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