2 rcs_id('$Id: WikiUserNew.php,v 1.133 2006-03-07 18:39:21 rurban Exp $');
3 /* Copyright (C) 2004,2005 $ThePhpWikiProgrammingTeam
5 * This file is part of PhpWiki.
7 * PhpWiki is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * PhpWiki is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with PhpWiki; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * This is a complete OOP rewrite of the old WikiUser code with various
23 * configurable external authentication methods.
25 * There's only one entry point, the function WikiUser which returns
26 * a WikiUser object, which contains the name, authlevel and user's preferences.
27 * This object might get upgraded during the login step and later also.
28 * There exist three preferences storage methods: cookie, homepage and db,
29 * and multiple password checking methods.
30 * See index.php for $USER_AUTH_ORDER[] and USER_AUTH_POLICY if
31 * ALLOW_USER_PASSWORDS is defined.
33 * Each user object must define the two preferences methods
34 * getPreferences(), setPreferences(),
35 * and the following 1-4 auth methods
36 * checkPass() must be defined by all classes,
37 * userExists() only if USER_AUTH_POLICY'=='strict'
38 * mayChangePass() only if the password is storable.
39 * storePass() only if the password is storable.
41 * WikiUser() given no name, returns an _AnonUser (anonymous user)
42 * object, who may or may not have a cookie.
43 * However, if the there's a cookie with the userid or a session,
44 * the user is upgraded to the matching user object.
45 * Given a user name, returns a _BogoUser object, who may or may not
46 * have a cookie and/or PersonalPage, one of the various _PassUser objects
47 * or an _AdminUser object.
48 * BTW: A BogoUser is a userid (loginname) as valid WikiWord, who might
49 * have stored a password or not. If so, his account is secure, if not
50 * anybody can use it, because the username is visible e.g. in RecentChanges.
52 * Takes care of passwords, all preference loading/storing in the
53 * user's page and any cookies. lib/main.php will query the user object to
54 * verify the password as appropriate.
56 * @author: Reini Urban (the tricky parts),
57 * Carsten Klapp (started rolling the ball)
59 * Random architectural notes, sorted by date:
61 * Test it by defining ENABLE_USER_NEW in config/config.ini
62 * 1) Now a ForbiddenUser is returned instead of false.
63 * 2) Previously ALLOW_ANON_USER = false meant that anon users cannot edit,
64 * but may browse. Now with ALLOW_ANON_USER = false he may not browse,
65 * which is needed to disable browse PagePermissions.
66 * I added now ALLOW_ANON_EDIT = true to makes things clear.
67 * (which replaces REQUIRE_SIGNIN_BEFORE_EDIT)
69 * 3) Removed pear prepare. Performance hog, and using integers as
70 * handler doesn't help. Do simple sprintf as with adodb. And a prepare
71 * in the object init is no advantage, because in the init loop a lot of
72 * objects are tried, but not used.
73 * 4) Already gotten prefs are passed to the next object to avoid
74 * duplicate getPreferences() calls.
76 * 5) Major php-5 problem: $this re-assignment is disallowed by the parser
77 * So we cannot just discrimate with
78 * if (!check_php_version(5))
80 * A /php5-patch.php is provided, which patches the src automatically
81 * for php4 and php5. Default is php4.
82 * Update: not needed anymore. we use eval to fool the load-time syntax checker.
84 * 6) enforced new cookie policy: prefs don't get stored in cookies
85 * anymore, only in homepage and/or database, but always in the
86 * current session. old pref cookies will get deleted.
88 * 7) Certain themes should be able to extend the predefined list
89 * of preferences. Display/editing is done in the theme specific userprefs.tmpl,
90 * but storage must be extended to the Get/SetPreferences methods.
91 * <theme>/themeinfo.php must provide CustomUserPreferences:
92 * A list of name => _UserPreference class pairs.
95 define('WIKIAUTH_FORBIDDEN', -1); // Completely not allowed.
96 define('WIKIAUTH_ANON', 0); // Not signed in.
97 define('WIKIAUTH_BOGO', 1); // Any valid WikiWord is enough.
98 define('WIKIAUTH_USER', 2); // Bogo user with a password.
99 define('WIKIAUTH_ADMIN', 10); // UserName == ADMIN_USER.
100 define('WIKIAUTH_UNOBTAINABLE', 100); // Permissions that no user can achieve
102 //if (!defined('COOKIE_EXPIRATION_DAYS')) define('COOKIE_EXPIRATION_DAYS', 365);
103 //if (!defined('COOKIE_DOMAIN')) define('COOKIE_DOMAIN', '/');
104 if (!defined('EDITWIDTH_MIN_COLS')) define('EDITWIDTH_MIN_COLS', 30);
105 if (!defined('EDITWIDTH_MAX_COLS')) define('EDITWIDTH_MAX_COLS', 150);
106 if (!defined('EDITWIDTH_DEFAULT_COLS')) define('EDITWIDTH_DEFAULT_COLS', 80);
108 if (!defined('EDITHEIGHT_MIN_ROWS')) define('EDITHEIGHT_MIN_ROWS', 5);
109 if (!defined('EDITHEIGHT_MAX_ROWS')) define('EDITHEIGHT_MAX_ROWS', 80);
110 if (!defined('EDITHEIGHT_DEFAULT_ROWS')) define('EDITHEIGHT_DEFAULT_ROWS', 22);
112 define('TIMEOFFSET_MIN_HOURS', -26);
113 define('TIMEOFFSET_MAX_HOURS', 26);
114 if (!defined('TIMEOFFSET_DEFAULT_HOURS')) define('TIMEOFFSET_DEFAULT_HOURS', 0);
117 * There are be the following constants in config/config.ini to
118 * establish login parameters:
120 * ALLOW_ANON_USER default true
121 * ALLOW_ANON_EDIT default true
122 * ALLOW_BOGO_LOGIN default true
123 * ALLOW_USER_PASSWORDS default true
124 * PASSWORD_LENGTH_MINIMUM default 0
126 * To require user passwords for editing:
127 * ALLOW_ANON_USER = true
128 * ALLOW_ANON_EDIT = false (before named REQUIRE_SIGNIN_BEFORE_EDIT)
129 * ALLOW_BOGO_LOGIN = false
130 * ALLOW_USER_PASSWORDS = true
132 * To establish a COMPLETELY private wiki, such as an internal
134 * ALLOW_ANON_USER = false
135 * (and probably require user passwords as described above). In this
136 * case the user will be prompted to login immediately upon accessing
139 * There are other possible combinations, but the typical wiki (such
140 * as http://PhpWiki.sf.net/phpwiki) would usually just leave all four
145 // The last object in the row is the bad guy...
146 if (!is_array($USER_AUTH_ORDER))
147 $USER_AUTH_ORDER = array("Forbidden");
149 $USER_AUTH_ORDER[] = "Forbidden";
151 // Local convenience functions.
152 function _isAnonUserAllowed() {
153 return (defined('ALLOW_ANON_USER') && ALLOW_ANON_USER);
155 function _isBogoUserAllowed() {
156 return (defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN);
158 function _isUserPasswordsAllowed() {
159 return (defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
162 // Possibly upgrade userobject functions.
163 function _determineAdminUserOrOtherUser($UserName) {
164 // Sanity check. User name is a condition of the definition of the
165 // _AdminUser, _BogoUser and _passuser.
167 return $GLOBALS['ForbiddenUser'];
169 //FIXME: check admin membership later at checkPass. Now we cannot raise the level.
170 //$group = &WikiGroup::getGroup($GLOBALS['request']);
171 if ($UserName == ADMIN_USER)
172 return new _AdminUser($UserName);
173 /* elseif ($group->isMember(GROUP_ADMIN)) { // unneeded code
174 return _determineBogoUserOrPassUser($UserName);
178 return _determineBogoUserOrPassUser($UserName);
181 function _determineBogoUserOrPassUser($UserName) {
182 global $ForbiddenUser;
184 // Sanity check. User name is a condition of the definition of
185 // _BogoUser and _PassUser.
187 return $ForbiddenUser;
189 // Check for password and possibly upgrade user object.
190 // $_BogoUser = new _BogoUser($UserName);
191 if (_isBogoUserAllowed() and isWikiWord($UserName)) {
192 include_once("lib/WikiUser/BogoLogin.php");
193 $_BogoUser = new _BogoLoginPassUser($UserName);
194 if ($_BogoUser->userExists() or $GLOBALS['request']->getArg('auth'))
197 if (_isUserPasswordsAllowed()) {
198 // PassUsers override BogoUsers if a password is stored
199 if (isset($_BogoUser) and isset($_BogoUser->_prefs)
200 and $_BogoUser->_prefs->get('passwd'))
201 return new _PassUser($UserName, $_BogoUser->_prefs);
203 $_PassUser = new _PassUser($UserName,
204 isset($_BogoUser) ? $_BogoUser->_prefs : false);
205 if ($_PassUser->userExists() or $GLOBALS['request']->getArg('auth'))
209 // No Bogo- or PassUser exists, or
210 // passwords are not allowed, and bogo is disallowed too.
211 // (Only the admin can sign in).
212 return $ForbiddenUser;
216 * Primary WikiUser function, called by lib/main.php.
218 * This determines the user's type and returns an appropriate user
219 * object. lib/main.php then querys the resultant object for password
220 * validity as necessary.
222 * If an _AnonUser object is returned, the user may only browse pages
223 * (and save prefs in a cookie).
225 * To disable access but provide prefs the global $ForbiddenUser class
226 * is returned. (was previously false)
229 function WikiUser ($UserName = '') {
230 global $ForbiddenUser;
232 //Maybe: Check sessionvar for username & save username into
233 //sessionvar (may be more appropriate to do this in lib/main.php).
235 $ForbiddenUser = new _ForbiddenUser($UserName);
236 // Found a user name.
237 return _determineAdminUserOrOtherUser($UserName);
239 elseif (!empty($_SESSION['userid'])) {
240 // Found a user name.
241 $ForbiddenUser = new _ForbiddenUser($_SESSION['userid']);
242 return _determineAdminUserOrOtherUser($_SESSION['userid']);
245 // Check for autologin pref in cookie and possibly upgrade
246 // user object to another type.
247 $_AnonUser = new _AnonUser();
248 if ($UserName = $_AnonUser->_userid && $_AnonUser->_prefs->get('autologin')) {
249 // Found a user name.
250 $ForbiddenUser = new _ForbiddenUser($UserName);
251 return _determineAdminUserOrOtherUser($UserName);
254 $ForbiddenUser = new _ForbiddenUser();
255 if (_isAnonUserAllowed())
257 return $ForbiddenUser; // User must sign in to browse pages.
259 return $ForbiddenUser; // User must sign in with a password.
262 trigger_error("DEBUG: Note: End of function reached in WikiUser." . " "
263 . "Unexpectedly, an appropriate user class could not be determined.");
264 return $ForbiddenUser; // Failsafe.
269 * WikiUser.php use the name 'WikiUser'
271 function WikiUserClassname() {
277 * Upgrade olduser by copying properties from user to olduser.
278 * We are not sure yet, for which php's a simple $this = $user works reliably,
279 * (on php4 it works ok, on php5 it's currently disallowed on the parser level)
280 * that's why try it the hard way.
282 function UpgradeUser ($olduser, $user) {
283 if (isa($user,'_WikiUser') and isa($olduser,'_WikiUser')) {
284 // populate the upgraded class $olduser with the values from the new user object
285 //only _auth_level, _current_method, _current_index,
286 if (!empty($user->_level) and
287 $user->_level > $olduser->_level)
288 $olduser->_level = $user->_level;
289 if (!empty($user->_current_index) and
290 $user->_current_index > $olduser->_current_index) {
291 $olduser->_current_index = $user->_current_index;
292 $olduser->_current_method = $user->_current_method;
294 if (!empty($user->_authmethod))
295 $olduser->_authmethod = $user->_authmethod;
297 foreach (get_object_vars($user) as $k => $v) {
298 if (!empty($v)) $olduser->$k = $v;
301 $olduser->hasHomePage(); // revive db handle, because these don't survive sessions
302 //$GLOBALS['request']->_user = $olduser;
310 * Probably not needed, since we use the various user objects methods so far.
311 * Anyway, here it is, looping through all available objects.
313 function UserExists ($UserName) {
315 if (!($user = $request->getUser()))
316 $user = WikiUser($UserName);
319 if ($user->userExists($UserName)) {
320 $request->_user = $user;
323 if (isa($user,'_BogoUser'))
324 $user = new _PassUser($UserName,$user->_prefs);
325 $class = $user->nextClass();
326 if ($user = new $class($UserName,$user->_prefs)) {
327 return $user->userExists($UserName);
329 $request->_user = $GLOBALS['ForbiddenUser'];
333 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
336 * Base WikiUser class.
341 var $_level = WIKIAUTH_ANON;
343 var $_HomePagehandle = false;
346 function _WikiUser($UserName='', $prefs=false) {
348 $this->_userid = $UserName;
349 $this->_HomePagehandle = false;
351 $this->hasHomePage();
353 if (empty($this->_prefs)) {
354 if ($prefs) $this->_prefs = $prefs;
355 else $this->getPreferences();
359 function UserName() {
360 if (!empty($this->_userid))
361 return $this->_userid;
364 function getPreferences() {
365 trigger_error("DEBUG: Note: undefined _WikiUser class trying to load prefs." . " "
366 . "New subclasses of _WikiUser must override this function.");
370 function setPreferences($prefs, $id_only) {
371 trigger_error("DEBUG: Note: undefined _WikiUser class trying to save prefs."
373 . "New subclasses of _WikiUser must override this function.");
377 function userExists() {
378 return $this->hasHomePage();
381 function checkPass($submitted_password) {
382 // By definition, an undefined user class cannot sign in.
383 trigger_error("DEBUG: Warning: undefined _WikiUser class trying to sign in."
385 . "New subclasses of _WikiUser must override this function.");
389 // returns page_handle to user's home page or false if none
390 function hasHomePage() {
391 if ($this->_userid) {
392 if (!empty($this->_HomePagehandle) and is_object($this->_HomePagehandle)) {
393 return $this->_HomePagehandle->exists();
396 // check db again (maybe someone else created it since
399 $this->_HomePagehandle = $request->getPage($this->_userid);
400 return $this->_HomePagehandle->exists();
407 // innocent helper: case-insensitive position in _auth_methods
408 function array_position ($string, $array) {
409 $string = strtolower($string);
410 for ($found = 0; $found < count($array); $found++) {
411 if (strtolower($array[$found]) == $string)
417 function nextAuthMethodIndex() {
418 if (empty($this->_auth_methods))
419 $this->_auth_methods = $GLOBALS['USER_AUTH_ORDER'];
420 if (empty($this->_current_index)) {
421 if (strtolower(get_class($this)) != '_passuser') {
422 $this->_current_method = substr(get_class($this),1,-8);
423 $this->_current_index = $this->array_position($this->_current_method,
424 $this->_auth_methods);
426 $this->_current_index = -1;
429 $this->_current_index++;
430 if ($this->_current_index >= count($this->_auth_methods))
432 $this->_current_method = $this->_auth_methods[$this->_current_index];
433 return $this->_current_index;
436 function AuthMethod($index = false) {
437 return $this->_auth_methods[ $index === false
438 ? count($this->_auth_methods)-1
442 // upgrade the user object
443 function nextClass() {
444 $method = $this->AuthMethod($this->nextAuthMethodIndex());
445 include_once("lib/WikiUser/$method.php");
446 return "_".$method."PassUser";
449 //Fixme: for _HttpAuthPassUser
450 function PrintLoginForm (&$request, $args, $fail_message = false,
451 $seperate_page = false) {
452 include_once('lib/Template.php');
453 // Call update_locale in case the system's default language is not 'en'.
454 // (We have no user pref for lang at this point yet, no one is logged in.)
455 if ($GLOBALS['LANG'] != DEFAULT_LANGUAGE)
456 update_locale(DEFAULT_LANGUAGE);
457 $userid = $this->_userid;
459 extract($args); // fixme
461 $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
463 $pagename = $request->getArg('pagename');
465 $login = Template('login',
466 compact('pagename', 'userid', 'require_level',
467 'fail_message', 'pass_required', 'nocache'));
468 // check if the html template was already processed
469 $seperate_page = $seperate_page ? true : !alreadyTemplateProcessed('html');
470 if ($seperate_page) {
471 $page = $request->getPage($pagename);
472 $revision = $page->getCurrentRevision();
473 return GeneratePage($login,_("Sign In"),$revision);
475 return $login->printExpansion();
479 /** Signed in but not password checked or empty password.
481 function isSignedIn() {
482 return (isa($this,'_BogoUser') or isa($this,'_PassUser'));
485 /** This is password checked for sure.
487 function isAuthenticated() {
488 //return isa($this,'_PassUser');
489 //return isa($this,'_BogoUser') || isa($this,'_PassUser');
490 return $this->_level >= WIKIAUTH_BOGO;
493 function isAdmin () {
495 if ($this->_level == WIKIAUTH_ADMIN) return true;
496 if (!$this->isSignedIn()) return false;
497 if (!$this->isAuthenticated()) return false;
499 if (!$group) $group = &$GLOBALS['request']->getGroup();
500 return ($this->_level > WIKIAUTH_BOGO and $group->isMember(GROUP_ADMIN));
503 /** Name or IP for a signed user. UserName could come from a cookie e.g.
506 return ( $this->UserName()
508 : $GLOBALS['request']->get('REMOTE_ADDR') );
511 /** Name for an authenticated user. No IP here.
513 function getAuthenticatedId() {
514 return ( $this->isAuthenticated()
516 : ''); //$GLOBALS['request']->get('REMOTE_ADDR') );
519 function hasAuthority ($require_level) {
520 return $this->_level >= $require_level;
523 /* This is quite restrictive and not according the login description online.
524 Any word char (A-Za-z0-9_), ".", "@" and "-"
525 The backends may loosen this.
527 function isValidName ($userid = false) {
528 if (!$userid) $userid = $this->_userid;
529 return preg_match("/^[\w\.@\-]+$/",$userid) and strlen($userid) < 32;
533 * Called on an auth_args POST request, such as login, logout or signin.
534 * TODO: Check BogoLogin users with empty password. (self-signed users)
536 function AuthCheck ($postargs) {
537 // Normalize args, and extract.
538 $keys = array('userid', 'passwd', 'require_level', 'login', 'logout',
540 foreach ($keys as $key)
541 $args[$key] = isset($postargs[$key]) ? $postargs[$key] : false;
543 $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
545 if ($logout) { // Log out
546 if (method_exists($GLOBALS['request']->_user, "logout")) { //_HttpAuthPassUser
547 $GLOBALS['request']->_user->logout();
549 $user = new _AnonUser();
551 $user->_level = WIKIAUTH_ANON;
554 return false; // User hit cancel button.
555 elseif (!$login && !$userid)
556 return false; // Nothing to do?
558 if (!$this->isValidName($userid))
559 return _("Invalid username.");;
561 $authlevel = $this->checkPass($passwd === false ? '' : $passwd);
562 if ($authlevel <= 0) { // anon or forbidden
564 return _("Invalid password.");
566 return _("Invalid password or userid.");
567 } elseif ($authlevel < $require_level) { // auth ok, but not enough
568 if (!empty($this->_current_method) and strtolower(get_class($this)) == '_passuser')
571 $class = "_" . $this->_current_method . "PassUser";
572 include_once("lib/WikiUser/".$this->_current_method.".php");
573 $user = new $class($userid,$this->_prefs);
574 if (!check_php_version(5))
575 eval("\$this = \$user;");
576 // /*PHP5 patch*/$this = $user;
577 $this->_level = $authlevel;
580 $this->_userid = $userid;
581 $this->_level = $authlevel;
582 return _("Insufficient permissions.");
586 //$user = $GLOBALS['request']->_user;
587 if (!empty($this->_current_method) and
588 strtolower(get_class($this)) == '_passuser')
591 $class = "_" . $this->_current_method . "PassUser";
592 include_once("lib/WikiUser/".$this->_current_method.".php");
593 $user = new $class($userid, $this->_prefs);
594 if (!check_php_version(5))
595 eval("\$this = \$user;");
596 // /*PHP5 patch*/$this = $user;
597 $user->_level = $authlevel;
600 $this->_userid = $userid;
601 $this->_level = $authlevel;
608 * Not authenticated in user, but he may be signed in. Basicly with view access only.
609 * prefs are stored in cookies, but only the userid.
614 var $_level = WIKIAUTH_ANON; // var in php-5.0.0RC1 deprecated
616 /** Anon only gets to load and save prefs in a cookie, that's it.
618 function getPreferences() {
621 if (empty($this->_prefs))
622 $this->_prefs = new UserPreferences;
623 $UserName = $this->UserName();
625 // Try to read deprecated 1.3.x style cookies
626 if ($cookie = $request->cookies->get_old(WIKI_NAME)) {
627 if (! $unboxedcookie = $this->_prefs->retrieve($cookie)) {
628 trigger_error(_("Empty Preferences or format of UserPreferences cookie not recognised.")
630 . sprintf("%s='%s'", WIKI_NAME, $cookie)
632 . _("Default preferences will be used."),
636 * Only set if it matches the UserName who is
637 * signing in or if this really is an Anon login (no
638 * username). (Remember, _BogoUser and higher inherit this
641 if (! $UserName || $UserName == @$unboxedcookie['userid']) {
642 $updated = $this->_prefs->updatePrefs($unboxedcookie);
643 //$this->_prefs = new UserPreferences($unboxedcookie);
644 $UserName = @$unboxedcookie['userid'];
645 if (is_string($UserName) and (substr($UserName,0,2) != 's:'))
646 $this->_userid = $UserName;
650 // v1.3.8 policy: don't set PhpWiki cookies, only plaintext WIKI_ID cookies
652 $request->deleteCookieVar(WIKI_NAME);
654 // Try to read deprecated 1.3.4 style cookies
655 if (! $UserName and ($cookie = $request->cookies->get_old("WIKI_PREF2"))) {
656 if (! $unboxedcookie = $this->_prefs->retrieve($cookie)) {
657 if (! $UserName || $UserName == $unboxedcookie['userid']) {
658 $updated = $this->_prefs->updatePrefs($unboxedcookie);
659 //$this->_prefs = new UserPreferences($unboxedcookie);
660 $UserName = $unboxedcookie['userid'];
661 if (is_string($UserName) and (substr($UserName,0,2) != 's:'))
662 $this->_userid = $UserName;
667 $request->deleteCookieVar("WIKI_PREF2");
671 // Try reading userid from old PhpWiki cookie formats:
672 if ($cookie = $request->cookies->get_old('WIKI_ID')) {
673 if (is_string($cookie) and (substr($cookie,0,2) != 's:'))
675 elseif (is_array($cookie) and !empty($cookie['userid']))
676 $UserName = $cookie['userid'];
678 if (! $UserName and !headers_sent())
679 $request->deleteCookieVar("WIKI_ID");
681 $this->_userid = $UserName;
684 // initializeTheme() needs at least an empty object
686 if (empty($this->_prefs))
687 $this->_prefs = new UserPreferences;
689 return $this->_prefs;
692 /** _AnonUser::setPreferences(): Save prefs in a cookie and session and update all global vars
694 * Allow for multiple wikis in same domain. Encode only the
695 * _prefs array of the UserPreference object. Ideally the
696 * prefs array should just be imploded into a single string or
697 * something so it is completely human readable by the end
698 * user. In that case stricter error checking will be needed
699 * when loading the cookie.
701 function setPreferences($prefs, $id_only=false) {
702 if (!is_object($prefs)) {
703 if (is_object($this->_prefs)) {
704 $updated = $this->_prefs->updatePrefs($prefs);
705 $prefs =& $this->_prefs;
707 // update the prefs values from scratch. This could leed to unnecessary
708 // side-effects: duplicate emailVerified, ...
709 $this->_prefs = new UserPreferences($prefs);
713 if (!isset($this->_prefs))
714 $this->_prefs =& $prefs;
716 $updated = $this->_prefs->isChanged($prefs);
719 if ($id_only and !headers_sent()) {
721 // new 1.3.8 policy: no array cookies, only plain userid string as in
722 // the pre 1.3.x versions.
723 // prefs should be stored besides the session in the homepagehandle or in a db.
724 $request->setCookieVar('WIKI_ID', $this->_userid,
725 COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
726 //$request->setCookieVar(WIKI_NAME, array('userid' => $prefs->get('userid')),
727 // COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
730 $packed = $prefs->store();
731 $unpacked = $prefs->unpack($packed);
732 if (count($unpacked)) {
733 foreach (array('_method','_select','_update','_insert') as $param) {
734 if (!empty($this->_prefs->{$param}))
735 $prefs->{$param} = $this->_prefs->{$param};
737 $this->_prefs = $prefs;
742 function userExists() {
746 function checkPass($submitted_password) {
748 // this might happen on a old-style signin button.
750 // By definition, the _AnonUser does not HAVE a password
751 // (compared to _BogoUser, who has an EMPTY password).
752 trigger_error("DEBUG: Warning: _AnonUser unexpectedly asked to checkPass()." . " "
753 . "Check isa(\$user, '_PassUser'), or: isa(\$user, '_AdminUser') etc. first." . " "
754 . "New subclasses of _WikiUser must override this function.");
761 * Helper class to finish the PassUser auth loop.
762 * This is added automatically to USER_AUTH_ORDER.
767 var $_level = WIKIAUTH_FORBIDDEN;
769 function checkPass($submitted_password) {
770 return WIKIAUTH_FORBIDDEN;
773 function userExists() {
774 if ($this->_HomePagehandle) return true;
780 * Do NOT extend _BogoUser to other classes, for checkPass()
781 * security. (In case of defects in code logic of the new class!)
782 * The intermediate step between anon and passuser.
783 * We also have the _BogoLoginPassUser class with stricter
784 * password checking, which fits into the auth loop.
785 * Note: This class is not called anymore by WikiUser()
790 function userExists() {
791 if (isWikiWord($this->_userid)) {
792 $this->_level = WIKIAUTH_BOGO;
795 $this->_level = WIKIAUTH_ANON;
800 function checkPass($submitted_password) {
801 // By definition, BogoUser has an empty password.
803 return $this->_level;
810 * Called if ALLOW_USER_PASSWORDS and Anon and Bogo failed.
812 * The classes for all subsequent auth methods extend from this class.
813 * This handles the auth method type dispatcher according $USER_AUTH_ORDER,
814 * the three auth method policies first-only, strict and stacked
815 * and the two methods for prefs: homepage or database,
816 * if $DBAuthParams['pref_select'] is defined.
818 * Default is PersonalPage auth and prefs.
820 * @author: Reini Urban
824 var $_auth_dbi, $_prefs;
825 var $_current_method, $_current_index;
827 // check and prepare the auth and pref methods only once
828 function _PassUser($UserName='', $prefs=false) {
829 //global $DBAuthParams, $DBParams;
831 if (!$this->isValidName($UserName))
833 $this->_userid = $UserName;
834 if ($this->hasHomePage())
835 $this->_HomePagehandle = $GLOBALS['request']->getPage($this->_userid);
837 $this->_authmethod = substr(get_class($this),1,-8);
838 if ($this->_authmethod == 'a') $this->_authmethod = 'admin';
840 // Check the configured Prefs methods
841 $dbi = $this->getAuthDbh();
842 $dbh = $GLOBALS['request']->getDbh();
843 if ( $dbi and !isset($this->_prefs->_select) and $dbh->getAuthParam('pref_select')) {
844 if (!$this->_prefs) {
845 $this->_prefs = new UserPreferences();
848 $this->_prefs->_method = $dbh->getParam('dbtype');
849 $this->_prefs->_select = $this->prepare($dbh->getAuthParam('pref_select'), "userid");
851 if ( !isset($this->_prefs->_update) and $dbh->getAuthParam('pref_update')) {
852 $this->_prefs->_update = $this->prepare($dbh->getAuthParam('pref_update'),
853 array("userid", "pref_blob"));
856 if (!$this->_prefs) {
857 $this->_prefs = new UserPreferences();
860 $this->_prefs->_method = 'HomePage';
863 if (! $this->_prefs or isset($need_pref) ) {
864 if ($prefs) $this->_prefs = $prefs;
865 else $this->getPreferences();
868 // Upgrade to the next parent _PassUser class. Avoid recursion.
869 if ( strtolower(get_class($this)) === '_passuser' ) {
870 //auth policy: Check the order of the configured auth methods
871 // 1. first-only: Upgrade the class here in the constructor
872 // 2. old: ignore USER_AUTH_ORDER and try to use all available methods as
873 /// in the previous PhpWiki releases (slow)
874 // 3. strict: upgrade the class after checking the user existance in userExists()
875 // 4. stacked: upgrade the class after the password verification in checkPass()
876 // Methods: PersonalPage, HttpAuth, DB, Ldap, Imap, File
877 //if (!defined('USER_AUTH_POLICY')) define('USER_AUTH_POLICY','old');
878 if (defined('USER_AUTH_POLICY')) {
879 // policy 1: only pre-define one method for all users
880 if (USER_AUTH_POLICY === 'first-only') {
881 $class = $this->nextClass();
882 return new $class($UserName,$this->_prefs);
884 // Use the default behaviour from the previous versions:
885 elseif (USER_AUTH_POLICY === 'old') {
886 // Default: try to be smart
887 // On php5 we can directly return and upgrade the Object,
888 // before we have to upgrade it manually.
889 if (!empty($GLOBALS['PHP_AUTH_USER']) or !empty($_SERVER['REMOTE_USER'])) {
890 include_once("lib/WikiUser/HttpAuth.php");
891 if (check_php_version(5))
892 return new _HttpAuthPassUser($UserName,$this->_prefs);
894 $user = new _HttpAuthPassUser($UserName,$this->_prefs);
895 eval("\$this = \$user;");
896 // /*PHP5 patch*/$this = $user;
899 } elseif (in_array('Db', $dbh->getAuthParam('USER_AUTH_ORDER')) and
900 $dbh->getAuthParam('auth_check') and
901 ($dbh->getAuthParam('auth_dsn') or $dbh->getParam('dsn'))) {
902 if (check_php_version(5))
903 return new _DbPassUser($UserName,$this->_prefs);
905 $user = new _DbPassUser($UserName,$this->_prefs);
906 eval("\$this = \$user;");
907 // /*PHP5 patch*/$this = $user;
910 } elseif (in_array('LDAP', $dbh->getAuthParam('USER_AUTH_ORDER')) and
911 defined('LDAP_AUTH_HOST') and defined('LDAP_BASE_DN') and
912 function_exists('ldap_connect')) {
913 include_once("lib/WikiUser/LDAP.php");
914 if (check_php_version(5))
915 return new _LDAPPassUser($UserName,$this->_prefs);
917 $user = new _LDAPPassUser($UserName,$this->_prefs);
918 eval("\$this = \$user;");
919 // /*PHP5 patch*/$this = $user;
922 } elseif (in_array('IMAP', $dbh->getAuthParam('USER_AUTH_ORDER')) and
923 defined('IMAP_AUTH_HOST') and function_exists('imap_open')) {
924 include_once("lib/WikiUser/IMAP.php");
925 if (check_php_version(5))
926 return new _IMAPPassUser($UserName,$this->_prefs);
928 $user = new _IMAPPassUser($UserName,$this->_prefs);
929 eval("\$this = \$user;");
930 // /*PHP5 patch*/$this = $user;
933 } elseif (in_array('File', $dbh->getAuthParam('USER_AUTH_ORDER')) and
934 defined('AUTH_USER_FILE') and file_exists(AUTH_USER_FILE)) {
935 include_once("lib/WikiUser/File.php");
936 if (check_php_version(5))
937 return new _FilePassUser($UserName, $this->_prefs);
939 $user = new _FilePassUser($UserName, $this->_prefs);
940 eval("\$this = \$user;");
941 // /*PHP5 patch*/$this = $user;
945 include_once("lib/WikiUser/PersonalPage.php");
946 if (check_php_version(5))
947 return new _PersonalPagePassUser($UserName,$this->_prefs);
949 $user = new _PersonalPagePassUser($UserName,$this->_prefs);
950 eval("\$this = \$user;");
951 // /*PHP5 patch*/$this = $user;
957 // else use the page methods defined in _PassUser.
963 function getAuthDbh () {
964 global $request; //, $DBParams, $DBAuthParams;
966 $dbh = $request->getDbh();
967 // session restauration doesn't re-connect to the database automatically,
968 // so dirty it here, to force a reconnect.
969 if (isset($this->_auth_dbi)) {
970 if (($dbh->getParam('dbtype') == 'SQL') and empty($this->_auth_dbi->connection))
971 unset($this->_auth_dbi);
972 if (($dbh->getParam('dbtype') == 'ADODB') and empty($this->_auth_dbi->_connectionID))
973 unset($this->_auth_dbi);
975 if (empty($this->_auth_dbi)) {
976 if ($dbh->getParam('dbtype') != 'SQL'
977 and $dbh->getParam('dbtype') != 'ADODB'
978 and $dbh->getParam('dbtype') != 'PDO')
980 if (empty($GLOBALS['DBAuthParams']))
982 if (!$dbh->getAuthParam('auth_dsn')) {
983 $dbh = $request->getDbh(); // use phpwiki database
984 } elseif ($dbh->getAuthParam('auth_dsn') == $dbh->getParam('dsn')) {
985 $dbh = $request->getDbh(); // same phpwiki database
986 } else { // use another external database handle. needs PHP >= 4.1
987 $local_params = array_merge($GLOBALS['DBParams'],$GLOBALS['DBAuthParams']);
988 $local_params['dsn'] = $local_params['auth_dsn'];
989 $dbh = WikiDB::open($local_params);
991 $this->_auth_dbi =& $dbh->_backend->_dbh;
993 return $this->_auth_dbi;
996 function _normalize_stmt_var($var, $oldstyle = false) {
997 static $valid_variables = array('userid','password','pref_blob','groupname');
998 // old-style: "'$userid'"
999 // new-style: '"\$userid"' or just "userid"
1000 $new = str_replace(array("'",'"','\$','$'),'',$var);
1001 if (!in_array($new, $valid_variables)) {
1002 trigger_error("Unknown DBAuthParam statement variable: ". $new, E_USER_ERROR);
1005 return !$oldstyle ? "'$".$new."'" : '\$'.$new;
1008 // TODO: use it again for the auth and member tables
1009 function prepare ($stmt, $variables, $oldstyle = false) {
1011 $dbi = $request->getDbh();
1012 $this->getAuthDbh();
1013 // "'\$userid"' => %s
1014 // variables can be old-style: '"\$userid"' or new-style: "'$userid'" or just "userid"
1015 // old-style strings don't survive pear/Config/IniConfig treatment, that's why we changed it.
1017 if (is_array($variables)) {
1018 for ($i=0; $i < count($variables); $i++) {
1019 $var = $this->_normalize_stmt_var($variables[$i], $oldstyle);
1021 trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
1022 $variables[$i], $stmt), E_USER_WARNING);
1023 $variables[$i] = $var;
1024 if (!$var) $new[] = '';
1028 $var = $this->_normalize_stmt_var($variables, $oldstyle);
1030 trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
1031 $variables, $stmt), E_USER_WARNING);
1033 if (!$var) $new = '';
1036 $prefix = $dbi->getParam('prefix');
1037 // probably prefix table names if in same database
1038 if ($prefix and isset($this->_auth_dbi) and isset($dbi->_backend->_dbh) and
1039 ($dbi->getAuthParam('auth_dsn') and $dbi->getParam('dsn') == $dbi->getAuthParam('auth_dsn')))
1041 if (!stristr($stmt, $prefix)) {
1043 $stmt = str_replace(array(" user "," pref "," member "),
1044 array(" ".$prefix."user ",
1045 " ".$prefix."pref ",
1046 " ".$prefix."member "), $stmt);
1047 //Do it automatically for the lazy admin? Esp. on sf.net it's nice to have
1048 trigger_error("Need to prefix the DBAUTH tablename in config/config.ini:\n $oldstmt \n=> $stmt",
1052 // Preparate the SELECT statement, for ADODB and PearDB (MDB not).
1053 // Simple sprintf-style.
1054 $new_stmt = str_replace($variables, $new, $stmt);
1055 if ($new_stmt == $stmt) {
1057 trigger_error(sprintf("DbAuthParams: Invalid statement in %s",
1058 $stmt), E_USER_WARNING);
1060 trigger_error(sprintf("DbAuthParams: Old statement quoting style in %s",
1061 $stmt), E_USER_WARNING);
1062 $new_stmt = $this->prepare($stmt, $variables, 'oldstyle');
1068 function getPreferences() {
1069 if (!empty($this->_prefs->_method)) {
1070 if ($this->_prefs->_method == 'ADODB') {
1071 // FIXME: strange why this should be needed...
1072 include_once("lib/WikiUser/Db.php");
1073 include_once("lib/WikiUser/AdoDb.php");
1074 _AdoDbPassUser::_AdoDbPassUser($this->_userid, $this->_prefs);
1075 return _AdoDbPassUser::getPreferences();
1076 } elseif ($this->_prefs->_method == 'SQL') {
1077 include_once("lib/WikiUser/Db.php");
1078 include_once("lib/WikiUser/PearDb.php");
1079 _PearDbPassUser::_PearDbPassUser($this->_userid, $this->_prefs);
1080 return _PearDbPassUser::getPreferences();
1081 } elseif ($this->_prefs->_method == 'PDO') {
1082 include_once("lib/WikiUser/Db.php");
1083 include_once("lib/WikiUser/PdoDb.php");
1084 _PdoDbPassUser::_PdoDbPassUser($this->_userid, $this->_prefs);
1085 return _PdoDbPassUser::getPreferences();
1089 // We don't necessarily have to read the cookie first. Since
1090 // the user has a password, the prefs stored in the homepage
1091 // cannot be arbitrarily altered by other Bogo users.
1092 _AnonUser::getPreferences();
1093 // User may have deleted cookie, retrieve from his
1094 // PersonalPage if there is one.
1095 if ($this->_HomePagehandle) {
1096 if ($restored_from_page = $this->_prefs->retrieve
1097 ($this->_HomePagehandle->get('pref'))) {
1098 $updated = $this->_prefs->updatePrefs($restored_from_page,'init');
1099 //$this->_prefs = new UserPreferences($restored_from_page);
1100 return $this->_prefs;
1103 return $this->_prefs;
1106 function setPreferences($prefs, $id_only=false) {
1107 if (!empty($this->_prefs->_method)) {
1108 if ($this->_prefs->_method == 'ADODB') {
1109 // FIXME: strange why this should be needed...
1110 include_once("lib/WikiUser/Db.php");
1111 include_once("lib/WikiUser/AdoDb.php");
1112 _AdoDbPassUser::_AdoDbPassUser($this->_userid, $prefs);
1113 return _AdoDbPassUser::setPreferences($prefs, $id_only);
1115 elseif ($this->_prefs->_method == 'SQL') {
1116 include_once("lib/WikiUser/Db.php");
1117 include_once("lib/WikiUser/PearDb.php");
1118 _PearDbPassUser::_PearDbPassUser($this->_userid, $prefs);
1119 return _PearDbPassUser::setPreferences($prefs, $id_only);
1121 elseif ($this->_prefs->_method == 'PDO') {
1122 include_once("lib/WikiUser/Db.php");
1123 include_once("lib/WikiUser/PdoDb.php");
1124 _PdoDbPassUser::_PdoDbPassUser($this->_userid, $prefs);
1125 return _PdoDbPassUser::setPreferences($prefs, $id_only);
1128 if ($num = _AnonUser::setPreferences($prefs, $id_only)) {
1129 // Encode only the _prefs array of the UserPreference object
1130 if (!empty($this->_HomePagehandle) and !$id_only) {
1131 $this->_HomePagehandle->set('pref', $this->_prefs->store());
1137 function mayChangePass() {
1141 //The default method is getting the password from prefs.
1142 // child methods obtain $stored_password from external auth.
1143 function userExists() {
1144 //if ($this->_HomePagehandle) return true;
1145 $class = $this->nextClass();
1146 while ($user = new $class($this->_userid, $this->_prefs)) {
1147 if (!check_php_version(5))
1148 eval("\$this = \$user;");
1149 // /*PHP5 patch*/$this = $user;
1150 UpgradeUser($this,$user);
1151 if ($user->userExists()) {
1154 // prevent endless loop. does this work on all PHP's?
1155 // it just has to set the classname, what it correctly does.
1156 $class = $user->nextClass();
1157 if ($class == "_ForbiddenPassUser")
1163 //The default method is getting the password from prefs.
1164 // child methods obtain $stored_password from external auth.
1165 function checkPass($submitted_password) {
1166 $stored_password = $this->_prefs->get('passwd');
1167 if ($this->_checkPass($submitted_password, $stored_password)) {
1168 $this->_level = WIKIAUTH_USER;
1169 return $this->_level;
1171 if ((USER_AUTH_POLICY === 'strict') and $this->userExists()) {
1172 $this->_level = WIKIAUTH_FORBIDDEN;
1173 return $this->_level;
1175 return $this->_tryNextPass($submitted_password);
1180 function _checkPassLength($submitted_password) {
1181 if (strlen($submitted_password) < PASSWORD_LENGTH_MINIMUM) {
1182 trigger_error(_("The length of the password is shorter than the system policy allows."));
1189 * The basic password checker for all PassUser objects.
1190 * Uses global ENCRYPTED_PASSWD and PASSWORD_LENGTH_MINIMUM.
1191 * Empty passwords are always false!
1192 * PASSWORD_LENGTH_MINIMUM is enforced here and in the preference set method.
1193 * @see UserPreferences::set
1195 * DBPassUser password's have their own crypt definition.
1196 * That's why DBPassUser::checkPass() doesn't call this method, if
1197 * the db password method is 'plain', which means that the DB SQL
1198 * statement just returns 1 or 0. To use CRYPT() or PASSWORD() and
1199 * don't store plain passwords in the DB.
1201 * TODO: remove crypt() function check from config.php:396 ??
1203 function _checkPass($submitted_password, $stored_password) {
1204 if (!empty($submitted_password)) {
1205 // This works only on plaintext passwords.
1206 if (!ENCRYPTED_PASSWD and (strlen($stored_password) < PASSWORD_LENGTH_MINIMUM)) {
1207 // With the EditMetaData plugin
1208 trigger_error(_("The length of the stored password is shorter than the system policy allows. Sorry, you cannot login.\n You have to ask the System Administrator to reset your password."));
1211 if (!$this->_checkPassLength($submitted_password)) {
1214 if (ENCRYPTED_PASSWD) {
1215 // Verify against encrypted password.
1216 if (function_exists('crypt')) {
1217 if (crypt($submitted_password, $stored_password) == $stored_password )
1218 return true; // matches encrypted password
1223 trigger_error(_("The crypt function is not available in this version of PHP.") . " "
1224 . _("Please set ENCRYPTED_PASSWD to false in config/config.ini and probably change ADMIN_PASSWD."),
1230 // Verify against cleartext password.
1231 if ($submitted_password == $stored_password)
1234 // Check whether we forgot to enable ENCRYPTED_PASSWD
1235 if (function_exists('crypt')) {
1236 if (crypt($submitted_password, $stored_password) == $stored_password) {
1237 trigger_error(_("Please set ENCRYPTED_PASSWD to true in config/config.ini."),
1248 /** The default method is storing the password in prefs.
1249 * Child methods (DB, File) may store in external auth also, but this
1250 * must be explicitly enabled.
1251 * This may be called by plugin/UserPreferences or by ->SetPreferences()
1253 function changePass($submitted_password) {
1254 $stored_password = $this->_prefs->get('passwd');
1255 // check if authenticated
1256 if (!$this->isAuthenticated()) return false;
1257 if (ENCRYPTED_PASSWD) {
1258 $submitted_password = crypt($submitted_password);
1260 // check other restrictions, with side-effects only.
1261 $result = $this->_checkPass($submitted_password, $stored_password);
1262 if ($stored_password != $submitted_password) {
1263 $this->_prefs->set('passwd', $submitted_password);
1264 //update the storage (session, homepage, ...)
1265 $this->SetPreferences($this->_prefs);
1268 //Todo: return an error msg to the caller what failed?
1269 // same password or no privilege
1270 return ENCRYPTED_PASSWD ? true : false;
1273 function _tryNextPass($submitted_password) {
1274 if (DEBUG & _DEBUG_LOGIN) {
1275 $class = strtolower(get_class($this));
1276 if (substr($class,-10) == "dbpassuser") $class = "_dbpassuser";
1277 $GLOBALS['USER_AUTH_ERROR'][$class] = 'wrongpass';
1279 if (USER_AUTH_POLICY === 'strict') {
1280 $class = $this->nextClass();
1281 if ($user = new $class($this->_userid,$this->_prefs)) {
1282 if ($user->userExists()) {
1283 return $user->checkPass($submitted_password);
1287 if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
1288 $class = $this->nextClass();
1289 if ($user = new $class($this->_userid,$this->_prefs))
1290 return $user->checkPass($submitted_password);
1292 return $this->_level;
1295 function _tryNextUser() {
1296 if (DEBUG & _DEBUG_LOGIN) {
1297 $class = strtolower(get_class($this));
1298 if (substr($class,-10) == "dbpassuser") $class = "_dbpassuser";
1299 $GLOBALS['USER_AUTH_ERROR'][$class] = 'nosuchuser';
1301 if (USER_AUTH_POLICY === 'strict') {
1302 $class = $this->nextClass();
1303 while ($user = new $class($this->_userid,$this->_prefs)) {
1304 if (!check_php_version(5))
1305 eval("\$this = \$user;");
1306 // /*PHP5 patch*/$this = $user;
1307 //$user = UpgradeUser($this, $user);
1308 if ($user->userExists()) {
1311 $class = $this->nextClass();
1320 * Insert more auth classes here...
1321 * For example a customized db class for another db connection
1322 * or a socket-based auth server.
1328 * For security, this class should not be extended. Instead, extend
1329 * from _PassUser (think of this as unix "root").
1331 * FIXME: This should be a singleton class. Only ADMIN_USER may be of class AdminUser!
1332 * Other members of the Administrators group must raise their level otherwise somehow.
1333 * Currently every member is a AdminUser, which will not work for the various
1339 function mayChangePass() {
1342 function checkPass($submitted_password) {
1343 if ($this->_userid == ADMIN_USER)
1344 $stored_password = ADMIN_PASSWD;
1346 // Should not happen! Only ADMIN_USER should use this class.
1347 // return $this->_tryNextPass($submitted_password); // ???
1348 // TODO: safety check if really member of the ADMIN group?
1349 $stored_password = $this->_pref->get('passwd');
1351 if ($this->_checkPass($submitted_password, $stored_password)) {
1352 $this->_level = WIKIAUTH_ADMIN;
1353 if (!empty($GLOBALS['HTTP_SERVER_VARS']['PHP_AUTH_USER']) and class_exists("_HttpAuthPassUser")) {
1355 _HttpAuthPassUser::_fake_auth($this->_userid, $submitted_password);
1357 return $this->_level;
1359 return $this->_tryNextPass($submitted_password);
1360 //$this->_level = WIKIAUTH_ANON;
1361 //return $this->_level;
1365 function storePass($submitted_password) {
1366 if ($this->_userid == ADMIN_USER)
1369 // should not happen! only ADMIN_USER should use this class.
1370 return parent::storePass($submitted_password);
1375 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1377 * Various data classes for the preference types,
1378 * to support get, set, sanify (range checking, ...)
1379 * update() will do the neccessary side-effects if a
1380 * setting gets changed (theme, language, ...)
1383 class _UserPreference
1387 function _UserPreference ($default_value) {
1388 $this->default_value = $default_value;
1391 function sanify ($value) {
1392 return (string)$value;
1395 function get ($name) {
1396 if (isset($this->{$name}))
1397 return $this->{$name};
1399 return $this->default_value;
1402 function getraw ($name) {
1403 if (!empty($this->{$name}))
1404 return $this->{$name};
1407 // stores the value as $this->$name, and not as $this->value (clever?)
1408 function set ($name, $value) {
1410 $value = $this->sanify($value);
1411 if ($this->get($name) != $value) {
1412 $this->update($value);
1415 if ($value != $this->default_value) {
1416 $this->{$name} = $value;
1418 unset($this->{$name});
1423 // default: no side-effects
1424 function update ($value) {
1429 class _UserPreference_numeric
1430 extends _UserPreference
1432 function _UserPreference_numeric ($default, $minval = false,
1434 $this->_UserPreference((double)$default);
1435 $this->_minval = (double)$minval;
1436 $this->_maxval = (double)$maxval;
1439 function sanify ($value) {
1440 $value = (double)$value;
1441 if ($this->_minval !== false && $value < $this->_minval)
1442 $value = $this->_minval;
1443 if ($this->_maxval !== false && $value > $this->_maxval)
1444 $value = $this->_maxval;
1449 class _UserPreference_int
1450 extends _UserPreference_numeric
1452 function _UserPreference_int ($default, $minval = false, $maxval = false) {
1453 $this->_UserPreference_numeric((int)$default, (int)$minval, (int)$maxval);
1456 function sanify ($value) {
1457 return (int)parent::sanify((int)$value);
1461 class _UserPreference_bool
1462 extends _UserPreference
1464 function _UserPreference_bool ($default = false) {
1465 $this->_UserPreference((bool)$default);
1468 function sanify ($value) {
1469 if (is_array($value)) {
1470 /* This allows for constructs like:
1472 * <input type="hidden" name="pref[boolPref][]" value="0" />
1473 * <input type="checkbox" name="pref[boolPref][]" value="1" />
1475 * (If the checkbox is not checked, only the hidden input
1476 * gets sent. If the checkbox is sent, both inputs get
1479 foreach ($value as $val) {
1485 return (bool) $value;
1489 class _UserPreference_language
1490 extends _UserPreference
1492 function _UserPreference_language ($default = DEFAULT_LANGUAGE) {
1493 $this->_UserPreference($default);
1496 // FIXME: check for valid locale
1497 function sanify ($value) {
1498 // Revert to DEFAULT_LANGUAGE if user does not specify
1499 // language in UserPreferences or chooses <system language>.
1500 if ($value == '' or empty($value))
1501 $value = DEFAULT_LANGUAGE;
1503 return (string) $value;
1506 function update ($newvalue) {
1507 if (! $this->_init ) {
1508 // invalidate etag to force fresh output
1509 $GLOBALS['request']->setValidators(array('%mtime' => false));
1510 update_locale($newvalue ? $newvalue : $GLOBALS['LANG']);
1515 class _UserPreference_theme
1516 extends _UserPreference
1518 function _UserPreference_theme ($default = THEME) {
1519 $this->_UserPreference($default);
1522 function sanify ($value) {
1523 if (!empty($value) and FindFile($this->_themefile($value)))
1525 return $this->default_value;
1528 function update ($newvalue) {
1530 // invalidate etag to force fresh output
1531 if (! $this->_init )
1532 $GLOBALS['request']->setValidators(array('%mtime' => false));
1534 include_once($this->_themefile($newvalue));
1535 if (empty($WikiTheme))
1536 include_once($this->_themefile(THEME));
1539 function _themefile ($theme) {
1540 return "themes/$theme/themeinfo.php";
1544 class _UserPreference_notify
1545 extends _UserPreference
1547 function sanify ($value) {
1551 return $this->default_value;
1554 /** update to global user prefs: side-effect on set notify changes
1555 * use a global_data notify hash:
1556 * notify = array('pagematch' => array(userid => ('email' => mail,
1557 * 'verified' => 0|1),
1561 function update ($value) {
1562 if (!empty($this->_init)) return;
1563 $dbh = $GLOBALS['request']->getDbh();
1564 $notify = $dbh->get('notify');
1569 // expand to existing pages only or store matches?
1570 // for now we store (glob-style) matches which is easier for the user
1571 $pages = $this->_page_split($value);
1572 // Limitation: only current user.
1573 $user = $GLOBALS['request']->getUser();
1574 if (!$user or !method_exists($user,'UserName')) return;
1575 // This fails with php5 and a WIKI_ID cookie:
1576 $userid = $user->UserName();
1577 $email = $user->_prefs->get('email');
1578 $verified = $user->_prefs->_prefs['email']->getraw('emailVerified');
1579 // check existing notify hash and possibly delete pages for email
1580 if (!empty($data)) {
1581 foreach ($data as $page => $users) {
1582 if (isset($data[$page][$userid]) and !in_array($page, $pages)) {
1583 unset($data[$page][$userid]);
1585 if (count($data[$page]) == 0)
1586 unset($data[$page]);
1589 // add the new pages
1590 if (!empty($pages)) {
1591 foreach ($pages as $page) {
1592 if (!isset($data[$page]))
1593 $data[$page] = array();
1594 if (!isset($data[$page][$userid])) {
1595 // should we really store the verification notice here or
1596 // check it dynamically at every page->save?
1598 $data[$page][$userid] = array('email' => $email,
1599 'verified' => $verified);
1601 $data[$page][$userid] = array('email' => $email);
1606 // store users changes
1607 $dbh->set('notify',$data);
1610 /** split the user-given comma or whitespace delimited pagenames
1613 function _page_split($value) {
1614 return preg_split('/[\s,]+/',$value,-1,PREG_SPLIT_NO_EMPTY);
1618 class _UserPreference_email
1619 extends _UserPreference
1621 function sanify($value) {
1622 // check for valid email address
1623 if ($this->get('email') == $value and $this->getraw('emailVerified'))
1626 if ($value == 1 or $value === true)
1628 list($ok,$msg) = ValidateMail($value,'noconnect');
1632 trigger_error("E-Mail Validation Error: ".$msg, E_USER_WARNING);
1633 return $this->default_value;
1637 /** Side-effect on email changes:
1638 * Send a verification mail or for now just a notification email.
1639 * For true verification (value = 2), we'd need a mailserver hook.
1641 function update($value) {
1642 if (!empty($this->_init)) return;
1643 $verified = $this->getraw('emailVerified');
1645 if (($value == 1 or $value === true) and $verified)
1647 if (!empty($value) and !$verified) {
1648 list($ok,$msg) = ValidateMail($value);
1649 if ($ok and mail($value,"[".WIKI_NAME ."] "._("Email Verification"),
1650 sprintf(_("Welcome to %s!\nYour email account is verified and\nwill be used to send page change notifications.\nSee %s"),
1651 WIKI_NAME, WikiURL($GLOBALS['request']->getArg('pagename'),'',true))))
1652 $this->set('emailVerified',1);
1657 /** Check for valid email address
1658 fixed version from http://www.zend.com/zend/spotlight/ev12apr.php
1659 Note: too strict, Bug #1053681
1661 function ValidateMail($email, $noconnect=false) {
1662 $HTTP_HOST = $GLOBALS['request']->get('HTTP_HOST');
1664 // if this check is too strict (like invalid mail addresses in a local network only)
1665 // uncomment the following line:
1666 // return array(true,"not validated");
1667 // see http://sourceforge.net/tracker/index.php?func=detail&aid=1053681&group_id=6121&atid=106121
1671 // This is Paul Warren's (pdw@ex-parrot.com) monster regex for RFC822
1672 // addresses, from the Perl module Mail::RFC822::Address, reduced to
1673 // accept single RFC822 addresses without comments only. (The original
1674 // accepts groups and properly commented addresses also.)
1675 $lwsp = "(?:(?:\\r\\n)?[ \\t])";
1677 $specials = '()<>@,;:\\\\".\\[\\]';
1678 $controls = '\\000-\\031';
1680 $dtext = "[^\\[\\]\\r\\\\]";
1681 $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$lwsp*";
1683 $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$lwsp)*\"$lwsp*";
1685 $atom = "[^$specials $controls]+(?:$lwsp+|\\Z|(?=[\\[\"$specials]))";
1686 $word = "(?:$atom|$quoted_string)";
1687 $localpart = "$word(?:\\.$lwsp*$word)*";
1689 $sub_domain = "(?:$atom|$domain_literal)";
1690 $domain = "$sub_domain(?:\\.$lwsp*$sub_domain)*";
1692 $addr_spec = "$localpart\@$lwsp*$domain";
1695 $route = "(?:\@$domain(?:,\@$lwsp*$domain)*:$lwsp*)";
1696 $route_addr = "\\<$lwsp*$route?$addr_spec\\>$lwsp*";
1697 $mailbox = "(?:$addr_spec|$phrase$route_addr)";
1699 $rfc822re = "/$lwsp*$mailbox/";
1701 if (!preg_match($rfc822re, $email)) {
1703 $result[1] = sprintf(_("E-Mail address '%s' is not properly formatted"), $email);
1707 return array(true,sprintf(_("E-Mail address '%s' is properly formatted"), $email));
1709 list ( $Username, $Domain ) = split ("@", $email);
1710 //Todo: getmxrr workaround on windows or manual input field to verify it manually
1711 if (!isWindows() and getmxrr($Domain, $MXHost)) { // avoid warning on Windows.
1712 $ConnectAddress = $MXHost[0];
1714 $ConnectAddress = $Domain;
1716 $Connect = @fsockopen ( $ConnectAddress, 25 );
1718 if (ereg("^220", $Out = fgets($Connect, 1024))) {
1719 fputs ($Connect, "HELO $HTTP_HOST\r\n");
1720 $Out = fgets ( $Connect, 1024 );
1721 fputs ($Connect, "MAIL FROM: <".$email.">\r\n");
1722 $From = fgets ( $Connect, 1024 );
1723 fputs ($Connect, "RCPT TO: <".$email.">\r\n");
1724 $To = fgets ($Connect, 1024);
1725 fputs ($Connect, "QUIT\r\n");
1727 if (!ereg ("^250", $From)) {
1729 $result[1]="Server rejected address: ". $From;
1732 if (!ereg ( "^250", $To )) {
1734 $result[1]="Server rejected address: ". $To;
1739 $result[1] = "No response from server";
1744 $result[1]="Can not connect E-Mail server.";
1748 $result[1]="E-Mail address '$email' appears to be valid.";
1750 } // end of function
1752 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1757 * This object holds the $request->_prefs subobjects.
1758 * A simple packed array of non-default values get's stored as cookie,
1759 * homepage, or database, which are converted to the array of
1761 * We don't store the objects, because otherwise we will
1762 * not be able to upgrade any subobject. And it's a waste of space also.
1765 class UserPreferences
1767 function UserPreferences($saved_prefs = false) {
1768 // userid stored too, to ensure the prefs are being loaded for
1769 // the correct (currently signing in) userid if stored in a
1771 // Update: for db prefs we disallow passwd.
1772 // userid is needed for pref reflexion. current pref must know its username,
1773 // if some app needs prefs from different users, different from current user.
1776 'userid' => new _UserPreference(''),
1777 'passwd' => new _UserPreference(''),
1778 'autologin' => new _UserPreference_bool(),
1779 //'emailVerified' => new _UserPreference_emailVerified(),
1780 //fixed: store emailVerified as email parameter, 1.3.8
1781 'email' => new _UserPreference_email(''),
1782 'notifyPages' => new _UserPreference_notify(''), // 1.3.8
1783 'theme' => new _UserPreference_theme(THEME),
1784 'lang' => new _UserPreference_language(DEFAULT_LANGUAGE),
1785 'editWidth' => new _UserPreference_int(EDITWIDTH_DEFAULT_COLS,
1787 EDITWIDTH_MAX_COLS),
1788 'noLinkIcons' => new _UserPreference_bool(), // 1.3.8
1789 'editHeight' => new _UserPreference_int(EDITHEIGHT_DEFAULT_ROWS,
1790 EDITHEIGHT_MIN_ROWS,
1791 EDITHEIGHT_DEFAULT_ROWS),
1792 'timeOffset' => new _UserPreference_numeric(TIMEOFFSET_DEFAULT_HOURS,
1793 TIMEOFFSET_MIN_HOURS,
1794 TIMEOFFSET_MAX_HOURS),
1795 'relativeDates' => new _UserPreference_bool(),
1796 'googleLink' => new _UserPreference_bool(), // 1.3.10
1797 'doubleClickEdit' => new _UserPreference_bool(), // 1.3.11
1799 // add custom theme-specific pref types:
1800 // FIXME: on theme changes the wiki_user session pref object will fail.
1801 // We will silently ignore this.
1802 if (!empty($customUserPreferenceColumns))
1803 $this->_prefs = array_merge($this->_prefs,$customUserPreferenceColumns);
1805 if (isset($this->_method) and $this->_method == 'SQL') {
1806 //unset($this->_prefs['userid']);
1807 unset($this->_prefs['passwd']);
1810 if (is_array($saved_prefs)) {
1811 foreach ($saved_prefs as $name => $value)
1812 $this->set($name, $value);
1816 function _getPref($name) {
1817 if ($name == 'emailVerified')
1819 if (!isset($this->_prefs[$name])) {
1820 if ($name == 'passwd2') return false;
1821 if ($name == 'passwd') return false;
1822 trigger_error("$name: unknown preference", E_USER_NOTICE);
1825 return $this->_prefs[$name];
1828 // get the value or default_value of the subobject
1829 function get($name) {
1830 if ($_pref = $this->_getPref($name))
1831 if ($name == 'emailVerified')
1832 return $_pref->getraw($name);
1834 return $_pref->get($name);
1839 // check and set the new value in the subobject
1840 function set($name, $value) {
1841 $pref = $this->_getPref($name);
1842 if ($pref === false)
1845 /* do it here or outside? */
1846 if ($name == 'passwd' and
1847 defined('PASSWORD_LENGTH_MINIMUM') and
1848 strlen($value) <= PASSWORD_LENGTH_MINIMUM ) {
1849 //TODO: How to notify the user?
1853 if ($name == 'theme' and $value == '')
1856 // Fix Fatal error for undefined value. Thanks to Jim Ford and Joel Schaubert
1857 if ((!$value and $pref->default_value)
1858 or ($value and !isset($pref->$value))
1859 or ($value and ($pref->$value != $pref->default_value)))
1861 if ($name == 'emailVerified') $newvalue = $value;
1862 else $newvalue = $pref->sanify($value);
1863 $pref->set($name, $newvalue);
1865 $this->_prefs[$name] =& $pref;
1869 * use init to avoid update on set
1871 function updatePrefs($prefs, $init = false) {
1873 if ($init) $this->_init = $init;
1874 if (is_object($prefs)) {
1875 $type = 'emailVerified'; $obj =& $this->_prefs['email'];
1876 $obj->_init = $init;
1877 if ($obj->get($type) !== $prefs->get($type)) {
1878 if ($obj->set($type,$prefs->get($type)))
1881 foreach (array_keys($this->_prefs) as $type) {
1882 $obj =& $this->_prefs[$type];
1883 $obj->_init = $init;
1884 if ($prefs->get($type) !== $obj->get($type)) {
1885 // special systemdefault prefs: (probably not needed)
1886 if ($type == 'theme' and $prefs->get($type) == '' and
1887 $obj->get($type) == THEME) continue;
1888 if ($type == 'lang' and $prefs->get($type) == '' and
1889 $obj->get($type) == DEFAULT_LANGUAGE) continue;
1890 if ($this->_prefs[$type]->set($type,$prefs->get($type)))
1894 } elseif (is_array($prefs)) {
1895 //unset($this->_prefs['userid']);
1897 if (isset($this->_method) and
1898 ($this->_method == 'SQL' or $this->_method == 'ADODB')) {
1899 unset($this->_prefs['passwd']);
1902 // emailVerified at first, the rest later
1903 $type = 'emailVerified'; $obj =& $this->_prefs['email'];
1904 $obj->_init = $init;
1905 if (isset($prefs[$type]) and $obj->get($type) !== $prefs[$type]) {
1906 if ($obj->set($type,$prefs[$type]))
1909 foreach (array_keys($this->_prefs) as $type) {
1910 $obj =& $this->_prefs[$type];
1911 $obj->_init = $init;
1912 if (!isset($prefs[$type]) and isa($obj,"_UserPreference_bool"))
1913 $prefs[$type] = false;
1914 if (isset($prefs[$type]) and isa($obj,"_UserPreference_int"))
1915 $prefs[$type] = (int) $prefs[$type];
1916 if (isset($prefs[$type]) and $obj->get($type) != $prefs[$type]) {
1917 // special systemdefault prefs:
1918 if ($type == 'theme' and $prefs[$type] == '' and
1919 $obj->get($type) == THEME) continue;
1920 if ($type == 'lang' and $prefs[$type] == '' and
1921 $obj->get($type) == DEFAULT_LANGUAGE) continue;
1922 if ($obj->set($type,$prefs[$type]))
1930 // For now convert just array of objects => array of values
1931 // Todo: the specialized subobjects must override this.
1934 foreach ($this->_prefs as $name => $object) {
1935 if ($value = $object->getraw($name))
1936 $prefs[$name] = $value;
1937 if ($name == 'email' and ($value = $object->getraw('emailVerified')))
1938 $prefs['emailVerified'] = $value;
1939 if ($name == 'passwd' and $value and ENCRYPTED_PASSWD) {
1940 $prefs['passwd'] = crypt($value);
1943 return $this->pack($prefs);
1946 // packed string or array of values => array of values
1947 // Todo: the specialized subobjects must override this.
1948 function retrieve($packed) {
1949 if (is_string($packed) and (substr($packed, 0, 2) == "a:"))
1950 $packed = unserialize($packed);
1951 if (!is_array($packed)) return false;
1953 foreach ($packed as $name => $packed_pref) {
1954 if (is_string($packed_pref) and substr($packed_pref, 0, 2) == "O:") {
1955 //legacy: check if it's an old array of objects
1956 // Looks like a serialized object.
1957 // This might fail if the object definition does not exist anymore.
1958 // object with ->$name and ->default_value vars.
1959 $pref = @unserialize($packed_pref);
1961 $pref = @unserialize(base64_decode($packed_pref));
1962 $prefs[$name] = $pref->get($name);
1963 // fix old-style prefs
1964 } elseif (is_numeric($name) and is_array($packed_pref)) {
1965 if (count($packed_pref) == 1) {
1966 list($name,$value) = each($packed_pref);
1967 $prefs[$name] = $value;
1970 $prefs[$name] = @unserialize($packed_pref);
1971 if (empty($prefs[$name]))
1972 $prefs[$name] = @unserialize(base64_decode($packed_pref));
1973 // patched by frederik@pandora.be
1974 if (empty($prefs[$name]))
1975 $prefs[$name] = $packed_pref;
1982 * Check if the given prefs object is different from the current prefs object
1984 function isChanged($other) {
1985 foreach ($this->_prefs as $type => $obj) {
1986 if ($obj->get($type) !== $other->get($type))
1992 function defaultPreferences() {
1994 foreach ($this->_prefs as $key => $obj) {
1995 $prefs[$key] = $obj->default_value;
2002 return $this->_prefs;
2005 function pack($nonpacked) {
2006 return serialize($nonpacked);
2009 function unpack($packed) {
2012 //$packed = base64_decode($packed);
2013 if (substr($packed, 0, 2) == "O:") {
2014 // Looks like a serialized object
2015 return unserialize($packed);
2017 if (substr($packed, 0, 2) == "a:") {
2018 return unserialize($packed);
2020 //trigger_error("DEBUG: Can't unpack bad UserPreferences",
2026 return wikihash($this->_prefs);
2030 /** TODO: new pref storage classes
2031 * These are currently user specific and should be rewritten to be pref specific.
2032 * i.e. $this == $user->_prefs
2035 class CookieUserPreferences
2036 extends UserPreferences
2038 function CookieUserPreferences ($saved_prefs = false) {
2039 //_AnonUser::_AnonUser('',$saved_prefs);
2040 UserPreferences::UserPreferences($saved_prefs);
2044 class PageUserPreferences
2045 extends UserPreferences
2047 function PageUserPreferences ($saved_prefs = false) {
2048 UserPreferences::UserPreferences($saved_prefs);
2052 class PearDbUserPreferences
2053 extends UserPreferences
2055 function PearDbUserPreferences ($saved_prefs = false) {
2056 UserPreferences::UserPreferences($saved_prefs);
2060 class AdoDbUserPreferences
2061 extends UserPreferences
2063 function AdoDbUserPreferences ($saved_prefs = false) {
2064 UserPreferences::UserPreferences($saved_prefs);
2066 function getPreferences() {
2067 // override the generic slow method here for efficiency
2068 _AnonUser::getPreferences();
2069 $this->getAuthDbh();
2070 if (isset($this->_select)) {
2071 $dbh = & $this->_auth_dbi;
2072 $rs = $dbh->Execute(sprintf($this->_select,$dbh->qstr($this->_userid)));
2076 $prefs_blob = $rs->fields['pref_blob'];
2078 if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
2079 $updated = $this->_prefs->updatePrefs($restored_from_db);
2080 //$this->_prefs = new UserPreferences($restored_from_db);
2081 return $this->_prefs;
2085 if (empty($this->_prefs->_prefs) and $this->_HomePagehandle) {
2086 if ($restored_from_page = $this->_prefs->retrieve
2087 ($this->_HomePagehandle->get('pref'))) {
2088 $updated = $this->_prefs->updatePrefs($restored_from_page);
2089 //$this->_prefs = new UserPreferences($restored_from_page);
2090 return $this->_prefs;
2093 return $this->_prefs;
2098 // $Log: not supported by cvs2svn $
2099 // Revision 1.132 2006/03/04 13:19:12 rurban
2100 // fix for fatal error on empty pref value (sign out). Thanks to Jim Ford and Joel Schaubert. rename hash for php-5.1
2102 // Revision 1.131 2005/10/12 06:16:48 rurban
2103 // add new _insert statement
2105 // Revision 1.129 2005/06/10 06:10:35 rurban
2106 // ensure Update Preferences gets through
2108 // Revision 1.128 2005/06/05 05:38:02 rurban
2109 // Default ENABLE_DOUBLECLICKEDIT = false. Moved to UserPreferences
2111 // Revision 1.127 2005/04/02 18:01:41 uckelman
2112 // Fixed regex for RFC822 addresses.
2114 // Revision 1.126 2005/02/28 20:30:46 rurban
2115 // some stupid code for _AdminUser (probably not needed)
2117 // Revision 1.125 2005/02/08 13:25:50 rurban
2118 // encrypt password. fix strict logic.
2119 // both bugs reported by Mikhail Vladimirov
2121 // Revision 1.124 2005/01/30 23:11:00 rurban
2122 // allow self-creating passuser on login
2124 // Revision 1.123 2005/01/25 06:58:21 rurban
2127 // Revision 1.122 2005/01/08 22:51:56 rurban
2128 // remove deprecated workaround
2130 // Revision 1.121 2004/12/19 00:58:01 rurban
2131 // Enforce PASSWORD_LENGTH_MINIMUM in almost all PassUser checks,
2132 // Provide an errormessage if so. Just PersonalPage and BogoLogin not.
2133 // Simplify httpauth logout handling and set sessions for all methods.
2134 // fix main.php unknown index "x" getLevelDescription() warning.
2136 // Revision 1.120 2004/12/17 12:31:57 rurban
2137 // better logout, fake httpauth not yet
2139 // Revision 1.119 2004/11/21 11:59:17 rurban
2140 // remove final \n to be ob_cache independent
2142 // Revision 1.118 2004/11/19 19:22:03 rurban
2143 // ModeratePage part1: change status
2145 // Revision 1.117 2004/11/10 15:29:21 rurban
2146 // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
2147 // * ACCESS_LOG_SQL: fix cause request not yet initialized
2148 // * WikiDB: moved SQL specific methods upwards
2149 // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
2150 // fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
2152 // Revision 1.116 2004/11/05 21:03:27 rurban
2153 // new DEBUG flag: _DEBUG_LOGIN (64)
2154 // verbose login debug-msg (settings and reason for failure)
2156 // Revision 1.115 2004/11/05 20:53:35 rurban
2157 // login cleanup: better debug msg on failing login,
2158 // checked password less immediate login (bogo or anon),
2159 // checked olduser pref session error,
2160 // better PersonalPage without password warning on minimal password length=0
2161 // (which is default now)
2163 // Revision 1.114 2004/11/05 16:15:57 rurban
2164 // forgot the BogoLogin inclusion with the latest rewrite
2166 // Revision 1.113 2004/11/03 17:13:49 rurban
2167 // make it easier to disable EmailVerification
2170 // Revision 1.112 2004/11/01 10:43:57 rurban
2171 // seperate PassUser methods into seperate dir (memory usage)
2172 // fix WikiUser (old) overlarge data session
2173 // remove wikidb arg from various page class methods, use global ->_dbi instead
2176 // Revision 1.111 2004/10/21 21:03:50 rurban
2177 // isAdmin must be signed and authenticated
2178 // comment out unused sections (memory)
2180 // Revision 1.110 2004/10/14 19:19:33 rurban
2181 // loadsave: check if the dumped file will be accessible from outside.
2182 // and some other minor fixes. (cvsclient native not yet ready)
2184 // Revision 1.109 2004/10/07 16:08:58 rurban
2185 // fixed broken FileUser session handling.
2186 // thanks to Arnaud Fontaine for detecting this.
2187 // enable file user Administrator membership.
2189 // Revision 1.108 2004/10/05 17:00:04 rurban
2190 // support paging for simple lists
2191 // fix RatingDb sql backend.
2192 // remove pages from AllPages (this is ListPages then)
2194 // Revision 1.107 2004/10/04 23:42:15 rurban
2195 // HttpAuth admin group logic. removed old logs
2197 // Revision 1.106 2004/07/01 08:49:38 rurban
2198 // obsolete php5-patch.php: minor php5 login problem though
2200 // Revision 1.105 2004/06/29 06:48:03 rurban
2201 // Improve LDAP auth and GROUP_LDAP membership:
2202 // no error message on false password,
2203 // added two new config vars: LDAP_OU_USERS and LDAP_OU_GROUP with GROUP_METHOD=LDAP
2204 // fixed two group queries (this -> user)
2205 // stdlib: ConvertOldMarkup still flawed
2207 // Revision 1.104 2004/06/28 15:39:37 rurban
2208 // fixed endless recursion in WikiGroup: isAdmin()
2210 // Revision 1.103 2004/06/28 15:01:07 rurban
2211 // fixed LDAP_SET_OPTION handling, LDAP error on connection problem
2213 // Revision 1.102 2004/06/27 10:23:48 rurban
2214 // typo detected by Philippe Vanhaesendonck
2216 // Revision 1.101 2004/06/25 14:29:19 rurban
2217 // WikiGroup refactoring:
2218 // global group attached to user, code for not_current user.
2219 // improved helpers for special groups (avoid double invocations)
2220 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
2221 // fixed a XHTML validation error on userprefs.tmpl
2223 // Revision 1.100 2004/06/21 06:29:35 rurban
2224 // formatting: linewrap only
2226 // Revision 1.99 2004/06/20 15:30:05 rurban
2227 // get_class case-sensitivity issues
2229 // Revision 1.98 2004/06/16 21:24:31 rurban
2230 // do not display no-connect warning: #2662
2232 // Revision 1.97 2004/06/16 13:21:16 rurban
2233 // stabilize on failing ldap queries or bind
2235 // Revision 1.96 2004/06/16 12:42:06 rurban
2236 // fix homepage prefs
2238 // Revision 1.95 2004/06/16 10:38:58 rurban
2239 // Disallow refernces in calls if the declaration is a reference
2240 // ("allow_call_time_pass_reference clean").
2241 // PhpWiki is now allow_call_time_pass_reference = Off clean,
2242 // but several external libraries may not.
2243 // In detail these libs look to be affected (not tested):
2247 // Revision 1.94 2004/06/15 10:40:35 rurban
2248 // minor WikiGroup cleanup: no request param, start of current user independency
2250 // Revision 1.93 2004/06/15 09:15:52 rurban
2251 // IMPORTANT: fixed passwd handling for passwords stored in prefs:
2252 // fix encrypted usage, actually store and retrieve them from db
2253 // fix bogologin with passwd set.
2254 // fix php crashes with call-time pass-by-reference (references wrongly used
2255 // in declaration AND call). This affected mainly Apache2 and IIS.
2256 // (Thanks to John Cole to detect this!)
2258 // Revision 1.92 2004/06/14 11:31:36 rurban
2259 // renamed global $Theme to $WikiTheme (gforge nameclash)
2260 // inherit PageList default options from PageList
2261 // default sortby=pagename
2262 // use options in PageList_Selectable (limit, sortby, ...)
2263 // added action revert, with button at action=diff
2264 // added option regex to WikiAdminSearchReplace
2266 // Revision 1.91 2004/06/08 14:57:43 rurban
2267 // stupid ldap bug detected by John Cole
2269 // Revision 1.90 2004/06/08 09:31:15 rurban
2270 // fixed typo detected by lucidcarbon (line 1663 assertion)
2272 // Revision 1.89 2004/06/06 16:58:51 rurban
2273 // added more required ActionPages for foreign languages
2274 // install now english ActionPages if no localized are found. (again)
2275 // fixed default anon user level to be 0, instead of -1
2276 // (wrong "required administrator to view this page"...)
2278 // Revision 1.88 2004/06/04 20:32:53 rurban
2279 // Several locale related improvements suggested by Pierrick Meignen
2280 // LDAP fix by John Cole
2281 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
2283 // Revision 1.87 2004/06/04 12:40:21 rurban
2284 // Restrict valid usernames to prevent from attacks against external auth or compromise
2286 // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
2287 // Fxied more warnings
2289 // Revision 1.86 2004/06/03 18:06:29 rurban
2290 // fix file locking issues (only needed on write)
2291 // fixed immediate LANG and THEME in-session updates if not stored in prefs
2292 // advanced editpage toolbars (search & replace broken)
2294 // Revision 1.85 2004/06/03 12:46:03 rurban
2295 // fix signout, level must be 0 not -1
2297 // Revision 1.84 2004/06/03 12:36:03 rurban
2298 // fix eval warning on signin
2300 // Revision 1.83 2004/06/03 10:18:19 rurban
2301 // fix User locking issues, new config ENABLE_PAGEPERM
2303 // Revision 1.82 2004/06/03 09:39:51 rurban
2304 // fix LDAP injection (wildcard in username) detected by Steve Christey, MITRE
2306 // Revision 1.81 2004/06/02 18:01:45 rurban
2307 // init global FileFinder to add proper include paths at startup
2308 // adds PHPWIKI_DIR if started from another dir, lib/pear also
2309 // fix slashify for Windows
2310 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
2312 // Revision 1.80 2004/06/02 14:20:27 rurban
2313 // fix adodb DbPassUser login
2315 // Revision 1.79 2004/06/01 15:27:59 rurban
2316 // AdminUser only ADMIN_USER not member of Administrators
2317 // some RateIt improvements by dfrankow
2318 // edit_toolbar buttons
2320 // Revision 1.78 2004/05/27 17:49:06 rurban
2321 // renamed DB_Session to DbSession (in CVS also)
2322 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
2323 // remove leading slash in error message
2324 // added force_unlock parameter to File_Passwd (no return on stale locks)
2325 // fixed adodb session AffectedRows
2326 // added FileFinder helpers to unify local filenames and DATA_PATH names
2327 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
2329 // Revision 1.77 2004/05/18 14:49:51 rurban
2330 // Simplified strings for easier translation
2332 // Revision 1.76 2004/05/18 13:30:04 rurban
2333 // prevent from endless loop with oldstyle warnings
2335 // Revision 1.75 2004/05/16 22:07:35 rurban
2336 // check more config-default and predefined constants
2337 // various PagePerm fixes:
2338 // fix default PagePerms, esp. edit and view for Bogo and Password users
2339 // implemented Creator and Owner
2340 // BOGOUSERS renamed to BOGOUSER
2341 // fixed syntax errors in signin.tmpl
2343 // Revision 1.74 2004/05/15 19:48:33 rurban
2344 // fix some too loose PagePerms for signed, but not authenticated users
2345 // (admin, owner, creator)
2346 // no double login page header, better login msg.
2347 // moved action_pdf to lib/pdf.php
2349 // Revision 1.73 2004/05/15 18:31:01 rurban
2350 // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
2352 // Revision 1.72 2004/05/12 10:49:55 rurban
2353 // require_once fix for those libs which are loaded before FileFinder and
2354 // its automatic include_path fix, and where require_once doesn't grok
2355 // dirname(__FILE__) != './lib'
2356 // upgrade fix with PearDB
2357 // navbar.tmpl: remove spaces for IE button alignment
2359 // Revision 1.71 2004/05/10 12:34:47 rurban
2360 // stabilize DbAuthParam statement pre-prozessor:
2361 // try old-style and new-style (double-)quoting
2362 // reject unknown $variables
2363 // use ->prepare() for all calls (again)
2365 // Revision 1.70 2004/05/06 19:26:16 rurban
2366 // improve stability, trying to find the InlineParser endless loop on sf.net
2368 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
2370 // Revision 1.69 2004/05/06 13:56:40 rurban
2371 // Enable the Administrators group, and add the WIKIPAGE group default root page.
2373 // Revision 1.68 2004/05/05 13:37:54 rurban
2374 // Support to remove all UserPreferences
2376 // Revision 1.66 2004/05/03 21:44:24 rurban
2377 // fixed sf,net bug #947264: LDAP options are constants, not strings!
2379 // Revision 1.65 2004/05/03 13:16:47 rurban
2380 // fixed UserPreferences update, esp for boolean and int
2382 // Revision 1.64 2004/05/02 15:10:06 rurban
2383 // new finally reliable way to detect if /index.php is called directly
2384 // and if to include lib/main.php
2385 // new global AllActionPages
2386 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
2387 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
2388 // PageGroupTestOne => subpages
2389 // renamed PhpWikiRss to PhpWikiRecentChanges
2390 // more docs, default configs, ...
2392 // Revision 1.63 2004/05/01 15:59:29 rurban
2393 // more php-4.0.6 compatibility: superglobals
2395 // Revision 1.62 2004/04/29 18:31:24 rurban
2396 // Prevent from warning where no db pref was previously stored.
2398 // Revision 1.61 2004/04/29 17:18:19 zorloc
2399 // Fixes permission failure issues. With PagePermissions and Disabled Actions when user did not have permission WIKIAUTH_FORBIDDEN was returned. In WikiUser this was ok because WIKIAUTH_FORBIDDEN had a value of 11 -- thus no user could perform that action. But WikiUserNew has a WIKIAUTH_FORBIDDEN value of -1 -- thus a user without sufficent permission to do anything. The solution is a new high value permission level (WIKIAUTH_UNOBTAINABLE) to be the default level for access failure.
2401 // Revision 1.60 2004/04/27 18:20:54 rurban
2402 // sf.net patch #940359 by rassie
2404 // Revision 1.59 2004/04/26 12:35:21 rurban
2405 // POP3_AUTH_PORT deprecated, use "host:port" similar to IMAP
2406 // File_Passwd is already loaded
2408 // Revision 1.58 2004/04/20 17:08:28 rurban
2409 // Some IniConfig fixes: prepend our private lib/pear dir
2410 // switch from " to ' in the auth statements
2411 // use error handling.
2412 // WikiUserNew changes for the new "'$variable'" syntax
2413 // in the statements
2414 // TODO: optimization to put config vars into the session.
2416 // Revision 1.57 2004/04/19 18:27:45 rurban
2417 // Prevent from some PHP5 warnings (ref args, no :: object init)
2418 // php5 runs now through, just one wrong XmlElement object init missing
2419 // Removed unneccesary UpgradeUser lines
2420 // Changed WikiLink to omit version if current (RecentChanges)
2422 // Revision 1.56 2004/04/19 09:13:24 rurban
2423 // new pref: googleLink
2425 // Revision 1.54 2004/04/18 00:24:45 rurban
2426 // re-use our simple prepare: just for table prefix warnings
2428 // Revision 1.53 2004/04/12 18:29:15 rurban
2429 // exp. Session auth for already authenticated users from another app
2431 // Revision 1.52 2004/04/12 13:04:50 rurban
2432 // added auth_create: self-registering Db users
2434 // removed rating recommendations
2435 // ziplib reformatting
2437 // Revision 1.51 2004/04/11 10:42:02 rurban
2438 // pgsrc/CreatePagePlugin
2440 // Revision 1.50 2004/04/10 05:34:35 rurban
2443 // Revision 1.49 2004/04/07 23:13:18 rurban
2444 // fixed pear/File_Passwd for Windows
2445 // fixed FilePassUser sessions (filehandle revive) and password update
2447 // Revision 1.48 2004/04/06 20:00:10 rurban
2448 // Cleanup of special PageList column types
2449 // Added support of plugin and theme specific Pagelist Types
2450 // Added support for theme specific UserPreferences
2451 // Added session support for ip-based throttling
2452 // sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
2453 // Enhanced postgres schema
2454 // Added DB_Session_dba support
2456 // Revision 1.47 2004/04/02 15:06:55 rurban
2457 // fixed a nasty ADODB_mysql session update bug
2458 // improved UserPreferences layout (tabled hints)
2459 // fixed UserPreferences auth handling
2460 // improved auth stability
2461 // improved old cookie handling: fixed deletion of old cookies with paths
2463 // Revision 1.46 2004/04/01 06:29:51 rurban
2465 // RateIt also for ADODB
2471 // c-basic-offset: 4
2472 // c-hanging-comment-ender-p: nil
2473 // indent-tabs-mode: nil