2 /* Copyright (C) 2004,2005,2006,2007,2009,2010 $ThePhpWikiProgrammingTeam
3 * Copyright (C) 2009-2010 Marc-Etienne Vargenau, Alcatel-Lucent
4 * Copyright (C) 2009-2010 Roger Guignard, Alcatel-Lucent
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * This is a complete OOP rewrite of the old WikiUser code with various
25 * configurable external authentication methods.
27 * There's only one entry point, the function WikiUser which returns
28 * a WikiUser object, which contains the name, authlevel and user's preferences.
29 * This object might get upgraded during the login step and later also.
30 * There exist three preferences storage methods: cookie, homepage and db,
31 * and multiple password checking methods.
32 * See index.php for $USER_AUTH_ORDER[] and USER_AUTH_POLICY if
33 * ALLOW_USER_PASSWORDS is defined.
35 * Each user object must define the two preferences methods
36 * getPreferences(), setPreferences(),
37 * and the following 1-4 auth methods
38 * checkPass() must be defined by all classes,
39 * userExists() only if USER_AUTH_POLICY'=='strict'
40 * mayChangePass() only if the password is storable.
41 * storePass() only if the password is storable.
43 * WikiUser() given no name, returns an _AnonUser (anonymous user)
44 * object, who may or may not have a cookie.
45 * However, if the there's a cookie with the userid or a session,
46 * the user is upgraded to the matching user object.
47 * Given a user name, returns a _BogoUser object, who may or may not
48 * have a cookie and/or PersonalPage, one of the various _PassUser objects
49 * or an _AdminUser object.
50 * BTW: A BogoUser is a userid (loginname) as valid WikiWord, who might
51 * have stored a password or not. If so, his account is secure, if not
52 * anybody can use it, because the username is visible e.g. in RecentChanges.
54 * Takes care of passwords, all preference loading/storing in the
55 * user's page and any cookies. lib/main.php will query the user object to
56 * verify the password as appropriate.
58 * @author: Reini Urban (the tricky parts),
59 * Carsten Klapp (started rolling the ball)
61 * Random architectural notes, sorted by date:
63 * 1) Now a ForbiddenUser is returned instead of false.
64 * 2) Previously ALLOW_ANON_USER = false meant that anon users cannot edit,
65 * but may browse. Now with ALLOW_ANON_USER = false he may not browse,
66 * which is needed to disable browse PagePermissions.
67 * I added now ALLOW_ANON_EDIT = true to makes things clear.
68 * (which replaces REQUIRE_SIGNIN_BEFORE_EDIT)
70 * 3) Removed pear prepare. Performance hog, and using integers as
71 * handler doesn't help. Do simple sprintf as with adodb. And a prepare
72 * in the object init is no advantage, because in the init loop a lot of
73 * objects are tried, but not used.
74 * 4) Already gotten prefs are passed to the next object to avoid
75 * duplicate getPreferences() calls.
77 * 5) Major php-5 problem: $this re-assignment is disallowed by the parser
78 * So we cannot just discrimate with
79 * if (!check_php_version(5))
81 * A /php5-patch.php is provided, which patches the src automatically
82 * for php4 and php5. Default is php4.
83 * Update: not needed anymore. we use eval to fool the load-time syntax checker.
85 * 6) enforced new cookie policy: prefs don't get stored in cookies
86 * anymore, only in homepage and/or database, but always in the
87 * current session. old pref cookies will get deleted.
89 * 7) Certain themes should be able to extend the predefined list
90 * of preferences. Display/editing is done in the theme specific userprefs.tmpl,
91 * but storage must be extended to the Get/SetPreferences methods.
92 * <theme>/themeinfo.php must provide CustomUserPreferences:
93 * A list of name => _UserPreference class pairs.
95 * Fixed a nasty recursion bug (i.e. php crash), when user = new class
96 * which returned false, did not return false on php-4.4.7. Check for
97 * a object member now.
100 define('WIKIAUTH_FORBIDDEN', -1); // Completely not allowed.
101 define('WIKIAUTH_ANON', 0); // Not signed in.
102 define('WIKIAUTH_BOGO', 1); // Any valid WikiWord is enough.
103 define('WIKIAUTH_USER', 2); // Bogo user with a password.
104 define('WIKIAUTH_ADMIN', 10); // UserName == ADMIN_USER.
105 define('WIKIAUTH_UNOBTAINABLE', 100); // Permissions that no user can achieve
107 //if (!defined('COOKIE_EXPIRATION_DAYS')) define('COOKIE_EXPIRATION_DAYS', 365);
108 //if (!defined('COOKIE_DOMAIN')) define('COOKIE_DOMAIN', '/');
109 if (!defined('EDITWIDTH_MIN_COLS')) define('EDITWIDTH_MIN_COLS', 30);
110 if (!defined('EDITWIDTH_MAX_COLS')) define('EDITWIDTH_MAX_COLS', 150);
111 if (!defined('EDITWIDTH_DEFAULT_COLS')) define('EDITWIDTH_DEFAULT_COLS', 80);
113 if (!defined('EDITHEIGHT_MIN_ROWS')) define('EDITHEIGHT_MIN_ROWS', 5);
114 if (!defined('EDITHEIGHT_MAX_ROWS')) define('EDITHEIGHT_MAX_ROWS', 80);
115 if (!defined('EDITHEIGHT_DEFAULT_ROWS')) define('EDITHEIGHT_DEFAULT_ROWS', 22);
117 define('TIMEOFFSET_MIN_HOURS', -26);
118 define('TIMEOFFSET_MAX_HOURS', 26);
119 if (!defined('TIMEOFFSET_DEFAULT_HOURS')) define('TIMEOFFSET_DEFAULT_HOURS', 0);
121 /* EMAIL VERIFICATION
122 * On certain nets or hosts the email domain cannot be determined automatically from the DNS.
123 * Provide some overrides here.
124 * ( username @ ) domain => mail-domain
126 $EMailHosts = array('avl.com' => 'mail.avl.com');
129 * There are be the following constants in config/config.ini to
130 * establish login parameters:
132 * ALLOW_ANON_USER default true
133 * ALLOW_ANON_EDIT default true
134 * ALLOW_BOGO_LOGIN default true
135 * ALLOW_USER_PASSWORDS default true
136 * PASSWORD_LENGTH_MINIMUM default 0
138 * To require user passwords for editing:
139 * ALLOW_ANON_USER = true
140 * ALLOW_ANON_EDIT = false (before named REQUIRE_SIGNIN_BEFORE_EDIT)
141 * ALLOW_BOGO_LOGIN = false
142 * ALLOW_USER_PASSWORDS = true
144 * To establish a COMPLETELY private wiki, such as an internal
146 * ALLOW_ANON_USER = false
147 * (and probably require user passwords as described above). In this
148 * case the user will be prompted to login immediately upon accessing
151 * There are other possible combinations, but the typical wiki (such
152 * as http://PhpWiki.sf.net/phpwiki) would usually just leave all four
157 // The last object in the row is the bad guy...
158 if (!is_array($USER_AUTH_ORDER))
159 $USER_AUTH_ORDER = array("Forbidden");
161 $USER_AUTH_ORDER[] = "Forbidden";
163 // Local convenience functions.
164 function _isAnonUserAllowed()
166 return (defined('ALLOW_ANON_USER') && ALLOW_ANON_USER);
169 function _isBogoUserAllowed()
171 return (defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN);
174 function _isUserPasswordsAllowed()
176 return (defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
179 // Possibly upgrade userobject functions.
180 function _determineAdminUserOrOtherUser($UserName)
182 // Sanity check. User name is a condition of the definition of the
183 // _AdminUser, _BogoUser and _passuser.
185 return $GLOBALS['ForbiddenUser'];
187 //FIXME: check admin membership later at checkPass. Now we cannot raise the level.
188 //$group = &WikiGroup::getGroup($GLOBALS['request']);
189 if ($UserName == ADMIN_USER)
190 return new _AdminUser($UserName);
191 /* elseif ($group->isMember(GROUP_ADMIN)) { // unneeded code
192 return _determineBogoUserOrPassUser($UserName);
196 return _determineBogoUserOrPassUser($UserName);
199 function _determineBogoUserOrPassUser($UserName)
201 global $ForbiddenUser;
203 // Sanity check. User name is a condition of the definition of
204 // _BogoUser and _PassUser.
206 return $ForbiddenUser;
208 // Check for password and possibly upgrade user object.
209 // $_BogoUser = new _BogoUser($UserName);
210 if (_isBogoUserAllowed() and isWikiWord($UserName)) {
211 include_once 'lib/WikiUser/BogoLogin.php';
212 $_BogoUser = new _BogoLoginPassUser($UserName);
213 if ($_BogoUser->userExists() or $GLOBALS['request']->getArg('auth'))
216 if (_isUserPasswordsAllowed()) {
217 // PassUsers override BogoUsers if a password is stored
218 if (isset($_BogoUser) and isset($_BogoUser->_prefs)
219 and $_BogoUser->_prefs->get('passwd')
221 return new _PassUser($UserName, $_BogoUser->_prefs);
223 $_PassUser = new _PassUser($UserName,
224 isset($_BogoUser) ? $_BogoUser->_prefs : false);
225 if ($_PassUser->userExists() or $GLOBALS['request']->getArg('auth')) {
226 if (isset($GLOBALS['request']->_user_class))
227 $class = $GLOBALS['request']->_user_class;
228 elseif (strtolower(get_class($_PassUser)) == "_passuser")
229 $class = $_PassUser->nextClass(); else
230 $class = get_class($_PassUser);
231 if ($user = new $class($UserName, $_PassUser->_prefs)
241 // No Bogo- or PassUser exists, or
242 // passwords are not allowed, and bogo is disallowed too.
243 // (Only the admin can sign in).
244 return $ForbiddenUser;
248 * Primary WikiUser function, called by lib/main.php.
250 * This determines the user's type and returns an appropriate user
251 * object. lib/main.php then querys the resultant object for password
252 * validity as necessary.
254 * If an _AnonUser object is returned, the user may only browse pages
255 * (and save prefs in a cookie).
257 * To disable access but provide prefs the global $ForbiddenUser class
258 * is returned. (was previously false)
261 function WikiUser($UserName = '')
263 global $ForbiddenUser, $HTTP_SESSION_VARS;
265 //Maybe: Check sessionvar for username & save username into
266 //sessionvar (may be more appropriate to do this in lib/main.php).
268 $ForbiddenUser = new _ForbiddenUser($UserName);
269 // Found a user name.
270 return _determineAdminUserOrOtherUser($UserName);
271 } elseif (!empty($HTTP_SESSION_VARS['userid'])) {
272 // Found a user name.
273 $ForbiddenUser = new _ForbiddenUser($_SESSION['userid']);
274 return _determineAdminUserOrOtherUser($_SESSION['userid']);
276 // Check for autologin pref in cookie and possibly upgrade
277 // user object to another type.
278 $_AnonUser = new _AnonUser();
279 if ($UserName = $_AnonUser->_userid && $_AnonUser->_prefs->get('autologin')) {
280 // Found a user name.
281 $ForbiddenUser = new _ForbiddenUser($UserName);
282 return _determineAdminUserOrOtherUser($UserName);
284 $ForbiddenUser = new _ForbiddenUser();
285 if (_isAnonUserAllowed())
287 return $ForbiddenUser; // User must sign in to browse pages.
293 * WikiUser.php use the name 'WikiUser'
295 function WikiUserClassname()
301 * Upgrade olduser by copying properties from user to olduser.
302 * We are not sure yet, for which php's a simple $this = $user works reliably,
303 * (on php4 it works ok, on php5 it's currently disallowed on the parser level)
304 * that's why try it the hard way.
306 function UpgradeUser($user, $newuser)
308 if (isa($user, '_WikiUser') and isa($newuser, '_WikiUser')) {
309 // populate the upgraded class $newuser with the values from the current user object
310 //only _auth_level, _current_method, _current_index,
311 if (!empty($user->_level) and
312 $user->_level > $newuser->_level
314 $newuser->_level = $user->_level;
315 if (!empty($user->_current_index) and
316 $user->_current_index > $newuser->_current_index
318 $newuser->_current_index = $user->_current_index;
319 $newuser->_current_method = $user->_current_method;
321 if (!empty($user->_authmethod))
322 $newuser->_authmethod = $user->_authmethod;
323 $GLOBALS['request']->_user_class = get_class($newuser);
325 foreach (get_object_vars($user) as $k => $v) {
326 if (!empty($v)) $olduser->$k = $v;
329 $newuser->hasHomePage(); // revive db handle, because these don't survive sessions
330 //$GLOBALS['request']->_user = $olduser;
338 * Probably not needed, since we use the various user objects methods so far.
339 * Anyway, here it is, looping through all available objects.
341 function UserExists($UserName)
344 if (!($user = $request->getUser()))
345 $user = WikiUser($UserName);
348 if ($user->userExists($UserName)) {
349 $request->_user = $user;
352 if (isa($user, '_BogoUser'))
353 $user = new _PassUser($UserName, $user->_prefs);
354 $class = $user->nextClass();
355 if ($user = new $class($UserName, $user->_prefs)) {
356 return $user->userExists($UserName);
358 $request->_user = $GLOBALS['ForbiddenUser'];
362 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
365 * Base WikiUser class.
369 public $_userid = '';
370 public $_level = WIKIAUTH_ANON;
371 public $_prefs = false;
372 public $_HomePagehandle = false;
375 function _WikiUser($UserName = '', $prefs = false)
378 $this->_userid = $UserName;
379 $this->_HomePagehandle = false;
381 $this->hasHomePage();
383 if (empty($this->_prefs)) {
384 if ($prefs) $this->_prefs = $prefs;
385 else $this->getPreferences();
391 if (!empty($this->_userid)) {
392 return $this->_userid;
398 function getPreferences()
400 trigger_error("DEBUG: Note: undefined _WikiUser class trying to load prefs." . " "
401 . "New subclasses of _WikiUser must override this function.");
405 function setPreferences($prefs, $id_only)
407 trigger_error("DEBUG: Note: undefined _WikiUser class trying to save prefs."
409 . "New subclasses of _WikiUser must override this function.");
413 function userExists()
415 return $this->hasHomePage();
418 function checkPass($submitted_password)
420 // By definition, an undefined user class cannot sign in.
421 trigger_error("DEBUG: Warning: undefined _WikiUser class trying to sign in."
423 . "New subclasses of _WikiUser must override this function.");
427 // returns page_handle to user's home page or false if none
428 function hasHomePage()
430 if ($this->_userid) {
431 if (!empty($this->_HomePagehandle) and is_object($this->_HomePagehandle)) {
432 return $this->_HomePagehandle->exists();
434 // check db again (maybe someone else created it since
437 $this->_HomePagehandle = $request->getPage($this->_userid);
438 return $this->_HomePagehandle->exists();
445 function createHomePage()
448 $versiondata = array('author' => ADMIN_USER);
449 $request->_dbi->save(_("Automatically created user homepage to be able to store UserPreferences.") .
450 "\n{{Template/UserPage}}",
452 $request->_dbi->touch();
453 $this->_HomePagehandle = $request->getPage($this->_userid);
456 // innocent helper: case-insensitive position in _auth_methods
457 function array_position($string, $array)
459 $string = strtolower($string);
460 for ($found = 0; $found < count($array); $found++) {
461 if (strtolower($array[$found]) == $string)
467 function nextAuthMethodIndex()
469 if (empty($this->_auth_methods))
470 $this->_auth_methods = $GLOBALS['USER_AUTH_ORDER'];
471 if (empty($this->_current_index)) {
472 if (strtolower(get_class($this)) != '_passuser') {
473 $this->_current_method = substr(get_class($this), 1, -8);
474 $this->_current_index = $this->array_position($this->_current_method,
475 $this->_auth_methods);
477 $this->_current_index = -1;
480 $this->_current_index++;
481 if ($this->_current_index >= count($this->_auth_methods))
483 $this->_current_method = $this->_auth_methods[$this->_current_index];
484 return $this->_current_index;
487 function AuthMethod($index = false)
489 return $this->_auth_methods[$index === false
490 ? count($this->_auth_methods) - 1
494 // upgrade the user object
497 $method = $this->AuthMethod($this->nextAuthMethodIndex());
498 include_once("lib/WikiUser/$method.php");
499 return "_" . $method . "PassUser";
502 //Fixme: for _HttpAuthPassUser
503 function PrintLoginForm(&$request, $args, $fail_message = false,
504 $separate_page = false)
506 include_once 'lib/Template.php';
507 // Call update_locale in case the system's default language is not 'en'.
508 // (We have no user pref for lang at this point yet, no one is logged in.)
509 if ($GLOBALS['LANG'] != DEFAULT_LANGUAGE)
510 update_locale(DEFAULT_LANGUAGE);
511 $userid = $this->_userid;
513 extract($args); // fixme
515 $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
517 $pagename = $request->getArg('pagename');
519 $login = Template('login',
520 compact('pagename', 'userid', 'require_level',
521 'fail_message', 'pass_required', 'nocache'));
522 // check if the html template was already processed
523 $separate_page = $separate_page ? true : !alreadyTemplateProcessed('html');
524 if ($separate_page) {
525 $page = $request->getPage($pagename);
526 $revision = $page->getCurrentRevision();
527 return GeneratePage($login, _("Sign In"), $revision);
529 return $login->printExpansion();
533 /** Signed in but not password checked or empty password.
535 function isSignedIn()
537 return (isa($this, '_BogoUser') or isa($this, '_PassUser'));
540 /** This is password checked for sure.
542 function isAuthenticated()
544 //return isa($this,'_PassUser');
545 //return isa($this,'_BogoUser') || isa($this,'_PassUser');
546 return $this->_level >= WIKIAUTH_BOGO;
552 if ($this->_level == WIKIAUTH_ADMIN) return true;
553 if (!$this->isSignedIn()) return false;
554 if (!$this->isAuthenticated()) return false;
556 if (!$group) $group = &$GLOBALS['request']->getGroup();
557 return ($this->_level > WIKIAUTH_BOGO and $group->isMember(GROUP_ADMIN));
560 /** Name or IP for a signed user. UserName could come from a cookie e.g.
564 return ($this->UserName()
566 : $GLOBALS['request']->get('REMOTE_ADDR'));
569 /** Name for an authenticated user. No IP here.
571 function getAuthenticatedId()
573 return ($this->isAuthenticated()
575 : ''); //$GLOBALS['request']->get('REMOTE_ADDR') );
578 function hasAuthority($require_level)
580 return $this->_level >= $require_level;
583 /* This is quite restrictive and not according the login description online.
584 Any word char (A-Za-z0-9_), " ", ".", "@" and "-"
585 The backends may loosen or tighten this.
587 function isValidName($userid = false)
589 if (!$userid) $userid = $this->_userid;
590 if (!$userid) return false;
591 if (defined('FUSIONFORGE') and FUSIONFORGE) {
594 return preg_match("/^[\-\w\.@ ]+$/U", $userid) and strlen($userid) < 32;
598 * Called on an auth_args POST request, such as login, logout or signin.
599 * TODO: Check BogoLogin users with empty password. (self-signed users)
601 function AuthCheck($postargs)
603 // Normalize args, and extract.
604 $keys = array('userid', 'passwd', 'require_level', 'login', 'logout',
606 foreach ($keys as $key)
607 $args[$key] = isset($postargs[$key]) ? $postargs[$key] : false;
609 $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
611 if ($logout) { // Log out
612 if (LOGIN_LOG and is_writeable(LOGIN_LOG)) {
614 $zone_offset = Request_AccessLogEntry::_zone_offset();
615 $ncsa_time = date("d/M/Y:H:i:s", time());
616 $entry = sprintf('%s - %s - [%s %s] "%s" %s - "%s" "%s"',
617 (string)$request->get('REMOTE_HOST'),
618 (string)$request->_user->_userid,
619 $ncsa_time, $zone_offset,
620 "logout " . get_class($request->_user),
622 (string)$request->get('HTTP_REFERER'),
623 (string)$request->get('HTTP_USER_AGENT')
625 if (($fp = fopen(LOGIN_LOG, "a"))) {
627 fputs($fp, "$entry\n");
630 //error_log("$entry\n", 3, LOGIN_LOG);
632 if (method_exists($GLOBALS['request']->_user, "logout")) { //_HttpAuthPassUser
633 $GLOBALS['request']->_user->logout();
635 $user = new _AnonUser();
637 $user->_level = WIKIAUTH_ANON;
640 return false; // User hit cancel button.
641 elseif (!$login && !$userid)
642 return false; // Nothing to do?
644 if (!$this->isValidName($userid))
645 return _("Invalid username.");
648 $authlevel = $this->checkPass($passwd === false ? '' : $passwd);
650 if (LOGIN_LOG and is_writeable(LOGIN_LOG)) {
652 $zone_offset = Request_AccessLogEntry::_zone_offset();
653 $ncsa_time = date("d/M/Y:H:i:s", time());
654 $manglepasswd = $passwd;
655 for ($i = 0; $i < strlen($manglepasswd); $i++) {
656 $c = substr($manglepasswd, $i, 1);
657 if (ord($c) < 32) $manglepasswd[$i] = "<";
658 elseif ($c == '*') $manglepasswd[$i] = "*"; elseif ($c == '?') $manglepasswd[$i] = "?"; elseif ($c == '(') $manglepasswd[$i] = "("; elseif ($c == ')') $manglepasswd[$i] = ")"; elseif ($c == "\\") $manglepasswd[$i] = "\\"; elseif (ord($c) < 127) $manglepasswd[$i] = "x"; elseif (ord($c) >= 127) $manglepasswd[$i] = ">";
660 if ((DEBUG & _DEBUG_LOGIN) and $authlevel <= 0) $manglepasswd = $passwd;
661 $entry = sprintf('%s - %s - [%s %s] "%s" %s - "%s" "%s"',
662 $request->get('REMOTE_HOST'),
663 (string)$request->_user->_userid,
664 $ncsa_time, $zone_offset,
665 "login $userid/$manglepasswd => $authlevel " . get_class($request->_user),
666 $authlevel > 0 ? "200" : "403",
667 (string)$request->get('HTTP_REFERER'),
668 (string)$request->get('HTTP_USER_AGENT')
670 if (($fp = fopen(LOGIN_LOG, "a"))) {
672 fputs($fp, "$entry\n");
675 //error_log("$entry\n", 3, LOGIN_LOG);
678 if ($authlevel <= 0) { // anon or forbidden
680 return _("Invalid password.");
682 return _("Invalid password or userid.");
683 } elseif ($authlevel < $require_level) { // auth ok, but not enough
684 if (!empty($this->_current_method) and strtolower(get_class($this)) == '_passuser') {
686 $class = "_" . $this->_current_method . "PassUser";
687 include_once 'lib/WikiUser/' . $this->_current_method . '.php';
688 $user = new $class($userid, $this->_prefs);
689 $this->_level = $authlevel;
692 $this->_userid = $userid;
693 $this->_level = $authlevel;
694 return _("Insufficient permissions.");
698 //$user = $GLOBALS['request']->_user;
699 if (!empty($this->_current_method) and
700 strtolower(get_class($this)) == '_passuser'
703 $class = "_" . $this->_current_method . "PassUser";
704 include_once 'lib/WikiUser/' . $this->_current_method . '.php';
705 $user = new $class($userid, $this->_prefs);
706 $user->_level = $authlevel;
709 $this->_userid = $userid;
710 $this->_level = $authlevel;
717 * Not authenticated in user, but he may be signed in. Basicly with view access only.
718 * prefs are stored in cookies, but only the userid.
723 public $_level = WIKIAUTH_ANON;
725 /** Anon only gets to load and save prefs in a cookie, that's it.
727 function getPreferences()
731 if (empty($this->_prefs))
732 $this->_prefs = new UserPreferences;
733 $UserName = $this->UserName();
735 // Try to read deprecated 1.3.x style cookies
736 if ($cookie = $request->cookies->get_old(WIKI_NAME)) {
737 if (!$unboxedcookie = $this->_prefs->retrieve($cookie)) {
738 trigger_error(_("Empty Preferences or format of UserPreferences cookie not recognised.")
740 . sprintf("%s='%s'", WIKI_NAME, $cookie)
742 . _("Default preferences will be used."),
746 * Only set if it matches the UserName who is
747 * signing in or if this really is an Anon login (no
748 * username). (Remember, _BogoUser and higher inherit this
751 if (!$UserName || $UserName == @$unboxedcookie['userid']) {
752 $this->_prefs->updatePrefs($unboxedcookie);
753 $UserName = @$unboxedcookie['userid'];
754 if (is_string($UserName) and (substr($UserName, 0, 2) != 's:'))
755 $this->_userid = $UserName;
759 // v1.3.8 policy: don't set PhpWiki cookies, only plaintext WIKI_ID cookies
761 $request->deleteCookieVar(WIKI_NAME);
763 // Try to read deprecated 1.3.4 style cookies
764 if (!$UserName and ($cookie = $request->cookies->get_old("WIKI_PREF2"))) {
765 if (!$unboxedcookie = $this->_prefs->retrieve($cookie)) {
766 if (!$UserName || $UserName == $unboxedcookie['userid']) {
767 $this->_prefs->updatePrefs($unboxedcookie);
768 $UserName = $unboxedcookie['userid'];
769 if (is_string($UserName) and (substr($UserName, 0, 2) != 's:'))
770 $this->_userid = $UserName;
775 $request->deleteCookieVar("WIKI_PREF2");
779 // Try reading userid from old PhpWiki cookie formats:
780 if ($cookie = $request->cookies->get_old(getCookieName())) {
781 if (is_string($cookie) and (substr($cookie, 0, 2) != 's:'))
783 elseif (is_array($cookie) and !empty($cookie['userid']))
784 $UserName = $cookie['userid'];
786 if (!$UserName and !headers_sent())
787 $request->deleteCookieVar(getCookieName());
789 $this->_userid = $UserName;
792 // initializeTheme() needs at least an empty object
794 if (empty($this->_prefs))
795 $this->_prefs = new UserPreferences;
797 return $this->_prefs;
800 /** _AnonUser::setPreferences(): Save prefs in a cookie and session and update all global vars
802 * Allow for multiple wikis in same domain. Encode only the
803 * _prefs array of the UserPreference object. Ideally the
804 * prefs array should just be imploded into a single string or
805 * something so it is completely human readable by the end
806 * user. In that case stricter error checking will be needed
807 * when loading the cookie.
809 function setPreferences($prefs, $id_only = false)
811 if (!is_object($prefs)) {
812 if (is_object($this->_prefs)) {
813 $updated = $this->_prefs->updatePrefs($prefs);
814 $prefs =& $this->_prefs;
816 // update the prefs values from scratch. This could lead to unnecessary
817 // side-effects: duplicate emailVerified, ...
818 $this->_prefs = new UserPreferences($prefs);
822 if (!isset($this->_prefs))
823 $this->_prefs =& $prefs;
825 $updated = $this->_prefs->isChanged($prefs);
828 if ($id_only and !headers_sent()) {
830 // new 1.3.8 policy: no array cookies, only plain userid string as in
831 // the pre 1.3.x versions.
832 // prefs should be stored besides the session in the homepagehandle or in a db.
833 $request->setCookieVar(getCookieName(), $this->_userid,
834 COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
835 //$request->setCookieVar(WIKI_NAME, array('userid' => $prefs->get('userid')),
836 // COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
839 if (is_object($prefs)) {
840 $packed = $prefs->store();
841 $unpacked = $prefs->unpack($packed);
842 if (count($unpacked)) {
843 foreach (array('_method', '_select', '_update', '_insert') as $param) {
844 if (!empty($this->_prefs->{$param}))
845 $prefs->{$param} = $this->_prefs->{$param};
847 $this->_prefs = $prefs;
853 function userExists()
858 function checkPass($submitted_password)
866 * Helper class to finish the PassUser auth loop.
867 * This is added automatically to USER_AUTH_ORDER.
872 public $_level = WIKIAUTH_FORBIDDEN;
874 function checkPass($submitted_password)
876 return WIKIAUTH_FORBIDDEN;
879 function userExists()
881 if ($this->_HomePagehandle) return true;
887 * Do NOT extend _BogoUser to other classes, for checkPass()
888 * security. (In case of defects in code logic of the new class!)
889 * The intermediate step between anon and passuser.
890 * We also have the _BogoLoginPassUser class with stricter
891 * password checking, which fits into the auth loop.
892 * Note: This class is not called anymore by WikiUser()
897 function userExists()
899 if (isWikiWord($this->_userid)) {
900 $this->_level = WIKIAUTH_BOGO;
903 $this->_level = WIKIAUTH_ANON;
908 function checkPass($submitted_password)
910 // By definition, BogoUser has an empty password.
912 return $this->_level;
919 * Called if ALLOW_USER_PASSWORDS and Anon and Bogo failed.
921 * The classes for all subsequent auth methods extend from this class.
922 * This handles the auth method type dispatcher according $USER_AUTH_ORDER,
923 * the three auth method policies first-only, strict and stacked
924 * and the two methods for prefs: homepage or database,
925 * if $DBAuthParams['pref_select'] is defined.
927 * Default is PersonalPage auth and prefs.
929 * @author: Reini Urban
933 public $_auth_dbi, $_prefs;
934 public $_current_method, $_current_index;
936 // check and prepare the auth and pref methods only once
937 function _PassUser($UserName = '', $prefs = false)
939 //global $DBAuthParams, $DBParams;
941 /*if (!$this->isValidName($UserName))
943 $this->_userid = $UserName;
944 if ($this->hasHomePage())
945 $this->_HomePagehandle = $GLOBALS['request']->getPage($this->_userid);
947 $this->_authmethod = substr(get_class($this), 1, -8);
948 if ($this->_authmethod == 'a') $this->_authmethod = 'admin';
950 // Check the configured Prefs methods
951 $dbi = $this->getAuthDbh();
952 $dbh = $GLOBALS['request']->getDbh();
955 and !isset($this->_prefs->_select)
956 and $dbh->getAuthParam('pref_select')
958 if (!$this->_prefs) {
959 $this->_prefs = new UserPreferences();
962 $this->_prefs->_method = $dbh->getParam('dbtype');
963 $this->_prefs->_select = $this->prepare($dbh->getAuthParam('pref_select'), "userid");
965 if (!isset($this->_prefs->_update) and $dbh->getAuthParam('pref_update')) {
966 $this->_prefs->_update = $this->prepare($dbh->getAuthParam('pref_update'),
967 array("userid", "pref_blob"));
970 if (!$this->_prefs) {
971 $this->_prefs = new UserPreferences();
974 $this->_prefs->_method = 'HomePage';
977 if (!$this->_prefs or isset($need_pref)) {
978 if ($prefs) $this->_prefs = $prefs;
979 else $this->getPreferences();
982 // Upgrade to the next parent _PassUser class. Avoid recursion.
983 if (strtolower(get_class($this)) === '_passuser') {
984 //auth policy: Check the order of the configured auth methods
985 // 1. first-only: Upgrade the class here in the constructor
986 // 2. old: ignore USER_AUTH_ORDER and try to use all available methods as
987 /// in the previous PhpWiki releases (slow)
988 // 3. strict: upgrade the class after checking the user existance in userExists()
989 // 4. stacked: upgrade the class after the password verification in checkPass()
990 // Methods: PersonalPage, HttpAuth, DB, Ldap, Imap, File
991 //if (!defined('USER_AUTH_POLICY')) define('USER_AUTH_POLICY','old');
992 if (defined('USER_AUTH_POLICY')) {
993 // policy 1: only pre-define one method for all users
994 if (USER_AUTH_POLICY === 'first-only') {
995 $class = $this->nextClass();
996 return new $class($UserName, $this->_prefs);
997 } // Use the default behaviour from the previous versions:
998 elseif (USER_AUTH_POLICY === 'old') {
999 // Default: try to be smart
1000 // On php5 we can directly return and upgrade the Object,
1001 // before we have to upgrade it manually.
1002 if (!empty($GLOBALS['PHP_AUTH_USER']) or !empty($_SERVER['REMOTE_USER'])) {
1003 include_once 'lib/WikiUser/HttpAuth.php';
1004 return new _HttpAuthPassUser($UserName, $this->_prefs);
1005 } elseif (in_array('Db', $dbh->getAuthParam('USER_AUTH_ORDER')) and
1006 $dbh->getAuthParam('auth_check') and
1007 ($dbh->getAuthParam('auth_dsn') or $dbh->getParam('dsn'))
1009 return new _DbPassUser($UserName, $this->_prefs);
1010 } elseif (in_array('LDAP', $dbh->getAuthParam('USER_AUTH_ORDER')) and
1011 defined('LDAP_AUTH_HOST') and defined('LDAP_BASE_DN') and
1012 function_exists('ldap_connect')
1014 include_once 'lib/WikiUser/LDAP.php';
1015 return new _LDAPPassUser($UserName, $this->_prefs);
1016 } elseif (in_array('IMAP', $dbh->getAuthParam('USER_AUTH_ORDER')) and
1017 defined('IMAP_AUTH_HOST') and function_exists('imap_open')
1019 include_once 'lib/WikiUser/IMAP.php';
1020 return new _IMAPPassUser($UserName, $this->_prefs);
1021 } elseif (in_array('File', $dbh->getAuthParam('USER_AUTH_ORDER')) and
1022 defined('AUTH_USER_FILE') and file_exists(AUTH_USER_FILE)
1024 include_once 'lib/WikiUser/File.php';
1025 return new _FilePassUser($UserName, $this->_prefs);
1027 include_once 'lib/WikiUser/PersonalPage.php';
1028 return new _PersonalPagePassUser($UserName, $this->_prefs);
1031 // else use the page methods defined in _PassUser.
1037 function getAuthDbh()
1039 global $request; //, $DBParams, $DBAuthParams;
1041 $dbh = $request->getDbh();
1042 // session restauration doesn't re-connect to the database automatically,
1043 // so dirty it here, to force a reconnect.
1044 if (isset($this->_auth_dbi)) {
1045 if (($dbh->getParam('dbtype') == 'SQL') and empty($this->_auth_dbi->connection))
1046 unset($this->_auth_dbi);
1047 if (($dbh->getParam('dbtype') == 'ADODB') and empty($this->_auth_dbi->_connectionID))
1048 unset($this->_auth_dbi);
1050 if (empty($this->_auth_dbi)) {
1051 if ($dbh->getParam('dbtype') != 'SQL'
1052 and $dbh->getParam('dbtype') != 'ADODB'
1053 and $dbh->getParam('dbtype') != 'PDO'
1056 if (empty($GLOBALS['DBAuthParams']))
1058 if (!$dbh->getAuthParam('auth_dsn')) {
1059 $dbh = $request->getDbh(); // use phpwiki database
1060 } elseif ($dbh->getAuthParam('auth_dsn') == $dbh->getParam('dsn')) {
1061 $dbh = $request->getDbh(); // same phpwiki database
1062 } else { // use another external database handle. needs PHP >= 4.1
1063 $local_params = array_merge($GLOBALS['DBParams'], $GLOBALS['DBAuthParams']);
1064 $local_params['dsn'] = $local_params['auth_dsn'];
1065 $dbh = WikiDB::open($local_params);
1067 $this->_auth_dbi =& $dbh->_backend->_dbh;
1069 return $this->_auth_dbi;
1072 function _normalize_stmt_var($var, $oldstyle = false)
1074 static $valid_variables = array('userid', 'password', 'pref_blob', 'groupname');
1075 // old-style: "'$userid'"
1076 // new-style: '"\$userid"' or just "userid"
1077 $new = str_replace(array("'", '"', '\$', '$'), '', $var);
1078 if (!in_array($new, $valid_variables)) {
1079 trigger_error("Unknown DBAuthParam statement variable: " . $new, E_USER_ERROR);
1082 return !$oldstyle ? "'$" . $new . "'" : '\$' . $new;
1085 // TODO: use it again for the auth and member tables
1086 // sprintfstyle vs prepare style: %s or ?
1087 // multiple vars should be executed via prepare(?,?)+execute,
1088 // single vars with execute(sprintf(quote(var)))
1089 // help with position independency
1090 function prepare($stmt, $variables, $oldstyle = false, $sprintfstyle = true)
1093 $dbi = $request->getDbh();
1094 $this->getAuthDbh();
1095 // "'\$userid"' => %s
1096 // variables can be old-style: '"\$userid"' or new-style: "'$userid'" or just "userid"
1097 // old-style strings don't survive pear/Config/IniConfig treatment, that's why we changed it.
1099 if (is_array($variables)) {
1100 //$sprintfstyle = false;
1101 for ($i = 0; $i < count($variables); $i++) {
1102 $var = $this->_normalize_stmt_var($variables[$i], $oldstyle);
1104 trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
1105 $variables[$i], $stmt), E_USER_WARNING);
1106 $variables[$i] = $var;
1107 if (!$var) $new[] = '';
1109 $s = "%" . ($i + 1) . "s";
1110 $new[] = $sprintfstyle ? $s : "?";
1114 $var = $this->_normalize_stmt_var($variables, $oldstyle);
1116 trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
1117 $variables, $stmt), E_USER_WARNING);
1119 if (!$var) $new = '';
1120 else $new = $sprintfstyle ? '%s' : "?";
1122 $prefix = $dbi->getParam('prefix');
1123 // probably prefix table names if in same database
1124 if ($prefix and isset($this->_auth_dbi) and isset($dbi->_backend->_dbh) and
1125 ($dbi->getAuthParam('auth_dsn') and $dbi->getParam('dsn') == $dbi->getAuthParam('auth_dsn'))
1127 if (!stristr($stmt, $prefix)) {
1129 $stmt = str_replace(array(" user ", " pref ", " member "),
1130 array(" " . $prefix . "user ",
1131 " " . $prefix . "pref ",
1132 " " . $prefix . "member "), $stmt);
1133 //Do it automatically for the lazy admin? Esp. on sf.net it's nice to have
1134 trigger_error("Need to prefix the DBAUTH tablename in config/config.ini:\n $oldstmt \n=> $stmt",
1138 // Preparate the SELECT statement, for ADODB and PearDB (MDB not).
1139 // Simple sprintf-style.
1140 $new_stmt = str_replace($variables, $new, $stmt);
1141 if ($new_stmt == $stmt) {
1143 trigger_error(sprintf("DbAuthParams: Invalid statement in %s",
1144 $stmt), E_USER_WARNING);
1146 trigger_error(sprintf("DbAuthParams: Old statement quoting style in %s",
1147 $stmt), E_USER_WARNING);
1148 $new_stmt = $this->prepare($stmt, $variables, 'oldstyle');
1154 function getPreferences()
1156 if (!empty($this->_prefs->_method)) {
1157 if ($this->_prefs->_method == 'ADODB') {
1158 // FIXME: strange why this should be needed...
1159 include_once 'lib/WikiUser/Db.php';
1160 include_once 'lib/WikiUser/AdoDb.php';
1161 return _AdoDbPassUser::getPreferences();
1162 } elseif ($this->_prefs->_method == 'SQL') {
1163 include_once 'lib/WikiUser/Db.php';
1164 include_once 'lib/WikiUser/PearDb.php';
1165 return _PearDbPassUser::getPreferences();
1166 } elseif ($this->_prefs->_method == 'PDO') {
1167 include_once 'lib/WikiUser/Db.php';
1168 include_once 'lib/WikiUser/PdoDb.php';
1169 return _PdoDbPassUser::getPreferences();
1173 // We don't necessarily have to read the cookie first. Since
1174 // the user has a password, the prefs stored in the homepage
1175 // cannot be arbitrarily altered by other Bogo users.
1176 _AnonUser::getPreferences();
1177 // User may have deleted cookie, retrieve from his
1178 // PersonalPage if there is one.
1179 if (!empty($this->_HomePagehandle)) {
1180 if ($restored_from_page = $this->_prefs->retrieve
1181 ($this->_HomePagehandle->get('pref'))
1183 $this->_prefs->updatePrefs($restored_from_page, 'init');
1184 return $this->_prefs;
1187 return $this->_prefs;
1190 function setPreferences($prefs, $id_only = false)
1192 if (!empty($this->_prefs->_method)) {
1193 if ($this->_prefs->_method == 'ADODB') {
1194 // FIXME: strange why this should be needed...
1195 include_once 'lib/WikiUser/Db.php';
1196 include_once 'lib/WikiUser/AdoDb.php';
1197 return _AdoDbPassUser::setPreferences($prefs, $id_only);
1198 } elseif ($this->_prefs->_method == 'SQL') {
1199 include_once 'lib/WikiUser/Db.php';
1200 include_once 'lib/WikiUser/PearDb.php';
1201 return _PearDbPassUser::setPreferences($prefs, $id_only);
1202 } elseif ($this->_prefs->_method == 'PDO') {
1203 include_once 'lib/WikiUser/Db.php';
1204 include_once 'lib/WikiUser/PdoDb.php';
1205 return _PdoDbPassUser::setPreferences($prefs, $id_only);
1208 if ($updated = _AnonUser::setPreferences($prefs, $id_only)) {
1209 // Encode only the _prefs array of the UserPreference object
1210 // If no DB method exists to store the prefs we must store it in the page, not in the cookies.
1211 if (empty($this->_HomePagehandle)) {
1212 $this->_HomePagehandle = $GLOBALS['request']->getPage($this->_userid);
1214 if (!$this->_HomePagehandle->exists()) {
1215 $this->createHomePage();
1217 if (!empty($this->_HomePagehandle) and !$id_only) {
1218 $this->_HomePagehandle->set('pref', $this->_prefs->store());
1224 function mayChangePass()
1229 //The default method is getting the password from prefs.
1230 // child methods obtain $stored_password from external auth.
1231 function userExists()
1233 //if ($this->_HomePagehandle) return true;
1234 if (strtolower(get_class($this)) == "_passuser") {
1235 $class = $this->nextClass();
1236 $user = new $class($this->_userid, $this->_prefs);
1240 /* new user => false does not return false, but the _userid is empty then */
1241 while ($user and $user->_userid) {
1242 $user = UpgradeUser($this, $user);
1243 if ($user->userExists()) {
1244 $user = UpgradeUser($this, $user);
1247 // prevent endless loop. does this work on all PHP's?
1248 // it just has to set the classname, what it correctly does.
1249 $class = $user->nextClass();
1250 if ($class == "_ForbiddenPassUser")
1256 //The default method is getting the password from prefs.
1257 // child methods obtain $stored_password from external auth.
1258 function checkPass($submitted_password)
1260 $stored_password = $this->_prefs->get('passwd');
1261 if ($this->_checkPass($submitted_password, $stored_password)) {
1262 $this->_level = WIKIAUTH_USER;
1263 return $this->_level;
1265 if ((USER_AUTH_POLICY === 'strict') and $this->userExists()) {
1266 $this->_level = WIKIAUTH_FORBIDDEN;
1267 return $this->_level;
1269 return $this->_tryNextPass($submitted_password);
1273 function _checkPassLength($submitted_password)
1275 if (strlen($submitted_password) < PASSWORD_LENGTH_MINIMUM) {
1276 trigger_error(_("The length of the password is shorter than the system policy allows."));
1283 * The basic password checker for all PassUser objects.
1284 * Uses global ENCRYPTED_PASSWD and PASSWORD_LENGTH_MINIMUM.
1285 * Empty passwords are always false!
1286 * PASSWORD_LENGTH_MINIMUM is enforced here and in the preference set method.
1287 * @see UserPreferences::set
1289 * DBPassUser password's have their own crypt definition.
1290 * That's why DBPassUser::checkPass() doesn't call this method, if
1291 * the db password method is 'plain', which means that the DB SQL
1292 * statement just returns 1 or 0. To use CRYPT() or PASSWORD() and
1293 * don't store plain passwords in the DB.
1295 * TODO: remove crypt() function check from config.php:396 ??
1297 function _checkPass($submitted_password, $stored_password)
1299 if (!empty($submitted_password)) {
1300 // This works only on plaintext passwords.
1301 if (!ENCRYPTED_PASSWD and (strlen($stored_password) < PASSWORD_LENGTH_MINIMUM)) {
1302 // With the EditMetaData plugin
1303 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."));
1306 if (!$this->_checkPassLength($submitted_password)) {
1309 if (ENCRYPTED_PASSWD) {
1310 // Verify against encrypted password.
1311 if (function_exists('crypt')) {
1312 if (crypt($submitted_password, $stored_password) == $stored_password)
1313 return true; // matches encrypted password
1317 trigger_error(_("The crypt function is not available in this version of PHP.") . " "
1318 . _("Please set ENCRYPTED_PASSWD to false in config/config.ini and probably change ADMIN_PASSWD."),
1323 // Verify against cleartext password.
1324 if ($submitted_password == $stored_password)
1327 // Check whether we forgot to enable ENCRYPTED_PASSWD
1328 if (function_exists('crypt')) {
1329 if (crypt($submitted_password, $stored_password) == $stored_password) {
1330 trigger_error(_("Please set ENCRYPTED_PASSWD to true in config/config.ini."),
1341 /** The default method is storing the password in prefs.
1342 * Child methods (DB, File) may store in external auth also, but this
1343 * must be explicitly enabled.
1344 * This may be called by plugin/UserPreferences or by ->SetPreferences()
1346 function changePass($submitted_password)
1348 $stored_password = $this->_prefs->get('passwd');
1349 // check if authenticated
1350 if (!$this->isAuthenticated()) return false;
1351 if (ENCRYPTED_PASSWD) {
1352 $submitted_password = crypt($submitted_password);
1354 // check other restrictions, with side-effects only.
1355 $result = $this->_checkPass($submitted_password, $stored_password);
1356 if ($stored_password != $submitted_password) {
1357 $this->_prefs->set('passwd', $submitted_password);
1358 //update the storage (session, homepage, ...)
1359 $this->SetPreferences($this->_prefs);
1362 //Todo: return an error msg to the caller what failed?
1363 // same password or no privilege
1364 return ENCRYPTED_PASSWD ? true : false;
1367 function _tryNextPass($submitted_password)
1369 if (DEBUG & _DEBUG_LOGIN) {
1370 $class = strtolower(get_class($this));
1371 if (substr($class, -10) == "dbpassuser") $class = "_dbpassuser";
1372 $GLOBALS['USER_AUTH_ERROR'][$class] = 'wrongpass';
1374 if (USER_AUTH_POLICY === 'strict') {
1375 $class = $this->nextClass();
1376 if ($user = new $class($this->_userid, $this->_prefs)) {
1377 if ($user->userExists()) {
1378 return $user->checkPass($submitted_password);
1382 if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
1383 $class = $this->nextClass();
1384 if ($user = new $class($this->_userid, $this->_prefs))
1385 return $user->checkPass($submitted_password);
1387 return $this->_level;
1390 function _tryNextUser()
1392 if (DEBUG & _DEBUG_LOGIN) {
1393 $class = strtolower(get_class($this));
1394 if (substr($class, -10) == "dbpassuser") $class = "_dbpassuser";
1395 $GLOBALS['USER_AUTH_ERROR'][$class] = 'nosuchuser';
1397 if (USER_AUTH_POLICY === 'strict'
1398 or USER_AUTH_POLICY === 'stacked'
1400 $class = $this->nextClass();
1401 while ($user = new $class($this->_userid, $this->_prefs)) {
1402 $user = UpgradeUser($this, $user);
1403 if ($user->userExists()) {
1404 $user = UpgradeUser($this, $user);
1407 if ($class == "_ForbiddenPassUser") return false;
1408 $class = $this->nextClass();
1417 * Insert more auth classes here...
1418 * For example a customized db class for another db connection
1419 * or a socket-based auth server.
1424 * For security, this class should not be extended. Instead, extend
1425 * from _PassUser (think of this as unix "root").
1427 * FIXME: This should be a singleton class. Only ADMIN_USER may be of class AdminUser!
1428 * Other members of the Administrators group must raise their level otherwise somehow.
1429 * Currently every member is a AdminUser, which will not work for the various
1435 function mayChangePass()
1440 function checkPass($submitted_password)
1442 if ($this->_userid == ADMIN_USER)
1443 $stored_password = ADMIN_PASSWD;
1445 // Should not happen! Only ADMIN_USER should use this class.
1446 // return $this->_tryNextPass($submitted_password); // ???
1447 // TODO: safety check if really member of the ADMIN group?
1448 $stored_password = $this->_pref->get('passwd');
1450 if ($this->_checkPass($submitted_password, $stored_password)) {
1451 $this->_level = WIKIAUTH_ADMIN;
1452 if (!empty($GLOBALS['HTTP_SERVER_VARS']['PHP_AUTH_USER']) and class_exists("_HttpAuthPassUser")) {
1454 _HttpAuthPassUser::_fake_auth($this->_userid, $submitted_password);
1456 return $this->_level;
1458 return $this->_tryNextPass($submitted_password);
1459 //$this->_level = WIKIAUTH_ANON;
1460 //return $this->_level;
1464 function storePass($submitted_password)
1466 if ($this->_userid == ADMIN_USER)
1469 // should not happen! only ADMIN_USER should use this class.
1470 return parent::storePass($submitted_password);
1475 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1477 * Various data classes for the preference types,
1478 * to support get, set, sanify (range checking, ...)
1479 * update() will do the neccessary side-effects if a
1480 * setting gets changed (theme, language, ...)
1483 class _UserPreference
1485 public $default_value;
1487 function _UserPreference($default_value)
1489 $this->default_value = $default_value;
1492 function sanify($value)
1494 return (string)$value;
1499 if (isset($this->{$name}))
1500 return $this->{$name};
1502 return $this->default_value;
1505 function getraw($name)
1507 if (!empty($this->{$name})) {
1508 return $this->{$name};
1514 // stores the value as $this->$name, and not as $this->value (clever?)
1515 function set($name, $value)
1518 $value = $this->sanify($value);
1519 if ($this->get($name) != $value) {
1520 $this->update($value);
1523 if ($value != $this->default_value) {
1524 $this->{$name} = $value;
1526 unset($this->{$name});
1531 // default: no side-effects
1532 function update($value)
1538 class _UserPreference_numeric
1539 extends _UserPreference
1541 function _UserPreference_numeric($default, $minval = false,
1544 $this->_UserPreference((double)$default);
1545 $this->_minval = (double)$minval;
1546 $this->_maxval = (double)$maxval;
1549 function sanify($value)
1551 $value = (double)$value;
1552 if ($this->_minval !== false && $value < $this->_minval)
1553 $value = $this->_minval;
1554 if ($this->_maxval !== false && $value > $this->_maxval)
1555 $value = $this->_maxval;
1560 class _UserPreference_int
1561 extends _UserPreference_numeric
1563 function _UserPreference_int($default, $minval = false, $maxval = false)
1565 $this->_UserPreference_numeric((int)$default, (int)$minval, (int)$maxval);
1568 function sanify($value)
1570 return (int)parent::sanify((int)$value);
1574 class _UserPreference_bool
1575 extends _UserPreference
1577 function _UserPreference_bool($default = false)
1579 $this->_UserPreference((bool)$default);
1582 function sanify($value)
1584 if (is_array($value)) {
1585 /* This allows for constructs like:
1587 * <input type="hidden" name="pref[boolPref][]" value="0" />
1588 * <input type="checkbox" name="pref[boolPref][]" value="1" />
1590 * (If the checkbox is not checked, only the hidden input
1591 * gets sent. If the checkbox is sent, both inputs get
1594 foreach ($value as $val) {
1600 return (bool)$value;
1604 class _UserPreference_language
1605 extends _UserPreference
1607 function _UserPreference_language($default = DEFAULT_LANGUAGE)
1609 $this->_UserPreference($default);
1612 // FIXME: check for valid locale
1613 function sanify($value)
1615 // Revert to DEFAULT_LANGUAGE if user does not specify
1616 // language in UserPreferences or chooses <system language>.
1617 if ($value == '' or empty($value))
1618 $value = DEFAULT_LANGUAGE;
1620 return (string)$value;
1623 function update($newvalue)
1625 if (!$this->_init) {
1626 // invalidate etag to force fresh output
1627 $GLOBALS['request']->setValidators(array('%mtime' => false));
1628 update_locale($newvalue ? $newvalue : $GLOBALS['LANG']);
1633 class _UserPreference_theme
1634 extends _UserPreference
1636 function _UserPreference_theme($default = THEME)
1638 $this->_UserPreference($default);
1641 function sanify($value)
1643 if (!empty($value) and FindFile($this->_themefile($value)))
1645 return $this->default_value;
1648 function update($newvalue)
1651 // invalidate etag to force fresh output
1653 $GLOBALS['request']->setValidators(array('%mtime' => false));
1655 include_once($this->_themefile($newvalue));
1656 if (empty($WikiTheme))
1657 include_once($this->_themefile(THEME));
1660 function _themefile($theme)
1662 return "themes/$theme/themeinfo.php";
1666 class _UserPreference_notify
1667 extends _UserPreference
1669 function sanify($value)
1674 return $this->default_value;
1677 /** update to global user prefs: side-effect on set notify changes
1678 * use a global_data notify hash:
1679 * notify = array('pagematch' => array(userid => ('email' => mail,
1680 * 'verified' => 0|1),
1684 function update($value)
1686 if (!empty($this->_init)) return;
1687 $dbh = $GLOBALS['request']->getDbh();
1688 $notify = $dbh->get('notify');
1693 // expand to existing pages only or store matches?
1694 // for now we store (glob-style) matches which is easier for the user
1695 $pages = $this->_page_split($value);
1696 // Limitation: only current user.
1697 $user = $GLOBALS['request']->getUser();
1698 if (!$user or !method_exists($user, 'UserName')) return;
1699 // This fails with php5 and a WIKI_ID cookie:
1700 $userid = $user->UserName();
1701 $email = $user->_prefs->get('email');
1702 $verified = $user->_prefs->_prefs['email']->getraw('emailVerified');
1703 // check existing notify hash and possibly delete pages for email
1704 if (!empty($data)) {
1705 foreach ($data as $page => $users) {
1706 if (isset($data[$page][$userid]) and !in_array($page, $pages)) {
1707 unset($data[$page][$userid]);
1709 if (count($data[$page]) == 0)
1710 unset($data[$page]);
1713 // add the new pages
1714 if (!empty($pages)) {
1715 foreach ($pages as $page) {
1716 if (!isset($data[$page]))
1717 $data[$page] = array();
1718 if (!isset($data[$page][$userid])) {
1719 // should we really store the verification notice here or
1720 // check it dynamically at every page->save?
1722 $data[$page][$userid] = array('email' => $email,
1723 'verified' => $verified);
1725 $data[$page][$userid] = array('email' => $email);
1730 // store users changes
1731 $dbh->set('notify', $data);
1734 /** split the user-given comma or whitespace delimited pagenames
1737 function _page_split($value)
1739 return preg_split('/[\s,]+/', $value, -1, PREG_SPLIT_NO_EMPTY);
1743 class _UserPreference_email
1744 extends _UserPreference
1748 // get e-mail address from FusionForge
1749 if ((defined('FUSIONFORGE') and FUSIONFORGE) && session_loggedin()) {
1750 $user = session_get_user();
1751 return $user->getEmail();
1757 function sanify($value)
1759 // e-mail address is already checked by FusionForge
1760 if (defined('FUSIONFORGE') and FUSIONFORGE) {
1763 // check for valid email address
1764 if ($this->get('email') == $value and $this->getraw('emailVerified')) {
1768 if ($value == 1 or $value === true) {
1771 list($ok, $msg) = ValidateMail($value, 'noconnect');
1775 trigger_error("E-mail Validation Error: " . $msg, E_USER_WARNING);
1776 return $this->default_value;
1780 /** Side-effect on email changes:
1781 * Send a verification mail or for now just a notification email.
1782 * For true verification (value = 2), we'd need a mailserver hook.
1784 function update($value)
1786 // e-mail address is already checked by FusionForge
1787 if (defined('FUSIONFORGE') and FUSIONFORGE) {
1790 if (!empty($this->_init)) {
1793 $verified = $this->getraw('emailVerified');
1795 if (($value == 1 or $value === true) and $verified) {
1798 if (!empty($value) and !$verified) {
1799 list($ok, $msg) = ValidateMail($value);
1800 if ($ok and mail($value, "[" . WIKI_NAME . "] " . _("E-mail address confirmation"),
1801 sprintf(_("Welcome to %s!\nYour e-mail account is verified and\nwill be used to send page change notifications.\nSee %s"),
1802 WIKI_NAME, WikiURL($GLOBALS['request']->getArg('pagename'), '', true)))
1804 $this->set('emailVerified', 1);
1806 trigger_error($msg, E_USER_WARNING);
1812 /** Check for valid email address
1813 fixed version from http://www.zend.com/zend/spotlight/ev12apr.php
1814 Note: too strict, Bug #1053681
1816 function ValidateMail($email, $noconnect = false)
1819 $HTTP_HOST = $GLOBALS['request']->get('HTTP_HOST');
1821 // if this check is too strict (like invalid mail addresses in a local network only)
1822 // uncomment the following line:
1823 //return array(true,"not validated");
1824 // see http://sourceforge.net/tracker/index.php?func=detail&aid=1053681&group_id=6121&atid=106121
1828 // This is Paul Warren's (pdw@ex-parrot.com) monster regex for RFC822
1829 // addresses, from the Perl module Mail::RFC822::Address, reduced to
1830 // accept single RFC822 addresses without comments only. (The original
1831 // accepts groups and properly commented addresses also.)
1832 $lwsp = "(?:(?:\\r\\n)?[ \\t])";
1834 $specials = '()<>@,;:\\\\".\\[\\]';
1835 $controls = '\\000-\\031';
1837 $dtext = "[^\\[\\]\\r\\\\]";
1838 $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$lwsp*";
1840 $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$lwsp)*\"$lwsp*";
1842 $atom = "[^$specials $controls]+(?:$lwsp+|\\Z|(?=[\\[\"$specials]))";
1843 $word = "(?:$atom|$quoted_string)";
1844 $localpart = "$word(?:\\.$lwsp*$word)*";
1846 $sub_domain = "(?:$atom|$domain_literal)";
1847 $domain = "$sub_domain(?:\\.$lwsp*$sub_domain)*";
1849 $addr_spec = "$localpart\@$lwsp*$domain";
1852 $route = "(?:\@$domain(?:,\@$lwsp*$domain)*:$lwsp*)";
1853 $route_addr = "\\<$lwsp*$route?$addr_spec\\>$lwsp*";
1854 $mailbox = "(?:$addr_spec|$phrase$route_addr)";
1856 $rfc822re = "/$lwsp*$mailbox/";
1857 unset($domain, $route_addr, $route, $phrase, $addr_spec, $sub_domain, $localpart,
1858 $atom, $word, $quoted_string);
1859 unset($dtext, $controls, $specials, $lwsp, $domain_literal);
1861 if (!preg_match($rfc822re, $email)) {
1863 $result[1] = sprintf(_("E-mail address “%s” is not properly formatted"), $email);
1867 return array(true, sprintf(_("E-mail address “%s” is properly formatted"), $email));
1869 list ($Username, $Domain) = explode("@", $email);
1870 //Todo: getmxrr workaround on Windows or manual input field to verify it manually
1871 if (!isWindows() and getmxrr($Domain, $MXHost)) { // avoid warning on Windows.
1872 $ConnectAddress = $MXHost[0];
1874 $ConnectAddress = $Domain;
1875 if (isset($EMailHosts[$Domain])) {
1876 $ConnectAddress = $EMailHosts[$Domain];
1879 $Connect = @fsockopen($ConnectAddress, 25);
1881 if (ereg("^220", $Out = fgets($Connect, 1024))) {
1882 fputs($Connect, "HELO $HTTP_HOST\r\n");
1883 $Out = fgets($Connect, 1024);
1884 fputs($Connect, "MAIL FROM: <" . $email . ">\r\n");
1885 $From = fgets($Connect, 1024);
1886 fputs($Connect, "RCPT TO: <" . $email . ">\r\n");
1887 $To = fgets($Connect, 1024);
1888 fputs($Connect, "QUIT\r\n");
1890 if (!ereg("^250", $From)) {
1892 $result[1] = "Server rejected address: " . $From;
1895 if (!ereg("^250", $To)) {
1897 $result[1] = "Server rejected address: " . $To;
1902 $result[1] = "No response from server";
1907 $result[1] = "Cannot connect e-mail server.";
1911 $result[1] = "E-mail address '$email' appears to be valid.";
1913 } // end of function
1915 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1920 * This object holds the $request->_prefs subobjects.
1921 * A simple packed array of non-default values get's stored as cookie,
1922 * homepage, or database, which are converted to the array of
1924 * We don't store the objects, because otherwise we will
1925 * not be able to upgrade any subobject. And it's a waste of space also.
1928 class UserPreferences
1930 public $notifyPagesAll;
1932 function UserPreferences($saved_prefs = false)
1934 // userid stored too, to ensure the prefs are being loaded for
1935 // the correct (currently signing in) userid if stored in a
1937 // Update: for db prefs we disallow passwd.
1938 // userid is needed for pref reflexion. current pref must know its username,
1939 // if some app needs prefs from different users, different from current user.
1942 'userid' => new _UserPreference(''),
1943 'passwd' => new _UserPreference(''),
1944 'autologin' => new _UserPreference_bool(),
1945 //'emailVerified' => new _UserPreference_emailVerified(),
1946 //fixed: store emailVerified as email parameter, 1.3.8
1947 'email' => new _UserPreference_email(''),
1948 'notifyPages' => new _UserPreference_notify(''), // 1.3.8
1949 'theme' => new _UserPreference_theme(THEME),
1950 'lang' => new _UserPreference_language(DEFAULT_LANGUAGE),
1951 'editWidth' => new _UserPreference_int(EDITWIDTH_DEFAULT_COLS,
1953 EDITWIDTH_MAX_COLS),
1954 'noLinkIcons' => new _UserPreference_bool(), // 1.3.8
1955 'editHeight' => new _UserPreference_int(EDITHEIGHT_DEFAULT_ROWS,
1956 EDITHEIGHT_MIN_ROWS,
1957 EDITHEIGHT_MAX_ROWS),
1958 'timeOffset' => new _UserPreference_numeric(TIMEOFFSET_DEFAULT_HOURS,
1959 TIMEOFFSET_MIN_HOURS,
1960 TIMEOFFSET_MAX_HOURS),
1961 'ownModifications' => new _UserPreference_bool(),
1962 'majorModificationsOnly' => new _UserPreference_bool(),
1963 'relativeDates' => new _UserPreference_bool(),
1964 'googleLink' => new _UserPreference_bool(), // 1.3.10
1965 'doubleClickEdit' => new _UserPreference_bool(), // 1.3.11
1968 // This should be probably be done with $customUserPreferenceColumns
1969 // For now, we use FUSIONFORGE define
1970 if (defined('FUSIONFORGE') and FUSIONFORGE) {
1971 $fusionforgeprefs = array(
1972 'pageTrail' => new _UserPreference_bool(),
1973 'diffMenuItem' => new _UserPreference_bool(),
1974 'pageInfoMenuItem' => new _UserPreference_bool(),
1975 'pdfMenuItem' => new _UserPreference_bool(),
1976 'lockMenuItem' => new _UserPreference_bool(),
1977 'chownMenuItem' => new _UserPreference_bool(),
1978 'setaclMenuItem' => new _UserPreference_bool(),
1979 'removeMenuItem' => new _UserPreference_bool(),
1980 'renameMenuItem' => new _UserPreference_bool(),
1981 'revertMenuItem' => new _UserPreference_bool(),
1982 'backLinksMenuItem' => new _UserPreference_bool(),
1983 'watchPageMenuItem' => new _UserPreference_bool(),
1984 'recentChangesMenuItem' => new _UserPreference_bool(),
1985 'randomPageMenuItem' => new _UserPreference_bool(),
1986 'likePagesMenuItem' => new _UserPreference_bool(),
1987 'specialPagesMenuItem' => new _UserPreference_bool(),
1989 $this->_prefs = array_merge($this->_prefs, $fusionforgeprefs);
1992 // add custom theme-specific pref types:
1993 // FIXME: on theme changes the wiki_user session pref object will fail.
1994 // We will silently ignore this.
1995 if (!empty($customUserPreferenceColumns))
1996 $this->_prefs = array_merge($this->_prefs, $customUserPreferenceColumns);
1998 if (isset($this->_method) and $this->_method == 'SQL') {
1999 //unset($this->_prefs['userid']);
2000 unset($this->_prefs['passwd']);
2003 if (is_array($saved_prefs)) {
2004 foreach ($saved_prefs as $name => $value)
2005 $this->set($name, $value);
2011 foreach ($this as $key => $val) {
2012 if (is_object($val) || (is_array($val))) {
2013 $this->{$key} = unserialize(serialize($val));
2018 function _getPref($name)
2020 if ($name == 'emailVerified')
2022 if (!isset($this->_prefs[$name])) {
2023 if ($name == 'passwd2') return false;
2024 if ($name == 'passwd') return false;
2025 trigger_error("$name: unknown preference", E_USER_NOTICE);
2028 return $this->_prefs[$name];
2031 // get the value or default_value of the subobject
2034 if ($_pref = $this->_getPref($name))
2035 if ($name == 'emailVerified')
2036 return $_pref->getraw($name);
2038 return $_pref->get($name);
2043 // check and set the new value in the subobject
2044 function set($name, $value)
2046 $pref = $this->_getPref($name);
2047 if ($pref === false)
2050 /* do it here or outside? */
2051 if ($name == 'passwd' and
2052 defined('PASSWORD_LENGTH_MINIMUM') and
2053 strlen($value) <= PASSWORD_LENGTH_MINIMUM
2055 //TODO: How to notify the user?
2059 if ($name == 'theme' and $value == '')
2062 // Fix Fatal error for undefined value. Thanks to Jim Ford and Joel Schaubert
2063 if ((!$value and $pref->default_value)
2064 or ($value and !isset($pref->{$name})) // bug #1355533
2065 or ($value and ($pref->{$name} != $pref->default_value))
2067 if ($name == 'emailVerified') $newvalue = $value;
2068 else $newvalue = $pref->sanify($value);
2069 $pref->set($name, $newvalue);
2071 $this->_prefs[$name] =& $pref;
2076 * use init to avoid update on set
2078 function updatePrefs($prefs, $init = false)
2081 if ($init) $this->_init = $init;
2082 if (is_object($prefs)) {
2083 $type = 'emailVerified';
2084 $obj =& $this->_prefs['email'];
2085 $obj->_init = $init;
2086 if ($obj->get($type) !== $prefs->get($type)) {
2087 if ($obj->set($type, $prefs->get($type)))
2090 foreach (array_keys($this->_prefs) as $type) {
2091 $obj =& $this->_prefs[$type];
2092 $obj->_init = $init;
2093 if ($prefs->get($type) !== $obj->get($type)) {
2094 // special systemdefault prefs: (probably not needed)
2095 if ($type == 'theme' and $prefs->get($type) == '' and
2096 $obj->get($type) == THEME
2098 if ($type == 'lang' and $prefs->get($type) == '' and
2099 $obj->get($type) == DEFAULT_LANGUAGE
2101 if ($this->_prefs[$type]->set($type, $prefs->get($type)))
2105 } elseif (is_array($prefs)) {
2106 //unset($this->_prefs['userid']);
2108 if (isset($this->_method) and
2109 ($this->_method == 'SQL' or $this->_method == 'ADODB')) {
2110 unset($this->_prefs['passwd']);
2113 // emailVerified at first, the rest later
2114 $type = 'emailVerified';
2115 $obj =& $this->_prefs['email'];
2116 $obj->_init = $init;
2117 if (isset($prefs[$type]) and $obj->get($type) !== $prefs[$type]) {
2118 if ($obj->set($type, $prefs[$type]))
2121 foreach (array_keys($this->_prefs) as $type) {
2122 $obj =& $this->_prefs[$type];
2123 $obj->_init = $init;
2124 if (!isset($prefs[$type]) and isa($obj, "_UserPreference_bool"))
2125 $prefs[$type] = false;
2126 if (isset($prefs[$type]) and isa($obj, "_UserPreference_int"))
2127 $prefs[$type] = (int)$prefs[$type];
2128 if (isset($prefs[$type]) and $obj->get($type) != $prefs[$type]) {
2129 // special systemdefault prefs:
2130 if ($type == 'theme' and $prefs[$type] == '' and
2131 $obj->get($type) == THEME
2133 if ($type == 'lang' and $prefs[$type] == '' and
2134 $obj->get($type) == DEFAULT_LANGUAGE
2136 if ($obj->set($type, $prefs[$type]))
2144 // For now convert just array of objects => array of values
2145 // Todo: the specialized subobjects must override this.
2149 foreach ($this->_prefs as $name => $object) {
2150 if ($value = $object->getraw($name))
2151 $prefs[$name] = $value;
2152 if ($name == 'email' and ($value = $object->getraw('emailVerified')))
2153 $prefs['emailVerified'] = $value;
2154 if ($name == 'passwd' and $value and ENCRYPTED_PASSWD) {
2155 if (strlen($value) != strlen(crypt('test')))
2156 $prefs['passwd'] = crypt($value);
2157 else // already crypted
2158 $prefs['passwd'] = $value;
2162 if (defined('FUSIONFORGE') and FUSIONFORGE) {
2163 // Merge current notifyPages with notifyPagesAll
2164 // notifyPages are pages to notify in the current project
2165 // while $notifyPagesAll is used to store all the monitored pages.
2166 if (isset($prefs['notifyPages'])) {
2167 $this->notifyPagesAll[PAGE_PREFIX] = $prefs['notifyPages'];
2168 $prefs['notifyPages'] = @serialize($this->notifyPagesAll);
2172 return $this->pack($prefs);
2175 // packed string or array of values => array of values
2176 // Todo: the specialized subobjects must override this.
2177 function retrieve($packed)
2179 if (is_string($packed) and (substr($packed, 0, 2) == "a:"))
2180 $packed = unserialize($packed);
2181 if (!is_array($packed)) return false;
2183 foreach ($packed as $name => $packed_pref) {
2184 if (is_string($packed_pref)
2185 and isSerialized($packed_pref)
2186 and substr($packed_pref, 0, 2) == "O:"
2188 //legacy: check if it's an old array of objects
2189 // Looks like a serialized object.
2190 // This might fail if the object definition does not exist anymore.
2191 // object with ->$name and ->default_value vars.
2192 $pref = @unserialize($packed_pref);
2193 if (is_object($pref))
2194 $prefs[$name] = $pref->get($name);
2195 // fix old-style prefs
2196 } elseif (is_numeric($name) and is_array($packed_pref)) {
2197 if (count($packed_pref) == 1) {
2198 list($name, $value) = each($packed_pref);
2199 $prefs[$name] = $value;
2202 if (isSerialized($packed_pref))
2203 $prefs[$name] = @unserialize($packed_pref);
2204 if (empty($prefs[$name]) and isSerialized(base64_decode($packed_pref)))
2205 $prefs[$name] = @unserialize(base64_decode($packed_pref));
2206 // patched by frederik@pandora.be
2207 if (empty($prefs[$name]))
2208 $prefs[$name] = $packed_pref;
2212 if (defined('FUSIONFORGE') and FUSIONFORGE) {
2213 // Restore notifyPages from notifyPagesAll
2214 // notifyPages are pages to notify in the current project
2215 // while $notifyPagesAll is used to store all the monitored pages.
2216 if (isset($prefs['notifyPages'])) {
2217 $this->notifyPagesAll = $prefs['notifyPages'];
2218 if (isset($this->notifyPagesAll[PAGE_PREFIX])) {
2219 $prefs['notifyPages'] = $this->notifyPagesAll[PAGE_PREFIX];
2221 $prefs['notifyPages'] = '';
2230 * Check if the given prefs object is different from the current prefs object
2232 function isChanged($other)
2234 foreach ($this->_prefs as $type => $obj) {
2235 if ($obj->get($type) !== $other->get($type))
2241 function defaultPreferences()
2244 foreach ($this->_prefs as $key => $obj) {
2245 $prefs[$key] = $obj->default_value;
2253 return $this->_prefs;
2256 function pack($nonpacked)
2258 return serialize($nonpacked);
2261 function unpack($packed)
2265 //$packed = base64_decode($packed);
2266 if (substr($packed, 0, 2) == "O:") {
2267 // Looks like a serialized object
2268 return unserialize($packed);
2270 if (substr($packed, 0, 2) == "a:") {
2271 return unserialize($packed);
2273 //trigger_error("DEBUG: Can't unpack bad UserPreferences",
2280 return wikihash($this->_prefs);
2287 // c-basic-offset: 4
2288 // c-hanging-comment-ender-p: nil
2289 // indent-tabs-mode: nil