]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUserNew.php
Fix default preferences for editheight maxrows, by Manuel Vacelet.
[SourceForge/phpwiki.git] / lib / WikiUserNew.php
1 <?php //-*-php-*-
2 rcs_id('$Id: WikiUserNew.php,v 1.137 2006-05-03 06:05:37 rurban Exp $');
3 /* Copyright (C) 2004,2005 $ThePhpWikiProgrammingTeam
4  *
5  * This file is part of PhpWiki.
6  * 
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.
11  * 
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.
16  * 
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
20  */
21 /**
22  * This is a complete OOP rewrite of the old WikiUser code with various
23  * configurable external authentication methods.
24  *
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.
32  *
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.
40  *
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.
51  *
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.
55  *
56  * @author: Reini Urban (the tricky parts), 
57  *          Carsten Klapp (started rolling the ball)
58  *
59  * Random architectural notes, sorted by date:
60  * 2004-01-25 rurban
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)
68  * 2004-02-27 rurban:
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.
75  * 2004-03-18 rurban
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))
79  *          $this = $user;
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.
83  * 2004-03-24 rurban
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.
87  * 2004-04-04 rurban
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.
93  */
94
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
101
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);
107
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);
111
112 define('TIMEOFFSET_MIN_HOURS', -26);
113 define('TIMEOFFSET_MAX_HOURS',  26);
114 if (!defined('TIMEOFFSET_DEFAULT_HOURS')) define('TIMEOFFSET_DEFAULT_HOURS', 0);
115
116 /**
117  * There are be the following constants in config/config.ini to 
118  * establish login parameters:
119  *
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
125  *
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
131  *
132  * To establish a COMPLETELY private wiki, such as an internal
133  * corporate one:
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
137  * any page.
138  *
139  * There are other possible combinations, but the typical wiki (such
140  * as http://PhpWiki.sf.net/phpwiki) would usually just leave all four 
141  * enabled.
142  *
143  */
144
145 // The last object in the row is the bad guy...
146 if (!is_array($USER_AUTH_ORDER))
147     $USER_AUTH_ORDER = array("Forbidden");
148 else
149     $USER_AUTH_ORDER[] = "Forbidden";
150
151 // Local convenience functions.
152 function _isAnonUserAllowed() {
153     return (defined('ALLOW_ANON_USER') && ALLOW_ANON_USER);
154 }
155 function _isBogoUserAllowed() {
156     return (defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN);
157 }
158 function _isUserPasswordsAllowed() {
159     return (defined('ALLOW_USER_PASSWORDS') && ALLOW_USER_PASSWORDS);
160 }
161
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.
166     if (!$UserName)
167         return $GLOBALS['ForbiddenUser'];
168
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);
175     }
176     */
177     else
178         return _determineBogoUserOrPassUser($UserName);
179 }
180
181 function _determineBogoUserOrPassUser($UserName) {
182     global $ForbiddenUser;
183
184     // Sanity check. User name is a condition of the definition of
185     // _BogoUser and _PassUser.
186     if (!$UserName)
187         return $ForbiddenUser;
188
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'))
195             return $_BogoUser;
196     }
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);
202         else { 
203             $_PassUser = new _PassUser($UserName,
204                                        isset($_BogoUser) ? $_BogoUser->_prefs : false);
205             if ($_PassUser->userExists() or $GLOBALS['request']->getArg('auth'))
206                 return $_PassUser;
207         }
208     }
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;
213 }
214
215 /**
216  * Primary WikiUser function, called by lib/main.php.
217  * 
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.
221  *
222  * If an _AnonUser object is returned, the user may only browse pages
223  * (and save prefs in a cookie).
224  *
225  * To disable access but provide prefs the global $ForbiddenUser class 
226  * is returned. (was previously false)
227  * 
228  */
229 function WikiUser ($UserName = '') {
230     global $ForbiddenUser;
231
232     //Maybe: Check sessionvar for username & save username into
233     //sessionvar (may be more appropriate to do this in lib/main.php).
234     if ($UserName) {
235         $ForbiddenUser = new _ForbiddenUser($UserName);
236         // Found a user name.
237         return _determineAdminUserOrOtherUser($UserName);
238     }
239     elseif (!empty($_SESSION['userid'])) {
240         // Found a user name.
241         $ForbiddenUser = new _ForbiddenUser($_SESSION['userid']);
242         return _determineAdminUserOrOtherUser($_SESSION['userid']);
243     }
244     else {
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);
252         }
253         else {
254             $ForbiddenUser = new _ForbiddenUser();
255             if (_isAnonUserAllowed())
256                 return $_AnonUser;
257             return $ForbiddenUser; // User must sign in to browse pages.
258         }
259         return $ForbiddenUser;     // User must sign in with a password.
260     }
261     /*
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.
265     */
266 }
267
268 /**
269  * WikiUser.php use the name 'WikiUser'
270  */
271 function WikiUserClassname() {
272     return '_WikiUser';
273 }
274
275
276 /**
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.
281  */
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;
293         }
294         if (!empty($user->_authmethod))
295             $olduser->_authmethod = $user->_authmethod;
296         /*
297         foreach (get_object_vars($user) as $k => $v) {
298             if (!empty($v)) $olduser->$k = $v;  
299         }
300         */
301         $olduser->hasHomePage(); // revive db handle, because these don't survive sessions
302         //$GLOBALS['request']->_user = $olduser;
303         return $olduser;
304     } else {
305         return false;
306     }
307 }
308
309 /**
310  * Probably not needed, since we use the various user objects methods so far.
311  * Anyway, here it is, looping through all available objects.
312  */
313 function UserExists ($UserName) {
314     global $request;
315     if (!($user = $request->getUser()))
316         $user = WikiUser($UserName);
317     if (!$user) 
318         return false;
319     if ($user->userExists($UserName)) {
320         $request->_user = $user;
321         return true;
322     }
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);
328     }
329     $request->_user = $GLOBALS['ForbiddenUser'];
330     return false;
331 }
332
333 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
334
335 /** 
336  * Base WikiUser class.
337  */
338 class _WikiUser
339 {
340      var $_userid = '';
341      var $_level = WIKIAUTH_ANON;
342      var $_prefs = false;
343      var $_HomePagehandle = false;
344
345     // constructor
346     function _WikiUser($UserName='', $prefs=false) {
347
348         $this->_userid = $UserName;
349         $this->_HomePagehandle = false;
350         if ($UserName) {
351             $this->hasHomePage();
352         }
353         if (empty($this->_prefs)) {
354             if ($prefs) $this->_prefs = $prefs;
355             else $this->getPreferences();
356         }
357     }
358
359     function UserName() {
360         if (!empty($this->_userid))
361             return $this->_userid;
362     }
363
364     function getPreferences() {
365         trigger_error("DEBUG: Note: undefined _WikiUser class trying to load prefs." . " "
366                       . "New subclasses of _WikiUser must override this function.");
367         return false;
368     }
369
370     function setPreferences($prefs, $id_only) {
371         trigger_error("DEBUG: Note: undefined _WikiUser class trying to save prefs." 
372                       . " "
373                       . "New subclasses of _WikiUser must override this function.");
374         return false;
375     }
376
377     function userExists() {
378         return $this->hasHomePage();
379     }
380
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." 
384                       . " "
385                       . "New subclasses of _WikiUser must override this function.");
386         return false;
387     }
388
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();
394             }
395             else {
396                 // check db again (maybe someone else created it since
397                 // we logged in.)
398                 global $request;
399                 $this->_HomePagehandle = $request->getPage($this->_userid);
400                 return $this->_HomePagehandle->exists();
401             }
402         }
403         // nope
404         return false;
405     }
406
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)
412                 return $found;
413         }
414         return false;
415     }
416
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);
425             } else {
426                 $this->_current_index = -1;
427             }
428         }
429         $this->_current_index++;
430         if ($this->_current_index >= count($this->_auth_methods))
431             return false;
432         $this->_current_method = $this->_auth_methods[$this->_current_index];
433         return $this->_current_index;
434     }
435
436     function AuthMethod($index = false) {
437         return $this->_auth_methods[ $index === false 
438                                      ? count($this->_auth_methods)-1 
439                                      : $index];
440     }
441
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";
447     }
448
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;
458         $require_level = 0;
459         extract($args); // fixme
460
461         $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
462
463         $pagename = $request->getArg('pagename');
464         $nocache = 1;
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);
474         } else {
475             return $login->printExpansion();
476         }
477     }
478
479     /** Signed in but not password checked or empty password.
480      */
481     function isSignedIn() {
482         return (isa($this,'_BogoUser') or isa($this,'_PassUser'));
483     }
484
485     /** This is password checked for sure.
486      */
487     function isAuthenticated() {
488         //return isa($this,'_PassUser');
489         //return isa($this,'_BogoUser') || isa($this,'_PassUser');
490         return $this->_level >= WIKIAUTH_BOGO;
491     }
492
493     function isAdmin () {
494         static $group; 
495         if ($this->_level == WIKIAUTH_ADMIN) return true;
496         if (!$this->isSignedIn()) return false;
497         if (!$this->isAuthenticated()) return false;
498
499         if (!$group) $group = &$GLOBALS['request']->getGroup();
500         return ($this->_level > WIKIAUTH_BOGO and $group->isMember(GROUP_ADMIN));
501     }
502
503     /** Name or IP for a signed user. UserName could come from a cookie e.g.
504      */
505     function getId () {
506         return ( $this->UserName()
507                  ? $this->UserName()
508                  : $GLOBALS['request']->get('REMOTE_ADDR') );
509     }
510
511     /** Name for an authenticated user. No IP here.
512      */
513     function getAuthenticatedId() {
514         return ( $this->isAuthenticated()
515                  ? $this->_userid
516                  : ''); //$GLOBALS['request']->get('REMOTE_ADDR') );
517     }
518
519     function hasAuthority ($require_level) {
520         return $this->_level >= $require_level;
521     }
522
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.
526     */
527     function isValidName ($userid = false) {
528         if (!$userid) $userid = $this->_userid;
529         return preg_match("/^[\w\.@\-]+$/",$userid) and strlen($userid) < 32;
530     }
531
532     /**
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)
535      */
536     function AuthCheck ($postargs) {
537         // Normalize args, and extract.
538         $keys = array('userid', 'passwd', 'require_level', 'login', 'logout',
539                       'cancel');
540         foreach ($keys as $key)
541             $args[$key] = isset($postargs[$key]) ? $postargs[$key] : false;
542         extract($args);
543         $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
544
545         if ($logout) { // Log out
546             if (method_exists($GLOBALS['request']->_user, "logout")) { //_HttpAuthPassUser
547                 $GLOBALS['request']->_user->logout();
548             }
549             $user = new _AnonUser();
550             $user->_userid = '';
551             $user->_level = WIKIAUTH_ANON;
552             return $user; 
553         } elseif ($cancel)
554             return false;        // User hit cancel button.
555         elseif (!$login && !$userid)
556             return false;       // Nothing to do?
557
558         if (!$this->isValidName($userid))
559             return _("Invalid username.");;
560
561         $authlevel = $this->checkPass($passwd === false ? '' : $passwd);
562         if ($authlevel <= 0) { // anon or forbidden
563             if ($passwd)
564                 return _("Invalid password.");
565             else
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') 
569             {
570                 // upgrade class
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;
578                 return $user;
579             }
580             $this->_userid = $userid;
581             $this->_level = $authlevel;
582             return _("Insufficient permissions.");
583         }
584
585         // Successful login.
586         //$user = $GLOBALS['request']->_user;
587         if (!empty($this->_current_method) and 
588             strtolower(get_class($this)) == '_passuser') 
589         {
590             // upgrade class
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;
598             return $user;
599         }
600         $this->_userid = $userid;
601         $this->_level = $authlevel;
602         return $this;
603     }
604
605 }
606
607 /**
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.
610  */
611 class _AnonUser
612 extends _WikiUser
613 {
614     var $_level = WIKIAUTH_ANON;        // var in php-5.0.0RC1 deprecated
615
616     /** Anon only gets to load and save prefs in a cookie, that's it.
617      */
618     function getPreferences() {
619         global $request;
620
621         if (empty($this->_prefs))
622             $this->_prefs = new UserPreferences;
623         $UserName = $this->UserName();
624
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.") 
629                               . "\n"
630                               . sprintf("%s='%s'", WIKI_NAME, $cookie)
631                               . "\n"
632                               . _("Default preferences will be used."),
633                               E_USER_NOTICE);
634             }
635             /**
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
639              * function too!).
640              */
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;
647                 else 
648                     $UserName = false;    
649             }
650             // v1.3.8 policy: don't set PhpWiki cookies, only plaintext WIKI_ID cookies
651             if (!headers_sent())
652                 $request->deleteCookieVar(WIKI_NAME);
653         }
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;
663                     else 
664                         $UserName = false;    
665                 }
666                 if (!headers_sent())
667                     $request->deleteCookieVar("WIKI_PREF2");
668             }
669         }
670         if (! $UserName ) {
671             // Try reading userid from old PhpWiki cookie formats:
672             if ($cookie = $request->cookies->get_old(getCookieName())) {
673                 if (is_string($cookie) and (substr($cookie,0,2) != 's:'))
674                     $UserName = $cookie;
675                 elseif (is_array($cookie) and !empty($cookie['userid']))
676                     $UserName = $cookie['userid'];
677             }
678             if (! $UserName and !headers_sent())
679                 $request->deleteCookieVar(getCookieName());
680             else
681                 $this->_userid = $UserName;
682         }
683
684         // initializeTheme() needs at least an empty object
685         /*
686          if (empty($this->_prefs))
687             $this->_prefs = new UserPreferences;
688         */
689         return $this->_prefs;
690     }
691
692     /** _AnonUser::setPreferences(): Save prefs in a cookie and session and update all global vars
693      *
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.
700      */
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;
706             } else {
707                 // update the prefs values from scratch. This could leed to unnecessary
708                 // side-effects: duplicate emailVerified, ...
709                 $this->_prefs = new UserPreferences($prefs);
710                 $updated = true;
711             }
712         } else {
713             if (!isset($this->_prefs))
714                 $this->_prefs =& $prefs;
715             else
716                 $updated = $this->_prefs->isChanged($prefs);
717         }
718         if ($updated) {
719             if ($id_only and !headers_sent()) {
720                 global $request;
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(getCookieName(), $this->_userid,
725                                        COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
726                 //$request->setCookieVar(WIKI_NAME, array('userid' => $prefs->get('userid')),
727                 //                       COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
728             }
729         }
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};
736             }
737             $this->_prefs = $prefs;
738         }
739         return $updated;
740     }
741
742     function userExists() {
743         return true;
744     }
745
746     function checkPass($submitted_password) {
747         return false;
748         // this might happen on a old-style signin button.
749
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.");
755         return false;
756     }
757
758 }
759
760 /** 
761  * Helper class to finish the PassUser auth loop. 
762  * This is added automatically to USER_AUTH_ORDER.
763  */
764 class _ForbiddenUser
765 extends _AnonUser
766 {
767     var $_level = WIKIAUTH_FORBIDDEN;
768
769     function checkPass($submitted_password) {
770         return WIKIAUTH_FORBIDDEN;
771     }
772
773     function userExists() {
774         if ($this->_HomePagehandle) return true;
775         return false;
776     }
777 }
778
779 /**
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()
786  */
787 class _BogoUser
788 extends _AnonUser
789 {
790     function userExists() {
791         if (isWikiWord($this->_userid)) {
792             $this->_level = WIKIAUTH_BOGO;
793             return true;
794         } else {
795             $this->_level = WIKIAUTH_ANON;
796             return false;
797         }
798     }
799
800     function checkPass($submitted_password) {
801         // By definition, BogoUser has an empty password.
802         $this->userExists();
803         return $this->_level;
804     }
805 }
806
807 class _PassUser
808 extends _AnonUser
809 /**
810  * Called if ALLOW_USER_PASSWORDS and Anon and Bogo failed.
811  *
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.
817  *
818  * Default is PersonalPage auth and prefs.
819  * 
820  * @author: Reini Urban
821  * @tables: pref
822  */
823 {
824     var $_auth_dbi, $_prefs;
825     var $_current_method, $_current_index;
826
827     // check and prepare the auth and pref methods only once
828     function _PassUser($UserName='', $prefs=false) {
829         //global $DBAuthParams, $DBParams;
830         if ($UserName) {
831             if (!$this->isValidName($UserName))
832                 return false;
833             $this->_userid = $UserName;
834             if ($this->hasHomePage())
835                 $this->_HomePagehandle = $GLOBALS['request']->getPage($this->_userid);
836         }
837         $this->_authmethod = substr(get_class($this),1,-8);
838         if ($this->_authmethod == 'a') $this->_authmethod = 'admin';
839
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();
846                 $need_pref = true;
847             }
848             $this->_prefs->_method = $dbh->getParam('dbtype');
849             $this->_prefs->_select = $this->prepare($dbh->getAuthParam('pref_select'), "userid");
850             // read-only prefs?
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"));
854             }
855         } else {
856             if (!$this->_prefs) {
857                 $this->_prefs = new UserPreferences();
858                 $need_pref = true;
859             }
860             $this->_prefs->_method = 'HomePage';
861         }
862         
863         if (! $this->_prefs or isset($need_pref) ) {
864             if ($prefs) $this->_prefs = $prefs;
865             else $this->getPreferences();
866         }
867         
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);
883                 }
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);
893                         else {
894                             $user = new _HttpAuthPassUser($UserName,$this->_prefs);
895                             eval("\$this = \$user;");
896                             // /*PHP5 patch*/$this = $user;
897                             return $user;
898                         }
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);
904                         else {
905                             $user = new _DbPassUser($UserName,$this->_prefs);
906                             eval("\$this = \$user;");
907                             // /*PHP5 patch*/$this = $user;
908                             return $user;
909                         }
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);
916                         else {
917                             $user = new _LDAPPassUser($UserName,$this->_prefs);
918                             eval("\$this = \$user;");
919                             // /*PHP5 patch*/$this = $user;
920                             return $user;
921                         }
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);
927                         else {
928                             $user = new _IMAPPassUser($UserName,$this->_prefs);
929                             eval("\$this = \$user;");
930                             // /*PHP5 patch*/$this = $user;
931                             return $user;
932                         }
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);
938                         else {
939                             $user = new _FilePassUser($UserName, $this->_prefs);
940                             eval("\$this = \$user;");
941                             // /*PHP5 patch*/$this = $user;
942                             return $user;
943                         }
944                     } else {
945                         include_once("lib/WikiUser/PersonalPage.php");
946                         if (check_php_version(5))
947                             return new _PersonalPagePassUser($UserName,$this->_prefs);
948                         else {
949                             $user = new _PersonalPagePassUser($UserName,$this->_prefs);
950                             eval("\$this = \$user;");
951                             // /*PHP5 patch*/$this = $user;
952                             return $user;
953                         }
954                     }
955                 }
956                 else 
957                     // else use the page methods defined in _PassUser.
958                     return $this;
959             }
960         }
961     }
962
963     function getAuthDbh () {
964         global $request; //, $DBParams, $DBAuthParams;
965
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);
974         }
975         if (empty($this->_auth_dbi)) {
976             if ($dbh->getParam('dbtype') != 'SQL' 
977                 and $dbh->getParam('dbtype') != 'ADODB'
978                 and $dbh->getParam('dbtype') != 'PDO')
979                 return false;
980             if (empty($GLOBALS['DBAuthParams']))
981                 return false;
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);
990             }       
991             $this->_auth_dbi =& $dbh->_backend->_dbh;    
992         }
993         return $this->_auth_dbi;
994     }
995
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);
1003             return false;
1004         }
1005         return !$oldstyle ? "'$".$new."'" : '\$'.$new;
1006     }
1007
1008     // TODO: use it again for the auth and member tables
1009     // sprintfstyle vs prepare style: %s or ?
1010     //   multiple vars should be executed via prepare(?,?)+execute, 
1011     //   single vars with execute(sprintf(quote(var)))
1012     // help with position independency
1013     function prepare ($stmt, $variables, $oldstyle = false, $sprintfstyle = true) {
1014         global $request;
1015         $dbi = $request->getDbh();
1016         $this->getAuthDbh();
1017         // "'\$userid"' => %s
1018         // variables can be old-style: '"\$userid"' or new-style: "'$userid'" or just "userid"
1019         // old-style strings don't survive pear/Config/IniConfig treatment, that's why we changed it.
1020         $new = array();
1021         if (is_array($variables)) {
1022             //$sprintfstyle = false;
1023             for ($i=0; $i < count($variables); $i++) { 
1024                 $var = $this->_normalize_stmt_var($variables[$i], $oldstyle);
1025                 if (!$var)
1026                     trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
1027                                           $variables[$i], $stmt), E_USER_WARNING);
1028                 $variables[$i] = $var;
1029                 if (!$var) $new[] = '';
1030                 else {
1031                     $s = "%" . ($i+1) . "s";    
1032                     $new[] = $sprintfstyle ? $s : "?";
1033                 }
1034             }
1035         } else {
1036             $var = $this->_normalize_stmt_var($variables, $oldstyle);
1037             if (!$var)
1038                 trigger_error(sprintf("DbAuthParams: Undefined or empty statement variable %s in %s",
1039                                       $variables, $stmt), E_USER_WARNING);
1040             $variables = $var;
1041             if (!$var) $new = ''; 
1042             else $new = $sprintfstyle ? '%s' : "?"; 
1043         }
1044         $prefix = $dbi->getParam('prefix');
1045         // probably prefix table names if in same database
1046         if ($prefix and isset($this->_auth_dbi) and isset($dbi->_backend->_dbh) and 
1047             ($dbi->getAuthParam('auth_dsn') and $dbi->getParam('dsn') == $dbi->getAuthParam('auth_dsn')))
1048         {
1049             if (!stristr($stmt, $prefix)) {
1050                 $oldstmt = $stmt;
1051                 $stmt = str_replace(array(" user "," pref "," member "),
1052                                     array(" ".$prefix."user ",
1053                                           " ".$prefix."pref ",
1054                                           " ".$prefix."member "), $stmt);
1055                 //Do it automatically for the lazy admin? Esp. on sf.net it's nice to have
1056                 trigger_error("Need to prefix the DBAUTH tablename in config/config.ini:\n  $oldstmt \n=> $stmt",
1057                               E_USER_WARNING);
1058             }
1059         }
1060         // Preparate the SELECT statement, for ADODB and PearDB (MDB not).
1061         // Simple sprintf-style.
1062         $new_stmt = str_replace($variables, $new, $stmt);
1063         if ($new_stmt == $stmt) {
1064             if ($oldstyle) {
1065                 trigger_error(sprintf("DbAuthParams: Invalid statement in %s",
1066                                   $stmt), E_USER_WARNING);
1067             } else {
1068                 trigger_error(sprintf("DbAuthParams: Old statement quoting style in %s",
1069                                   $stmt), E_USER_WARNING);
1070                 $new_stmt = $this->prepare($stmt, $variables, 'oldstyle');
1071             }
1072         }
1073         return $new_stmt;
1074     }
1075
1076     function getPreferences() {
1077         if (!empty($this->_prefs->_method)) {
1078             if ($this->_prefs->_method == 'ADODB') {
1079                 // FIXME: strange why this should be needed...
1080                 include_once("lib/WikiUser/Db.php");
1081                 include_once("lib/WikiUser/AdoDb.php");
1082                 _AdoDbPassUser::_AdoDbPassUser($this->_userid, $this->_prefs);
1083                 return _AdoDbPassUser::getPreferences();
1084             } elseif ($this->_prefs->_method == 'SQL') {
1085                 include_once("lib/WikiUser/Db.php");
1086                 include_once("lib/WikiUser/PearDb.php");
1087                 _PearDbPassUser::_PearDbPassUser($this->_userid, $this->_prefs);
1088                 return _PearDbPassUser::getPreferences();
1089             } elseif ($this->_prefs->_method == 'PDO') {
1090                 include_once("lib/WikiUser/Db.php");
1091                 include_once("lib/WikiUser/PdoDb.php");
1092                 _PdoDbPassUser::_PdoDbPassUser($this->_userid, $this->_prefs);
1093                 return _PdoDbPassUser::getPreferences();
1094             }
1095         }
1096
1097         // We don't necessarily have to read the cookie first. Since
1098         // the user has a password, the prefs stored in the homepage
1099         // cannot be arbitrarily altered by other Bogo users.
1100         _AnonUser::getPreferences();
1101         // User may have deleted cookie, retrieve from his
1102         // PersonalPage if there is one.
1103         if ($this->_HomePagehandle) {
1104             if ($restored_from_page = $this->_prefs->retrieve
1105                 ($this->_HomePagehandle->get('pref'))) {
1106                 $updated = $this->_prefs->updatePrefs($restored_from_page,'init');
1107                 //$this->_prefs = new UserPreferences($restored_from_page);
1108                 return $this->_prefs;
1109             }
1110         }
1111         return $this->_prefs;
1112     }
1113
1114     function setPreferences($prefs, $id_only=false) {
1115         if (!empty($this->_prefs->_method)) {
1116             if ($this->_prefs->_method == 'ADODB') {
1117                 // FIXME: strange why this should be needed...
1118                 include_once("lib/WikiUser/Db.php");
1119                 include_once("lib/WikiUser/AdoDb.php");
1120                 _AdoDbPassUser::_AdoDbPassUser($this->_userid, $prefs);
1121                 return _AdoDbPassUser::setPreferences($prefs, $id_only);
1122             }
1123             elseif ($this->_prefs->_method == 'SQL') {
1124                 include_once("lib/WikiUser/Db.php");
1125                 include_once("lib/WikiUser/PearDb.php");
1126                 _PearDbPassUser::_PearDbPassUser($this->_userid, $prefs);
1127                 return _PearDbPassUser::setPreferences($prefs, $id_only);
1128             }
1129             elseif ($this->_prefs->_method == 'PDO') {
1130                 include_once("lib/WikiUser/Db.php");
1131                 include_once("lib/WikiUser/PdoDb.php");
1132                 _PdoDbPassUser::_PdoDbPassUser($this->_userid, $prefs);
1133                 return _PdoDbPassUser::setPreferences($prefs, $id_only);
1134             }
1135         }
1136         if ($updated = _AnonUser::setPreferences($prefs, $id_only)) {
1137             // Encode only the _prefs array of the UserPreference object
1138             if (!empty($this->_HomePagehandle) and !$id_only) {
1139                 $this->_HomePagehandle->set('pref', $this->_prefs->store());
1140             }
1141         }
1142         return $updated;
1143     }
1144
1145     function mayChangePass() {
1146         return true;
1147     }
1148
1149     //The default method is getting the password from prefs. 
1150     // child methods obtain $stored_password from external auth.
1151     function userExists() {
1152         //if ($this->_HomePagehandle) return true;
1153         $class = $this->nextClass();
1154         while ($user = new $class($this->_userid, $this->_prefs)) {
1155             if (!check_php_version(5))
1156                 eval("\$this = \$user;");
1157             // /*PHP5 patch*/$this = $user;
1158             UpgradeUser($this,$user);
1159             if ($user->userExists()) {
1160                 return true;
1161             }
1162             // prevent endless loop. does this work on all PHP's?
1163             // it just has to set the classname, what it correctly does.
1164             $class = $user->nextClass();
1165             if ($class == "_ForbiddenPassUser")
1166                 return false;
1167         }
1168         return false;
1169     }
1170
1171     //The default method is getting the password from prefs. 
1172     // child methods obtain $stored_password from external auth.
1173     function checkPass($submitted_password) {
1174         $stored_password = $this->_prefs->get('passwd');
1175         if ($this->_checkPass($submitted_password, $stored_password)) {
1176             $this->_level = WIKIAUTH_USER;
1177             return $this->_level;
1178         } else {
1179             if ((USER_AUTH_POLICY === 'strict') and $this->userExists()) {
1180                 $this->_level = WIKIAUTH_FORBIDDEN;
1181                 return $this->_level;
1182             }
1183             return $this->_tryNextPass($submitted_password);
1184         }
1185     }
1186
1187
1188     function _checkPassLength($submitted_password) {
1189         if (strlen($submitted_password) < PASSWORD_LENGTH_MINIMUM) {
1190             trigger_error(_("The length of the password is shorter than the system policy allows."));
1191             return false;
1192         }
1193         return true;
1194     }
1195
1196     /**
1197      * The basic password checker for all PassUser objects.
1198      * Uses global ENCRYPTED_PASSWD and PASSWORD_LENGTH_MINIMUM.
1199      * Empty passwords are always false!
1200      * PASSWORD_LENGTH_MINIMUM is enforced here and in the preference set method.
1201      * @see UserPreferences::set
1202      *
1203      * DBPassUser password's have their own crypt definition.
1204      * That's why DBPassUser::checkPass() doesn't call this method, if 
1205      * the db password method is 'plain', which means that the DB SQL 
1206      * statement just returns 1 or 0. To use CRYPT() or PASSWORD() and 
1207      * don't store plain passwords in the DB.
1208      * 
1209      * TODO: remove crypt() function check from config.php:396 ??
1210      */
1211     function _checkPass($submitted_password, $stored_password) {
1212         if (!empty($submitted_password)) {
1213             // This works only on plaintext passwords.
1214             if (!ENCRYPTED_PASSWD and (strlen($stored_password) < PASSWORD_LENGTH_MINIMUM)) {
1215                 // With the EditMetaData plugin
1216                 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."));
1217                 return false;
1218             }
1219             if (!$this->_checkPassLength($submitted_password)) {
1220                 return false;
1221             }
1222             if (ENCRYPTED_PASSWD) {
1223                 // Verify against encrypted password.
1224                 if (function_exists('crypt')) {
1225                     if (crypt($submitted_password, $stored_password) == $stored_password )
1226                         return true; // matches encrypted password
1227                     else
1228                         return false;
1229                 }
1230                 else {
1231                     trigger_error(_("The crypt function is not available in this version of PHP.") . " "
1232                                   . _("Please set ENCRYPTED_PASSWD to false in config/config.ini and probably change ADMIN_PASSWD."),
1233                                   E_USER_WARNING);
1234                     return false;
1235                 }
1236             }
1237             else {
1238                 // Verify against cleartext password.
1239                 if ($submitted_password == $stored_password)
1240                     return true;
1241                 else {
1242                     // Check whether we forgot to enable ENCRYPTED_PASSWD
1243                     if (function_exists('crypt')) {
1244                         if (crypt($submitted_password, $stored_password) == $stored_password) {
1245                             trigger_error(_("Please set ENCRYPTED_PASSWD to true in config/config.ini."),
1246                                           E_USER_WARNING);
1247                             return true;
1248                         }
1249                     }
1250                 }
1251             }
1252         }
1253         return false;
1254     }
1255
1256     /** The default method is storing the password in prefs. 
1257      *  Child methods (DB, File) may store in external auth also, but this 
1258      *  must be explicitly enabled.
1259      *  This may be called by plugin/UserPreferences or by ->SetPreferences()
1260      */
1261     function changePass($submitted_password) {
1262         $stored_password = $this->_prefs->get('passwd');
1263         // check if authenticated
1264         if (!$this->isAuthenticated()) return false;
1265         if (ENCRYPTED_PASSWD) {
1266             $submitted_password = crypt($submitted_password);
1267         }
1268         // check other restrictions, with side-effects only.
1269         $result = $this->_checkPass($submitted_password, $stored_password);
1270         if ($stored_password != $submitted_password) {
1271             $this->_prefs->set('passwd', $submitted_password);
1272             //update the storage (session, homepage, ...)
1273             $this->SetPreferences($this->_prefs);
1274             return true;
1275         }
1276         //Todo: return an error msg to the caller what failed? 
1277         // same password or no privilege
1278         return ENCRYPTED_PASSWD ? true : false;
1279     }
1280
1281     function _tryNextPass($submitted_password) {
1282         if (DEBUG & _DEBUG_LOGIN) {
1283             $class = strtolower(get_class($this));
1284             if (substr($class,-10) == "dbpassuser") $class = "_dbpassuser";
1285             $GLOBALS['USER_AUTH_ERROR'][$class] = 'wrongpass';
1286         }
1287         if (USER_AUTH_POLICY === 'strict') {
1288             $class = $this->nextClass();
1289             if ($user = new $class($this->_userid,$this->_prefs)) {
1290                 if ($user->userExists()) {
1291                     return $user->checkPass($submitted_password);
1292                 }
1293             }
1294         }
1295         if (USER_AUTH_POLICY === 'stacked' or USER_AUTH_POLICY === 'old') {
1296             $class = $this->nextClass();
1297             if ($user = new $class($this->_userid,$this->_prefs))
1298                 return $user->checkPass($submitted_password);
1299         }
1300         return $this->_level;
1301     }
1302
1303     function _tryNextUser() {
1304         if (DEBUG & _DEBUG_LOGIN) {
1305             $class = strtolower(get_class($this));
1306             if (substr($class,-10) == "dbpassuser") $class = "_dbpassuser";
1307             $GLOBALS['USER_AUTH_ERROR'][$class] = 'nosuchuser';
1308         }
1309         if (USER_AUTH_POLICY === 'strict') {
1310             $class = $this->nextClass();
1311             while ($user = new $class($this->_userid,$this->_prefs)) {
1312                 if (!check_php_version(5))
1313                     eval("\$this = \$user;");
1314                 // /*PHP5 patch*/$this = $user;
1315                 //$user = UpgradeUser($this, $user);
1316                 if ($user->userExists()) {
1317                     return true;
1318                 }
1319                 $class = $this->nextClass();
1320             }
1321         }
1322         return false;
1323     }
1324
1325 }
1326
1327 /**
1328  * Insert more auth classes here...
1329  * For example a customized db class for another db connection 
1330  * or a socket-based auth server.
1331  *
1332  */
1333
1334
1335 /**
1336  * For security, this class should not be extended. Instead, extend
1337  * from _PassUser (think of this as unix "root").
1338  *
1339  * FIXME: This should be a singleton class. Only ADMIN_USER may be of class AdminUser!
1340  * Other members of the Administrators group must raise their level otherwise somehow.
1341  * Currently every member is a AdminUser, which will not work for the various 
1342  * storage methods.
1343  */
1344 class _AdminUser
1345 extends _PassUser
1346 {
1347     function mayChangePass() {
1348         return false;
1349     }
1350     function checkPass($submitted_password) {
1351         if ($this->_userid == ADMIN_USER)
1352             $stored_password = ADMIN_PASSWD;
1353         else {
1354             // Should not happen! Only ADMIN_USER should use this class.
1355             // return $this->_tryNextPass($submitted_password); // ???
1356             // TODO: safety check if really member of the ADMIN group?
1357             $stored_password = $this->_pref->get('passwd');
1358         }
1359         if ($this->_checkPass($submitted_password, $stored_password)) {
1360             $this->_level = WIKIAUTH_ADMIN;
1361             if (!empty($GLOBALS['HTTP_SERVER_VARS']['PHP_AUTH_USER']) and class_exists("_HttpAuthPassUser")) {
1362                 // fake http auth
1363                 _HttpAuthPassUser::_fake_auth($this->_userid, $submitted_password);
1364             }
1365             return $this->_level;
1366         } else {
1367             return $this->_tryNextPass($submitted_password);
1368             //$this->_level = WIKIAUTH_ANON;
1369             //return $this->_level;
1370         }
1371     }
1372
1373     function storePass($submitted_password) {
1374         if ($this->_userid == ADMIN_USER)
1375             return false;
1376         else {
1377             // should not happen! only ADMIN_USER should use this class.
1378             return parent::storePass($submitted_password);
1379         }
1380     }
1381 }
1382
1383 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1384 /**
1385  * Various data classes for the preference types, 
1386  * to support get, set, sanify (range checking, ...)
1387  * update() will do the neccessary side-effects if a 
1388  * setting gets changed (theme, language, ...)
1389 */
1390
1391 class _UserPreference
1392 {
1393     var $default_value;
1394
1395     function _UserPreference ($default_value) {
1396         $this->default_value = $default_value;
1397     }
1398
1399     function sanify ($value) {
1400         return (string)$value;
1401     }
1402
1403     function get ($name) {
1404         if (isset($this->{$name}))
1405             return $this->{$name};
1406         else 
1407             return $this->default_value;
1408     }
1409
1410     function getraw ($name) {
1411         if (!empty($this->{$name}))
1412             return $this->{$name};
1413     }
1414
1415     // stores the value as $this->$name, and not as $this->value (clever?)
1416     function set ($name, $value) {
1417         $return = 0;
1418         $value = $this->sanify($value);
1419         if ($this->get($name) != $value) {
1420             $this->update($value);
1421             $return = 1;
1422         }
1423         if ($value != $this->default_value) {
1424             $this->{$name} = $value;
1425         } else {
1426             unset($this->{$name});
1427         }
1428         return $return;
1429     }
1430
1431     // default: no side-effects 
1432     function update ($value) {
1433         ;
1434     }
1435 }
1436
1437 class _UserPreference_numeric
1438 extends _UserPreference
1439 {
1440     function _UserPreference_numeric ($default, $minval = false,
1441                                       $maxval = false) {
1442         $this->_UserPreference((double)$default);
1443         $this->_minval = (double)$minval;
1444         $this->_maxval = (double)$maxval;
1445     }
1446
1447     function sanify ($value) {
1448         $value = (double)$value;
1449         if ($this->_minval !== false && $value < $this->_minval)
1450             $value = $this->_minval;
1451         if ($this->_maxval !== false && $value > $this->_maxval)
1452             $value = $this->_maxval;
1453         return $value;
1454     }
1455 }
1456
1457 class _UserPreference_int
1458 extends _UserPreference_numeric
1459 {
1460     function _UserPreference_int ($default, $minval = false, $maxval = false) {
1461         $this->_UserPreference_numeric((int)$default, (int)$minval, (int)$maxval);
1462     }
1463
1464     function sanify ($value) {
1465         return (int)parent::sanify((int)$value);
1466     }
1467 }
1468
1469 class _UserPreference_bool
1470 extends _UserPreference
1471 {
1472     function _UserPreference_bool ($default = false) {
1473         $this->_UserPreference((bool)$default);
1474     }
1475
1476     function sanify ($value) {
1477         if (is_array($value)) {
1478             /* This allows for constructs like:
1479              *
1480              *   <input type="hidden" name="pref[boolPref][]" value="0" />
1481              *   <input type="checkbox" name="pref[boolPref][]" value="1" />
1482              *
1483              * (If the checkbox is not checked, only the hidden input
1484              * gets sent. If the checkbox is sent, both inputs get
1485              * sent.)
1486              */
1487             foreach ($value as $val) {
1488                 if ($val)
1489                     return true;
1490             }
1491             return false;
1492         }
1493         return (bool) $value;
1494     }
1495 }
1496
1497 class _UserPreference_language
1498 extends _UserPreference
1499 {
1500     function _UserPreference_language ($default = DEFAULT_LANGUAGE) {
1501         $this->_UserPreference($default);
1502     }
1503
1504     // FIXME: check for valid locale
1505     function sanify ($value) {
1506         // Revert to DEFAULT_LANGUAGE if user does not specify
1507         // language in UserPreferences or chooses <system language>.
1508         if ($value == '' or empty($value))
1509             $value = DEFAULT_LANGUAGE;
1510
1511         return (string) $value;
1512     }
1513     
1514     function update ($newvalue) {
1515         if (! $this->_init ) {
1516             // invalidate etag to force fresh output
1517             $GLOBALS['request']->setValidators(array('%mtime' => false));
1518             update_locale($newvalue ? $newvalue : $GLOBALS['LANG']);
1519         }
1520     }
1521 }
1522
1523 class _UserPreference_theme
1524 extends _UserPreference
1525 {
1526     function _UserPreference_theme ($default = THEME) {
1527         $this->_UserPreference($default);
1528     }
1529
1530     function sanify ($value) {
1531         if (!empty($value) and FindFile($this->_themefile($value)))
1532             return $value;
1533         return $this->default_value;
1534     }
1535
1536     function update ($newvalue) {
1537         global $WikiTheme;
1538         // invalidate etag to force fresh output
1539         if (! $this->_init )
1540             $GLOBALS['request']->setValidators(array('%mtime' => false));
1541         if ($newvalue)
1542             include_once($this->_themefile($newvalue));
1543         if (empty($WikiTheme))
1544             include_once($this->_themefile(THEME));
1545     }
1546
1547     function _themefile ($theme) {
1548         return "themes/$theme/themeinfo.php";
1549     }
1550 }
1551
1552 class _UserPreference_notify
1553 extends _UserPreference
1554 {
1555     function sanify ($value) {
1556         if (!empty($value))
1557             return $value;
1558         else
1559             return $this->default_value;
1560     }
1561
1562     /** update to global user prefs: side-effect on set notify changes
1563      * use a global_data notify hash:
1564      * notify = array('pagematch' => array(userid => ('email' => mail, 
1565      *                                                'verified' => 0|1),
1566      *                                     ...),
1567      *                ...);
1568      */
1569     function update ($value) {
1570         if (!empty($this->_init)) return;
1571         $dbh = $GLOBALS['request']->getDbh();
1572         $notify = $dbh->get('notify');
1573         if (empty($notify))
1574             $data = array();
1575         else 
1576             $data =& $notify;
1577         // expand to existing pages only or store matches?
1578         // for now we store (glob-style) matches which is easier for the user
1579         $pages = $this->_page_split($value);
1580         // Limitation: only current user.
1581         $user = $GLOBALS['request']->getUser();
1582         if (!$user or !method_exists($user,'UserName')) return;
1583         // This fails with php5 and a WIKI_ID cookie:
1584         $userid = $user->UserName();
1585         $email  = $user->_prefs->get('email');
1586         $verified = $user->_prefs->_prefs['email']->getraw('emailVerified');
1587         // check existing notify hash and possibly delete pages for email
1588         if (!empty($data)) {
1589             foreach ($data as $page => $users) {
1590                 if (isset($data[$page][$userid]) and !in_array($page, $pages)) {
1591                     unset($data[$page][$userid]);
1592                 }
1593                 if (count($data[$page]) == 0)
1594                     unset($data[$page]);
1595             }
1596         }
1597         // add the new pages
1598         if (!empty($pages)) {
1599             foreach ($pages as $page) {
1600                 if (!isset($data[$page]))
1601                     $data[$page] = array();
1602                 if (!isset($data[$page][$userid])) {
1603                     // should we really store the verification notice here or 
1604                     // check it dynamically at every page->save?
1605                     if ($verified) {
1606                         $data[$page][$userid] = array('email' => $email,
1607                                                       'verified' => $verified);
1608                     } else {
1609                         $data[$page][$userid] = array('email' => $email);
1610                     }
1611                 }
1612             }
1613         }
1614         // store users changes
1615         $dbh->set('notify',$data);
1616     }
1617
1618     /** split the user-given comma or whitespace delimited pagenames
1619      *  to array
1620      */
1621     function _page_split($value) {
1622         return preg_split('/[\s,]+/',$value,-1,PREG_SPLIT_NO_EMPTY);
1623     }
1624 }
1625
1626 class _UserPreference_email
1627 extends _UserPreference
1628 {
1629     function sanify($value) {
1630         // check for valid email address
1631         if ($this->get('email') == $value and $this->getraw('emailVerified'))
1632             return $value;
1633         // hack!
1634         if ($value == 1 or $value === true)
1635             return $value;
1636         list($ok,$msg) = ValidateMail($value,'noconnect');
1637         if ($ok) {
1638             return $value;
1639         } else {
1640             trigger_error("E-Mail Validation Error: ".$msg, E_USER_WARNING);
1641             return $this->default_value;
1642         }
1643     }
1644     
1645     /** Side-effect on email changes:
1646      * Send a verification mail or for now just a notification email.
1647      * For true verification (value = 2), we'd need a mailserver hook.
1648      */
1649     function update($value) {
1650         if (!empty($this->_init)) return;
1651         $verified = $this->getraw('emailVerified');
1652         // hack!
1653         if (($value == 1 or $value === true) and $verified)
1654             return;
1655         if (!empty($value) and !$verified) {
1656             list($ok,$msg) = ValidateMail($value);
1657             if ($ok and mail($value,"[".WIKI_NAME ."] "._("Email Verification"),
1658                      sprintf(_("Welcome to %s!\nYour email account is verified and\nwill be used to send page change notifications.\nSee %s"),
1659                              WIKI_NAME, WikiURL($GLOBALS['request']->getArg('pagename'),'',true))))
1660                 $this->set('emailVerified',1);
1661         }
1662     }
1663 }
1664
1665 /** Check for valid email address
1666     fixed version from http://www.zend.com/zend/spotlight/ev12apr.php
1667     Note: too strict, Bug #1053681
1668  */
1669 function ValidateMail($email, $noconnect=false) {
1670     $HTTP_HOST = $GLOBALS['request']->get('HTTP_HOST');
1671
1672     // if this check is too strict (like invalid mail addresses in a local network only)
1673     // uncomment the following line:
1674     // return array(true,"not validated");
1675     // see http://sourceforge.net/tracker/index.php?func=detail&aid=1053681&group_id=6121&atid=106121
1676
1677     $result = array();
1678
1679     // This is Paul Warren's (pdw@ex-parrot.com) monster regex for RFC822
1680     // addresses, from the Perl module Mail::RFC822::Address, reduced to
1681     // accept single RFC822 addresses without comments only. (The original
1682     // accepts groups and properly commented addresses also.)
1683     $lwsp = "(?:(?:\\r\\n)?[ \\t])";
1684
1685     $specials = '()<>@,;:\\\\".\\[\\]';
1686     $controls = '\\000-\\031';
1687
1688     $dtext = "[^\\[\\]\\r\\\\]";
1689     $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$lwsp*";
1690
1691     $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$lwsp)*\"$lwsp*";
1692
1693     $atom = "[^$specials $controls]+(?:$lwsp+|\\Z|(?=[\\[\"$specials]))";
1694     $word = "(?:$atom|$quoted_string)";
1695     $localpart = "$word(?:\\.$lwsp*$word)*";
1696
1697     $sub_domain = "(?:$atom|$domain_literal)";
1698     $domain = "$sub_domain(?:\\.$lwsp*$sub_domain)*";
1699
1700     $addr_spec = "$localpart\@$lwsp*$domain";
1701
1702     $phrase = "$word*";
1703     $route = "(?:\@$domain(?:,\@$lwsp*$domain)*:$lwsp*)";
1704     $route_addr = "\\<$lwsp*$route?$addr_spec\\>$lwsp*";
1705     $mailbox = "(?:$addr_spec|$phrase$route_addr)";
1706
1707     $rfc822re = "/$lwsp*$mailbox/";
1708
1709     if (!preg_match($rfc822re, $email)) {
1710         $result[0] = false;
1711         $result[1] = sprintf(_("E-Mail address '%s' is not properly formatted"), $email);
1712         return $result;
1713     }
1714     if ($noconnect)
1715       return array(true,sprintf(_("E-Mail address '%s' is properly formatted"), $email));
1716
1717     list ( $Username, $Domain ) = split ("@", $email);
1718     //Todo: getmxrr workaround on windows or manual input field to verify it manually
1719     if (!isWindows() and getmxrr($Domain, $MXHost)) { // avoid warning on Windows. 
1720         $ConnectAddress = $MXHost[0];
1721     } else {
1722         $ConnectAddress = $Domain;
1723     }
1724     $Connect = @fsockopen ( $ConnectAddress, 25 );
1725     if ($Connect) {
1726         if (ereg("^220", $Out = fgets($Connect, 1024))) {
1727             fputs ($Connect, "HELO $HTTP_HOST\r\n");
1728             $Out = fgets ( $Connect, 1024 );
1729             fputs ($Connect, "MAIL FROM: <".$email.">\r\n");
1730             $From = fgets ( $Connect, 1024 );
1731             fputs ($Connect, "RCPT TO: <".$email.">\r\n");
1732             $To = fgets ($Connect, 1024);
1733             fputs ($Connect, "QUIT\r\n");
1734             fclose($Connect);
1735             if (!ereg ("^250", $From)) {
1736                 $result[0]=false;
1737                 $result[1]="Server rejected address: ". $From;
1738                 return $result;
1739             }
1740             if (!ereg ( "^250", $To )) {
1741                 $result[0]=false;
1742                 $result[1]="Server rejected address: ". $To;
1743                 return $result;
1744             }
1745         } else {
1746             $result[0] = false;
1747             $result[1] = "No response from server";
1748             return $result;
1749           }
1750     }  else {
1751         $result[0]=false;
1752         $result[1]="Can not connect E-Mail server.";
1753         return $result;
1754     }
1755     $result[0]=true;
1756     $result[1]="E-Mail address '$email' appears to be valid.";
1757     return $result;
1758 } // end of function 
1759
1760 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1761
1762 /**
1763  * UserPreferences
1764  * 
1765  * This object holds the $request->_prefs subobjects.
1766  * A simple packed array of non-default values get's stored as cookie,
1767  * homepage, or database, which are converted to the array of 
1768  * ->_prefs objects.
1769  * We don't store the objects, because otherwise we will
1770  * not be able to upgrade any subobject. And it's a waste of space also.
1771  *
1772  */
1773 class UserPreferences
1774 {
1775     function UserPreferences($saved_prefs = false) {
1776         // userid stored too, to ensure the prefs are being loaded for
1777         // the correct (currently signing in) userid if stored in a
1778         // cookie.
1779         // Update: for db prefs we disallow passwd. 
1780         // userid is needed for pref reflexion. current pref must know its username, 
1781         // if some app needs prefs from different users, different from current user.
1782         $this->_prefs
1783             = array(
1784                     'userid'        => new _UserPreference(''),
1785                     'passwd'        => new _UserPreference(''),
1786                     'autologin'     => new _UserPreference_bool(),
1787                     //'emailVerified' => new _UserPreference_emailVerified(), 
1788                     //fixed: store emailVerified as email parameter, 1.3.8
1789                     'email'         => new _UserPreference_email(''),
1790                     'notifyPages'   => new _UserPreference_notify(''), // 1.3.8
1791                     'theme'         => new _UserPreference_theme(THEME),
1792                     'lang'          => new _UserPreference_language(DEFAULT_LANGUAGE),
1793                     'editWidth'     => new _UserPreference_int(EDITWIDTH_DEFAULT_COLS,
1794                                                                EDITWIDTH_MIN_COLS,
1795                                                                EDITWIDTH_MAX_COLS),
1796                     'noLinkIcons'   => new _UserPreference_bool(),    // 1.3.8 
1797                     'editHeight'    => new _UserPreference_int(EDITHEIGHT_DEFAULT_ROWS,
1798                                                                EDITHEIGHT_MIN_ROWS,
1799                                                                EDITHEIGHT_MAX_ROWS),
1800                     'timeOffset'    => new _UserPreference_numeric(TIMEOFFSET_DEFAULT_HOURS,
1801                                                                    TIMEOFFSET_MIN_HOURS,
1802                                                                    TIMEOFFSET_MAX_HOURS),
1803                     'relativeDates' => new _UserPreference_bool(),
1804                     'googleLink'    => new _UserPreference_bool(), // 1.3.10
1805                     'doubleClickEdit' => new _UserPreference_bool(), // 1.3.11
1806                     );
1807         // add custom theme-specific pref types:
1808         // FIXME: on theme changes the wiki_user session pref object will fail. 
1809         // We will silently ignore this.
1810         if (!empty($customUserPreferenceColumns))
1811             $this->_prefs = array_merge($this->_prefs,$customUserPreferenceColumns);
1812 /*
1813         if (isset($this->_method) and $this->_method == 'SQL') {
1814             //unset($this->_prefs['userid']);
1815             unset($this->_prefs['passwd']);
1816         }
1817 */
1818         if (is_array($saved_prefs)) {
1819             foreach ($saved_prefs as $name => $value)
1820                 $this->set($name, $value);
1821         }
1822     }
1823
1824     function _getPref($name) {
1825         if ($name == 'emailVerified')
1826             $name = 'email';
1827         if (!isset($this->_prefs[$name])) {
1828             if ($name == 'passwd2') return false;
1829             if ($name == 'passwd') return false;
1830             trigger_error("$name: unknown preference", E_USER_NOTICE);
1831             return false;
1832         }
1833         return $this->_prefs[$name];
1834     }
1835     
1836     // get the value or default_value of the subobject
1837     function get($name) {
1838         if ($_pref = $this->_getPref($name))
1839             if ($name == 'emailVerified')
1840                 return $_pref->getraw($name);
1841             else
1842                 return $_pref->get($name);
1843         else
1844             return false;  
1845     }
1846
1847     // check and set the new value in the subobject
1848     function set($name, $value) {
1849         $pref = $this->_getPref($name);
1850         if ($pref === false)
1851             return false;
1852
1853         /* do it here or outside? */
1854         if ($name == 'passwd' and 
1855             defined('PASSWORD_LENGTH_MINIMUM') and 
1856             strlen($value) <= PASSWORD_LENGTH_MINIMUM ) {
1857             //TODO: How to notify the user?
1858             return false;
1859         }
1860         /*
1861         if ($name == 'theme' and $value == '')
1862            return true;
1863         */
1864         // Fix Fatal error for undefined value. Thanks to Jim Ford and Joel Schaubert
1865         if ((!$value and $pref->default_value)
1866             or ($value and !isset($pref->$value))
1867             or ($value and ($pref->$value != $pref->default_value)))
1868         {
1869             if ($name == 'emailVerified') $newvalue = $value;
1870             else $newvalue = $pref->sanify($value);
1871             $pref->set($name, $newvalue);
1872         }
1873         $this->_prefs[$name] =& $pref;
1874         return true;
1875     }
1876     /**
1877      * use init to avoid update on set
1878      */
1879     function updatePrefs($prefs, $init = false) {
1880         $count = 0;
1881         if ($init) $this->_init = $init;
1882         if (is_object($prefs)) {
1883             $type = 'emailVerified'; $obj =& $this->_prefs['email'];
1884             $obj->_init = $init;
1885             if ($obj->get($type) !== $prefs->get($type)) {
1886                 if ($obj->set($type,$prefs->get($type)))
1887                     $count++;
1888             }
1889             foreach (array_keys($this->_prefs) as $type) {
1890                 $obj =& $this->_prefs[$type];
1891                 $obj->_init = $init;
1892                 if ($prefs->get($type) !== $obj->get($type)) {
1893                     // special systemdefault prefs: (probably not needed)
1894                     if ($type == 'theme' and $prefs->get($type) == '' and 
1895                         $obj->get($type) == THEME) continue;
1896                     if ($type == 'lang' and $prefs->get($type) == '' and 
1897                         $obj->get($type) == DEFAULT_LANGUAGE) continue;
1898                     if ($this->_prefs[$type]->set($type,$prefs->get($type)))
1899                         $count++;
1900                 }
1901             }
1902         } elseif (is_array($prefs)) {
1903             //unset($this->_prefs['userid']);
1904             /*
1905             if (isset($this->_method) and 
1906                  ($this->_method == 'SQL' or $this->_method == 'ADODB')) {
1907                 unset($this->_prefs['passwd']);
1908             }
1909             */
1910             // emailVerified at first, the rest later
1911             $type = 'emailVerified'; $obj =& $this->_prefs['email'];
1912             $obj->_init = $init;
1913             if (isset($prefs[$type]) and $obj->get($type) !== $prefs[$type]) {
1914                 if ($obj->set($type,$prefs[$type]))
1915                     $count++;
1916             }
1917             foreach (array_keys($this->_prefs) as $type) {
1918                 $obj =& $this->_prefs[$type];
1919                 $obj->_init = $init;
1920                 if (!isset($prefs[$type]) and isa($obj,"_UserPreference_bool")) 
1921                     $prefs[$type] = false;
1922                 if (isset($prefs[$type]) and isa($obj,"_UserPreference_int"))
1923                     $prefs[$type] = (int) $prefs[$type];
1924                 if (isset($prefs[$type]) and $obj->get($type) != $prefs[$type]) {
1925                     // special systemdefault prefs:
1926                     if ($type == 'theme' and $prefs[$type] == '' and 
1927                         $obj->get($type) == THEME) continue;
1928                     if ($type == 'lang' and $prefs[$type] == '' and 
1929                         $obj->get($type) == DEFAULT_LANGUAGE) continue;
1930                     if ($obj->set($type,$prefs[$type]))
1931                         $count++;
1932                 }
1933             }
1934         }
1935         return $count;
1936     }
1937
1938     // For now convert just array of objects => array of values
1939     // Todo: the specialized subobjects must override this.
1940     function store() {
1941         $prefs = array();
1942         foreach ($this->_prefs as $name => $object) {
1943             if ($value = $object->getraw($name))
1944                 $prefs[$name] = $value;
1945             if ($name == 'email' and ($value = $object->getraw('emailVerified')))
1946                 $prefs['emailVerified'] = $value;
1947             if ($name == 'passwd' and $value and ENCRYPTED_PASSWD) {
1948                 if (strlen($value) != strlen(crypt('test')))
1949                     $prefs['passwd'] = crypt($value);
1950                 else // already crypted
1951                     $prefs['passwd'] = $value;
1952             }
1953         }
1954         return $this->pack($prefs);
1955     }
1956
1957     // packed string or array of values => array of values
1958     // Todo: the specialized subobjects must override this.
1959     function retrieve($packed) {
1960         if (is_string($packed) and (substr($packed, 0, 2) == "a:"))
1961             $packed = unserialize($packed);
1962         if (!is_array($packed)) return false;
1963         $prefs = array();
1964         foreach ($packed as $name => $packed_pref) {
1965             if (is_string($packed_pref) and substr($packed_pref, 0, 2) == "O:") {
1966                 //legacy: check if it's an old array of objects
1967                 // Looks like a serialized object. 
1968                 // This might fail if the object definition does not exist anymore.
1969                 // object with ->$name and ->default_value vars.
1970                 $pref =  @unserialize($packed_pref);
1971                 if (empty($pref))
1972                     $pref = @unserialize(base64_decode($packed_pref));
1973                 $prefs[$name] = $pref->get($name);
1974             // fix old-style prefs
1975             } elseif (is_numeric($name) and is_array($packed_pref)) {
1976                 if (count($packed_pref) == 1) {
1977                     list($name,$value) = each($packed_pref);
1978                     $prefs[$name] = $value;
1979                 }
1980             } else {
1981                 $prefs[$name] = @unserialize($packed_pref);
1982                 if (empty($prefs[$name]))
1983                     $prefs[$name] = @unserialize(base64_decode($packed_pref));
1984                 // patched by frederik@pandora.be
1985                 if (empty($prefs[$name]))
1986                     $prefs[$name] = $packed_pref;
1987             }
1988         }
1989         return $prefs;
1990     }
1991
1992     /**
1993      * Check if the given prefs object is different from the current prefs object
1994      */
1995     function isChanged($other) {
1996         foreach ($this->_prefs as $type => $obj) {
1997             if ($obj->get($type) !== $other->get($type))
1998                 return true;
1999         }
2000         return false;
2001     }
2002
2003     function defaultPreferences() {
2004         $prefs = array();
2005         foreach ($this->_prefs as $key => $obj) {
2006             $prefs[$key] = $obj->default_value;
2007         }
2008         return $prefs;
2009     }
2010     
2011     // array of objects
2012     function getAll() {
2013         return $this->_prefs;
2014     }
2015
2016     function pack($nonpacked) {
2017         return serialize($nonpacked);
2018     }
2019
2020     function unpack($packed) {
2021         if (!$packed)
2022             return false;
2023         //$packed = base64_decode($packed);
2024         if (substr($packed, 0, 2) == "O:") {
2025             // Looks like a serialized object
2026             return unserialize($packed);
2027         }
2028         if (substr($packed, 0, 2) == "a:") {
2029             return unserialize($packed);
2030         }
2031         //trigger_error("DEBUG: Can't unpack bad UserPreferences",
2032         //E_USER_WARNING);
2033         return false;
2034     }
2035
2036     function hash () {
2037         return wikihash($this->_prefs);
2038     }
2039 }
2040
2041 /** TODO: new pref storage classes
2042  *  These are currently user specific and should be rewritten to be pref specific.
2043  *  i.e. $this == $user->_prefs
2044  */
2045 /*
2046 class CookieUserPreferences
2047 extends UserPreferences
2048 {
2049     function CookieUserPreferences ($saved_prefs = false) {
2050         //_AnonUser::_AnonUser('',$saved_prefs);
2051         UserPreferences::UserPreferences($saved_prefs);
2052     }
2053 }
2054
2055 class PageUserPreferences
2056 extends UserPreferences
2057 {
2058     function PageUserPreferences ($saved_prefs = false) {
2059         UserPreferences::UserPreferences($saved_prefs);
2060     }
2061 }
2062
2063 class PearDbUserPreferences
2064 extends UserPreferences
2065 {
2066     function PearDbUserPreferences ($saved_prefs = false) {
2067         UserPreferences::UserPreferences($saved_prefs);
2068     }
2069 }
2070
2071 class AdoDbUserPreferences
2072 extends UserPreferences
2073 {
2074     function AdoDbUserPreferences ($saved_prefs = false) {
2075         UserPreferences::UserPreferences($saved_prefs);
2076     }
2077     function getPreferences() {
2078         // override the generic slow method here for efficiency
2079         _AnonUser::getPreferences();
2080         $this->getAuthDbh();
2081         if (isset($this->_select)) {
2082             $dbh = & $this->_auth_dbi;
2083             $rs = $dbh->Execute(sprintf($this->_select,$dbh->qstr($this->_userid)));
2084             if ($rs->EOF) {
2085                 $rs->Close();
2086             } else {
2087                 $prefs_blob = $rs->fields['pref_blob'];
2088                 $rs->Close();
2089                 if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
2090                     $updated = $this->_prefs->updatePrefs($restored_from_db);
2091                     //$this->_prefs = new UserPreferences($restored_from_db);
2092                     return $this->_prefs;
2093                 }
2094             }
2095         }
2096         if (empty($this->_prefs->_prefs) and $this->_HomePagehandle) {
2097             if ($restored_from_page = $this->_prefs->retrieve
2098                 ($this->_HomePagehandle->get('pref'))) {
2099                 $updated = $this->_prefs->updatePrefs($restored_from_page);
2100                 //$this->_prefs = new UserPreferences($restored_from_page);
2101                 return $this->_prefs;
2102             }
2103         }
2104         return $this->_prefs;
2105     }
2106 }
2107 */
2108
2109 // $Log: not supported by cvs2svn $
2110 // Revision 1.136  2006/04/16 11:07:48  rurban
2111 // Dont crypt the passwd twice on storing prefs. Patch by Thomas Harding.
2112 // Fixes bug #1327470
2113 //
2114 // Revision 1.135  2006/03/19 16:26:39  rurban
2115 // fix DBAUTH arguments to be position independent, fixes bug #1358973
2116 //
2117 // Revision 1.134  2006/03/19 15:01:00  rurban
2118 // sf.net patch #1333957 by Matt Brown: Authentication cookie identical across all wikis on a host
2119 //
2120 // Revision 1.133  2006/03/07 18:39:21  rurban
2121 // add PdoDb, rename hash to wikihash (php-5.1), fix output of Homepage prefs update
2122 //
2123 // Revision 1.132  2006/03/04 13:19:12  rurban
2124 // fix for fatal error on empty pref value (sign out). Thanks to Jim Ford and Joel Schaubert. rename hash for php-5.1
2125 //
2126 // Revision 1.131  2005/10/12 06:16:48  rurban
2127 // add new _insert statement
2128 //
2129 // Revision 1.129  2005/06/10 06:10:35  rurban
2130 // ensure Update Preferences gets through
2131 //
2132 // Revision 1.128  2005/06/05 05:38:02  rurban
2133 // Default ENABLE_DOUBLECLICKEDIT = false. Moved to UserPreferences
2134 //
2135 // Revision 1.127  2005/04/02 18:01:41  uckelman
2136 // Fixed regex for RFC822 addresses.
2137 //
2138 // Revision 1.126  2005/02/28 20:30:46  rurban
2139 // some stupid code for _AdminUser (probably not needed)
2140 //
2141 // Revision 1.125  2005/02/08 13:25:50  rurban
2142 // encrypt password. fix strict logic.
2143 // both bugs reported by Mikhail Vladimirov
2144 //
2145 // Revision 1.124  2005/01/30 23:11:00  rurban
2146 // allow self-creating passuser on login
2147 //
2148 // Revision 1.123  2005/01/25 06:58:21  rurban
2149 // reformatting
2150 //
2151 // Revision 1.122  2005/01/08 22:51:56  rurban
2152 // remove deprecated workaround
2153 //
2154 // Revision 1.121  2004/12/19 00:58:01  rurban
2155 // Enforce PASSWORD_LENGTH_MINIMUM in almost all PassUser checks,
2156 // Provide an errormessage if so. Just PersonalPage and BogoLogin not.
2157 // Simplify httpauth logout handling and set sessions for all methods.
2158 // fix main.php unknown index "x" getLevelDescription() warning.
2159 //
2160 // Revision 1.120  2004/12/17 12:31:57  rurban
2161 // better logout, fake httpauth not yet
2162 //
2163 // Revision 1.119  2004/11/21 11:59:17  rurban
2164 // remove final \n to be ob_cache independent
2165 //
2166 // Revision 1.118  2004/11/19 19:22:03  rurban
2167 // ModeratePage part1: change status
2168 //
2169 // Revision 1.117  2004/11/10 15:29:21  rurban
2170 // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
2171 // * ACCESS_LOG_SQL: fix cause request not yet initialized
2172 // * WikiDB: moved SQL specific methods upwards
2173 // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
2174 //   fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
2175 //
2176 // Revision 1.116  2004/11/05 21:03:27  rurban
2177 // new DEBUG flag: _DEBUG_LOGIN (64)
2178 //   verbose login debug-msg (settings and reason for failure)
2179 //
2180 // Revision 1.115  2004/11/05 20:53:35  rurban
2181 // login cleanup: better debug msg on failing login,
2182 // checked password less immediate login (bogo or anon),
2183 // checked olduser pref session error,
2184 // better PersonalPage without password warning on minimal password length=0
2185 //   (which is default now)
2186 //
2187 // Revision 1.114  2004/11/05 16:15:57  rurban
2188 // forgot the BogoLogin inclusion with the latest rewrite
2189 //
2190 // Revision 1.113  2004/11/03 17:13:49  rurban
2191 // make it easier to disable EmailVerification
2192 //   Bug #1053681
2193 //
2194 // Revision 1.112  2004/11/01 10:43:57  rurban
2195 // seperate PassUser methods into seperate dir (memory usage)
2196 // fix WikiUser (old) overlarge data session
2197 // remove wikidb arg from various page class methods, use global ->_dbi instead
2198 // ...
2199 //
2200 // Revision 1.111  2004/10/21 21:03:50  rurban
2201 // isAdmin must be signed and authenticated
2202 // comment out unused sections (memory)
2203 //
2204 // Revision 1.110  2004/10/14 19:19:33  rurban
2205 // loadsave: check if the dumped file will be accessible from outside.
2206 // and some other minor fixes. (cvsclient native not yet ready)
2207 //
2208 // Revision 1.109  2004/10/07 16:08:58  rurban
2209 // fixed broken FileUser session handling.
2210 //   thanks to Arnaud Fontaine for detecting this.
2211 // enable file user Administrator membership.
2212 //
2213 // Revision 1.108  2004/10/05 17:00:04  rurban
2214 // support paging for simple lists
2215 // fix RatingDb sql backend.
2216 // remove pages from AllPages (this is ListPages then)
2217 //
2218 // Revision 1.107  2004/10/04 23:42:15  rurban
2219 // HttpAuth admin group logic. removed old logs
2220 //
2221 // Revision 1.106  2004/07/01 08:49:38  rurban
2222 // obsolete php5-patch.php: minor php5 login problem though
2223 //
2224 // Revision 1.105  2004/06/29 06:48:03  rurban
2225 // Improve LDAP auth and GROUP_LDAP membership:
2226 //   no error message on false password,
2227 //   added two new config vars: LDAP_OU_USERS and LDAP_OU_GROUP with GROUP_METHOD=LDAP
2228 //   fixed two group queries (this -> user)
2229 // stdlib: ConvertOldMarkup still flawed
2230 //
2231 // Revision 1.104  2004/06/28 15:39:37  rurban
2232 // fixed endless recursion in WikiGroup: isAdmin()
2233 //
2234 // Revision 1.103  2004/06/28 15:01:07  rurban
2235 // fixed LDAP_SET_OPTION handling, LDAP error on connection problem
2236 //
2237 // Revision 1.102  2004/06/27 10:23:48  rurban
2238 // typo detected by Philippe Vanhaesendonck
2239 //
2240 // Revision 1.101  2004/06/25 14:29:19  rurban
2241 // WikiGroup refactoring:
2242 //   global group attached to user, code for not_current user.
2243 //   improved helpers for special groups (avoid double invocations)
2244 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
2245 // fixed a XHTML validation error on userprefs.tmpl
2246 //
2247 // Revision 1.100  2004/06/21 06:29:35  rurban
2248 // formatting: linewrap only
2249 //
2250 // Revision 1.99  2004/06/20 15:30:05  rurban
2251 // get_class case-sensitivity issues
2252 //
2253 // Revision 1.98  2004/06/16 21:24:31  rurban
2254 // do not display no-connect warning: #2662
2255 //
2256 // Revision 1.97  2004/06/16 13:21:16  rurban
2257 // stabilize on failing ldap queries or bind
2258 //
2259 // Revision 1.96  2004/06/16 12:42:06  rurban
2260 // fix homepage prefs
2261 //
2262 // Revision 1.95  2004/06/16 10:38:58  rurban
2263 // Disallow refernces in calls if the declaration is a reference
2264 // ("allow_call_time_pass_reference clean").
2265 //   PhpWiki is now allow_call_time_pass_reference = Off clean,
2266 //   but several external libraries may not.
2267 //   In detail these libs look to be affected (not tested):
2268 //   * Pear_DB odbc
2269 //   * adodb oracle
2270 //
2271 // Revision 1.94  2004/06/15 10:40:35  rurban
2272 // minor WikiGroup cleanup: no request param, start of current user independency
2273 //
2274 // Revision 1.93  2004/06/15 09:15:52  rurban
2275 // IMPORTANT: fixed passwd handling for passwords stored in prefs:
2276 //   fix encrypted usage, actually store and retrieve them from db
2277 //   fix bogologin with passwd set.
2278 // fix php crashes with call-time pass-by-reference (references wrongly used
2279 //   in declaration AND call). This affected mainly Apache2 and IIS.
2280 //   (Thanks to John Cole to detect this!)
2281 //
2282 // Revision 1.92  2004/06/14 11:31:36  rurban
2283 // renamed global $Theme to $WikiTheme (gforge nameclash)
2284 // inherit PageList default options from PageList
2285 //   default sortby=pagename
2286 // use options in PageList_Selectable (limit, sortby, ...)
2287 // added action revert, with button at action=diff
2288 // added option regex to WikiAdminSearchReplace
2289 //
2290 // Revision 1.91  2004/06/08 14:57:43  rurban
2291 // stupid ldap bug detected by John Cole
2292 //
2293 // Revision 1.90  2004/06/08 09:31:15  rurban
2294 // fixed typo detected by lucidcarbon (line 1663 assertion)
2295 //
2296 // Revision 1.89  2004/06/06 16:58:51  rurban
2297 // added more required ActionPages for foreign languages
2298 // install now english ActionPages if no localized are found. (again)
2299 // fixed default anon user level to be 0, instead of -1
2300 //   (wrong "required administrator to view this page"...)
2301 //
2302 // Revision 1.88  2004/06/04 20:32:53  rurban
2303 // Several locale related improvements suggested by Pierrick Meignen
2304 // LDAP fix by John Cole
2305 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
2306 //
2307 // Revision 1.87  2004/06/04 12:40:21  rurban
2308 // Restrict valid usernames to prevent from attacks against external auth or compromise
2309 // possible holes.
2310 // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
2311 // Fxied more warnings
2312 //
2313 // Revision 1.86  2004/06/03 18:06:29  rurban
2314 // fix file locking issues (only needed on write)
2315 // fixed immediate LANG and THEME in-session updates if not stored in prefs
2316 // advanced editpage toolbars (search & replace broken)
2317 //
2318 // Revision 1.85  2004/06/03 12:46:03  rurban
2319 // fix signout, level must be 0 not -1
2320 //
2321 // Revision 1.84  2004/06/03 12:36:03  rurban
2322 // fix eval warning on signin
2323 //
2324 // Revision 1.83  2004/06/03 10:18:19  rurban
2325 // fix User locking issues, new config ENABLE_PAGEPERM
2326 //
2327 // Revision 1.82  2004/06/03 09:39:51  rurban
2328 // fix LDAP injection (wildcard in username) detected by Steve Christey, MITRE
2329 //
2330 // Revision 1.81  2004/06/02 18:01:45  rurban
2331 // init global FileFinder to add proper include paths at startup
2332 //   adds PHPWIKI_DIR if started from another dir, lib/pear also
2333 // fix slashify for Windows
2334 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
2335 //
2336 // Revision 1.80  2004/06/02 14:20:27  rurban
2337 // fix adodb DbPassUser login
2338 //
2339 // Revision 1.79  2004/06/01 15:27:59  rurban
2340 // AdminUser only ADMIN_USER not member of Administrators
2341 // some RateIt improvements by dfrankow
2342 // edit_toolbar buttons
2343 //
2344 // Revision 1.78  2004/05/27 17:49:06  rurban
2345 // renamed DB_Session to DbSession (in CVS also)
2346 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
2347 // remove leading slash in error message
2348 // added force_unlock parameter to File_Passwd (no return on stale locks)
2349 // fixed adodb session AffectedRows
2350 // added FileFinder helpers to unify local filenames and DATA_PATH names
2351 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
2352 //
2353 // Revision 1.77  2004/05/18 14:49:51  rurban
2354 // Simplified strings for easier translation
2355 //
2356 // Revision 1.76  2004/05/18 13:30:04  rurban
2357 // prevent from endless loop with oldstyle warnings
2358 //
2359 // Revision 1.75  2004/05/16 22:07:35  rurban
2360 // check more config-default and predefined constants
2361 // various PagePerm fixes:
2362 //   fix default PagePerms, esp. edit and view for Bogo and Password users
2363 //   implemented Creator and Owner
2364 //   BOGOUSERS renamed to BOGOUSER
2365 // fixed syntax errors in signin.tmpl
2366 //
2367 // Revision 1.74  2004/05/15 19:48:33  rurban
2368 // fix some too loose PagePerms for signed, but not authenticated users
2369 //  (admin, owner, creator)
2370 // no double login page header, better login msg.
2371 // moved action_pdf to lib/pdf.php
2372 //
2373 // Revision 1.73  2004/05/15 18:31:01  rurban
2374 // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
2375 //
2376 // Revision 1.72  2004/05/12 10:49:55  rurban
2377 // require_once fix for those libs which are loaded before FileFinder and
2378 //   its automatic include_path fix, and where require_once doesn't grok
2379 //   dirname(__FILE__) != './lib'
2380 // upgrade fix with PearDB
2381 // navbar.tmpl: remove spaces for IE &nbsp; button alignment
2382 //
2383 // Revision 1.71  2004/05/10 12:34:47  rurban
2384 // stabilize DbAuthParam statement pre-prozessor:
2385 //   try old-style and new-style (double-)quoting
2386 //   reject unknown $variables
2387 //   use ->prepare() for all calls (again)
2388 //
2389 // Revision 1.70  2004/05/06 19:26:16  rurban
2390 // improve stability, trying to find the InlineParser endless loop on sf.net
2391 //
2392 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
2393 //
2394 // Revision 1.69  2004/05/06 13:56:40  rurban
2395 // Enable the Administrators group, and add the WIKIPAGE group default root page.
2396 //
2397 // Revision 1.68  2004/05/05 13:37:54  rurban
2398 // Support to remove all UserPreferences
2399 //
2400 // Revision 1.66  2004/05/03 21:44:24  rurban
2401 // fixed sf,net bug #947264: LDAP options are constants, not strings!
2402 //
2403 // Revision 1.65  2004/05/03 13:16:47  rurban
2404 // fixed UserPreferences update, esp for boolean and int
2405 //
2406 // Revision 1.64  2004/05/02 15:10:06  rurban
2407 // new finally reliable way to detect if /index.php is called directly
2408 //   and if to include lib/main.php
2409 // new global AllActionPages
2410 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
2411 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
2412 // PageGroupTestOne => subpages
2413 // renamed PhpWikiRss to PhpWikiRecentChanges
2414 // more docs, default configs, ...
2415 //
2416 // Revision 1.63  2004/05/01 15:59:29  rurban
2417 // more php-4.0.6 compatibility: superglobals
2418 //
2419 // Revision 1.62  2004/04/29 18:31:24  rurban
2420 // Prevent from warning where no db pref was previously stored.
2421 //
2422 // Revision 1.61  2004/04/29 17:18:19  zorloc
2423 // 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.
2424 //
2425 // Revision 1.60  2004/04/27 18:20:54  rurban
2426 // sf.net patch #940359 by rassie
2427 //
2428 // Revision 1.59  2004/04/26 12:35:21  rurban
2429 // POP3_AUTH_PORT deprecated, use "host:port" similar to IMAP
2430 // File_Passwd is already loaded
2431 //
2432 // Revision 1.58  2004/04/20 17:08:28  rurban
2433 // Some IniConfig fixes: prepend our private lib/pear dir
2434 //   switch from " to ' in the auth statements
2435 //   use error handling.
2436 // WikiUserNew changes for the new "'$variable'" syntax
2437 //   in the statements
2438 // TODO: optimization to put config vars into the session.
2439 //
2440 // Revision 1.57  2004/04/19 18:27:45  rurban
2441 // Prevent from some PHP5 warnings (ref args, no :: object init)
2442 //   php5 runs now through, just one wrong XmlElement object init missing
2443 // Removed unneccesary UpgradeUser lines
2444 // Changed WikiLink to omit version if current (RecentChanges)
2445 //
2446 // Revision 1.56  2004/04/19 09:13:24  rurban
2447 // new pref: googleLink
2448 //
2449 // Revision 1.54  2004/04/18 00:24:45  rurban
2450 // re-use our simple prepare: just for table prefix warnings
2451 //
2452 // Revision 1.53  2004/04/12 18:29:15  rurban
2453 // exp. Session auth for already authenticated users from another app
2454 //
2455 // Revision 1.52  2004/04/12 13:04:50  rurban
2456 // added auth_create: self-registering Db users
2457 // fixed IMAP auth
2458 // removed rating recommendations
2459 // ziplib reformatting
2460 //
2461 // Revision 1.51  2004/04/11 10:42:02  rurban
2462 // pgsrc/CreatePagePlugin
2463 //
2464 // Revision 1.50  2004/04/10 05:34:35  rurban
2465 // sf bug#830912
2466 //
2467 // Revision 1.49  2004/04/07 23:13:18  rurban
2468 // fixed pear/File_Passwd for Windows
2469 // fixed FilePassUser sessions (filehandle revive) and password update
2470 //
2471 // Revision 1.48  2004/04/06 20:00:10  rurban
2472 // Cleanup of special PageList column types
2473 // Added support of plugin and theme specific Pagelist Types
2474 // Added support for theme specific UserPreferences
2475 // Added session support for ip-based throttling
2476 //   sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
2477 // Enhanced postgres schema
2478 // Added DB_Session_dba support
2479 //
2480 // Revision 1.47  2004/04/02 15:06:55  rurban
2481 // fixed a nasty ADODB_mysql session update bug
2482 // improved UserPreferences layout (tabled hints)
2483 // fixed UserPreferences auth handling
2484 // improved auth stability
2485 // improved old cookie handling: fixed deletion of old cookies with paths
2486 //
2487 // Revision 1.46  2004/04/01 06:29:51  rurban
2488 // better wording
2489 // RateIt also for ADODB
2490 //
2491
2492 // Local Variables:
2493 // mode: php
2494 // tab-width: 8
2495 // c-basic-offset: 4
2496 // c-hanging-comment-ender-p: nil
2497 // indent-tabs-mode: nil
2498 // End:
2499 ?>