]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser.php
renamed DB_Session to DbSession (in CVS also)
[SourceForge/phpwiki.git] / lib / WikiUser.php
1 <?php //-*-php-*-
2 rcs_id('$Id: WikiUser.php,v 1.54 2004-04-29 17:18:19 zorloc Exp $');
3
4 // It is anticipated that when userid support is added to phpwiki,
5 // this object will hold much more information (e-mail,
6 // home(wiki)page, etc.) about the user.
7
8 // There seems to be no clean way to "log out" a user when using HTTP
9 // authentication. So we'll hack around this by storing the currently
10 // logged in username and other state information in a cookie.
11
12 // 2002-09-08 11:44:04 rurban
13 // Todo: Fix prefs cookie/session handling:
14 //       _userid and _homepage cookie/session vars still hold the
15 //       serialized string.
16 //       If no homepage, fallback to prefs in cookie as in 1.3.3.
17
18 define('WIKIAUTH_FORBIDDEN', -1); // Completely not allowed.
19 define('WIKIAUTH_ANON', 0);
20 define('WIKIAUTH_BOGO', 1);     // any valid WikiWord is enough
21 define('WIKIAUTH_USER', 2);     // real auth from a database/file/server.
22
23 define('WIKIAUTH_ADMIN', 10);  // Wiki Admin
24 define('WIKIAUTH_UNOBTAINABLE', 100);  // Permissions that no user can achieve
25
26 $UserPreferences = array(
27                          'userid'        => new _UserPreference(''), // really store this also?
28                          'passwd'        => new _UserPreference(''),
29                          'email'         => new _UserPreference(''),
30                          'emailVerified' => new _UserPreference_bool(),
31                          'notifyPages'   => new _UserPreference(''),
32                          'theme'         => new _UserPreference_theme(THEME),
33                          'lang'          => new _UserPreference_language(DEFAULT_LANGUAGE),
34                          'editWidth'     => new _UserPreference_int(80, 30, 150),
35                          'noLinkIcons'   => new _UserPreference_bool(),
36                          'editHeight'    => new _UserPreference_int(22, 5, 80),
37                          'timeOffset'    => new _UserPreference_numeric(0, -26, 26),
38                          'relativeDates' => new _UserPreference_bool()
39                          );
40
41 function WikiUserClassname() {
42     return 'WikiUser';
43 }
44
45 function UpgradeUser ($olduser, $user) {
46     if (isa($user,'WikiUser') and isa($olduser,'WikiUser')) {
47         // populate the upgraded class with the values from the old object
48         foreach (get_object_vars($olduser) as $k => $v) {
49             $user->$k = $v;     
50         }
51         $GLOBALS['request']->_user = $user;
52         return $user;
53     } else {
54         return false;
55     }
56 }
57
58 /**
59
60 */
61 class WikiUser {
62     var $_userid = false;
63     var $_level  = false;
64     var $_request, $_dbi, $_authdbi, $_homepage;
65     var $_authmethod = '', $_authhow = '';
66
67     /**
68      * Constructor.
69      * 
70      * Populates the instance variables and calls $this->_ok() 
71      * to ensure that the parameters are valid.
72      * @param mixed $userid String of username or WikiUser object.
73      * @param integer $authlevel Authorization level.
74      */
75     function WikiUser (&$request, $userid = false, $authlevel = false) {
76         $this->_request = &$request;
77         $this->_dbi = &$this->_request->getDbh();
78
79         if (isa($userid, 'WikiUser')) {
80             $this->_userid   = $userid->_userid;
81             $this->_level    = $userid->_level;
82         }
83         else {
84             $this->_userid = $userid;
85             $this->_level = $authlevel;
86         }
87         if (!$this->_ok()) {
88             // Paranoia: if state is at all inconsistent, log out...
89             $this->_userid = false;
90             $this->_level = false;
91             $this->_homepage = false;
92             $this->_authhow .= ' paranoia logout';
93         }
94         if ($this->_userid) {
95             $this->_homepage = $this->_dbi->getPage($this->_userid);
96         }
97     }
98
99     /**
100     * Get the string indicating how the user was authenticated.
101     * 
102     * Get the string indicating how the user was authenticated.
103     * Does not seem to be set - jbw
104     * @return string The method of authentication.
105     */
106     function auth_how() {
107         return $this->_authhow;
108     }
109
110     /**
111      * Invariant
112      * 
113      * If the WikiUser object has a valid authorization level and the 
114      * userid is a string returns true, else false.
115      * @return boolean If valid level and username string true, else false
116      */
117     function _ok () {
118         if ((in_array($this->_level, array(WIKIAUTH_BOGO,
119                                            WIKIAUTH_USER,
120                                            WIKIAUTH_ADMIN))
121             &&
122             (is_string($this->_userid)))) {
123             return true;
124         }
125         return false;
126     }
127
128     function UserName() {
129         return $this->_userid;
130     }
131
132     function getId () {
133         return ( $this->isSignedIn()
134                  ? $this->_userid
135                  : $this->_request->get('REMOTE_ADDR') ); // FIXME: globals
136     }
137
138     function getAuthenticatedId() {
139         return ( $this->isAuthenticated()
140                  ? $this->_userid
141                  : $this->_request->get('REMOTE_ADDR') ); // FIXME: globals
142     }
143
144     function isSignedIn () {
145         return $this->_level >= WIKIAUTH_BOGO;
146     }
147
148     function isAuthenticated () {
149         return $this->_level >= WIKIAUTH_BOGO;
150     }
151
152     function isAdmin () {
153         return $this->_level == WIKIAUTH_ADMIN;
154     }
155
156     function hasAuthority ($require_level) {
157         return $this->_level >= $require_level;
158     }
159
160     function AuthCheck ($postargs) {
161         // Normalize args, and extract.
162         $keys = array('userid', 'passwd', 'require_level', 'login', 'logout',
163                       'cancel');
164         foreach ($keys as $key)
165             $args[$key] = isset($postargs[$key]) ? $postargs[$key] : false;
166         extract($args);
167         $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
168
169         if ($logout)
170             return new WikiUser($this->_request); // Log out
171         elseif ($cancel)
172             return false;        // User hit cancel button.
173         elseif (!$login && !$userid)
174             return false;       // Nothing to do?
175
176         $authlevel = $this->_pwcheck($userid, $passwd);
177         if (!$authlevel)
178             return _("Invalid password or userid.");
179         elseif ($authlevel < $require_level)
180             return _("Insufficient permissions.");
181
182         // Successful login.
183         $user = new WikiUser($this->_request,$userid,$authlevel);
184         return $user;
185     }
186
187     function PrintLoginForm (&$request, $args, $fail_message = false,
188                              $seperate_page = true) {
189         include_once('lib/Template.php');
190         // Call update_locale in case the system's default language is not 'en'.
191         // (We have no user pref for lang at this point yet, no one is logged in.)
192         update_locale(DEFAULT_LANGUAGE);
193         $userid = '';
194         $require_level = 0;
195         extract($args); // fixme
196
197         $require_level = max(0, min(WIKIAUTH_ADMIN, (int)$require_level));
198
199         $pagename = $request->getArg('pagename');
200         $login = new Template('login', $request,
201                               compact('pagename', 'userid', 'require_level',
202                                       'fail_message', 'pass_required'));
203         if ($seperate_page) {
204             $top = new Template('html', $request,
205                                 array('TITLE' => _("Sign In")));
206             return $top->printExpansion($login);
207         } else {
208             return $login;
209         }
210     }
211
212     /**
213      * Check password.
214      */
215     function _pwcheck ($userid, $passwd) {
216         global $WikiNameRegexp;
217
218         if (!empty($userid) && $userid == ADMIN_USER) {
219             // $this->_authmethod = 'pagedata';
220             if (defined('ENCRYPTED_PASSWD') && ENCRYPTED_PASSWD)
221                 if ( !empty($passwd)
222                      && crypt($passwd, ADMIN_PASSWD) == ADMIN_PASSWD )
223                     return WIKIAUTH_ADMIN;
224                 else
225                     return false;
226             if (!empty($passwd)) {
227                 if ($passwd == ADMIN_PASSWD)
228                   return WIKIAUTH_ADMIN;
229                 else {
230                     // maybe we forgot to enable ENCRYPTED_PASSWD?
231                     if ( function_exists('crypt')
232                          && crypt($passwd, ADMIN_PASSWD) == ADMIN_PASSWD ) {
233                         trigger_error(_("You forgot to set ENCRYPTED_PASSWD to true. Please update your /index.php"),
234                                       E_USER_WARNING);
235                         return WIKIAUTH_ADMIN;
236                     }
237                 }
238             }
239             return false;
240         }
241         // HTTP Authentication
242         elseif (ALLOW_HTTP_AUTH_LOGIN && !empty($PHP_AUTH_USER)) {
243             // if he ignored the password field, because he is already
244             // authenticated try the previously given password.
245             if (empty($passwd))
246                 $passwd = $PHP_AUTH_PW;
247         }
248
249         // WikiDB_User DB/File Authentication from $DBAuthParams
250         // Check if we have the user. If not try other methods.
251         if (ALLOW_USER_LOGIN) { // && !empty($passwd)) {
252             $request = $this->_request;
253             // first check if the user is known
254             if ($this->exists($userid)) {
255                 $this->_authmethod = 'pagedata';
256                 return ($this->checkPassword($passwd)) ? WIKIAUTH_USER : false;
257             } else {
258                 // else try others such as LDAP authentication:
259                 if (ALLOW_LDAP_LOGIN && !empty($passwd)) {
260                     if ($ldap = ldap_connect(LDAP_AUTH_HOST)) { // must be a valid LDAP server!
261                         $r = @ldap_bind($ldap); // this is an anonymous bind
262                         $st_search = "uid=$userid";
263                         // Need to set the right root search information. see ../index.php
264                         $sr = ldap_search($ldap, LDAP_BASE_DN,
265                                           "$st_search");
266                         $info = ldap_get_entries($ldap, $sr); // there may be more hits with this userid. try every
267                         for ($i = 0; $i < $info["count"]; $i++) {
268                             $dn = $info[$i]["dn"];
269                             // The password is still plain text.
270                             if ($r = @ldap_bind($ldap, $dn, $passwd)) {
271                                 // ldap_bind will return TRUE if everything matches
272                                 ldap_close($ldap);
273                                 $this->_authmethod = 'LDAP';
274                                 return WIKIAUTH_USER;
275                             }
276                         }
277                     } else {
278                         trigger_error("Unable to connect to LDAP server "
279                                       . LDAP_AUTH_HOST, E_USER_WARNING);
280                     }
281                 }
282                 // imap authentication. added by limako
283                 if (ALLOW_IMAP_LOGIN && !empty($passwd)) {
284                     $mbox = @imap_open( "{" . IMAP_AUTH_HOST . "}INBOX",
285                                         $userid, $passwd, OP_HALFOPEN );
286                     if($mbox) {
287                         imap_close($mbox);
288                         $this->_authmethod = 'IMAP';
289                         return WIKIAUTH_USER;
290                     }
291                 }
292             }
293         }
294         if ( ALLOW_BOGO_LOGIN
295              && preg_match('/\A' . $WikiNameRegexp . '\z/', $userid) ) {
296             $this->_authmethod = 'BOGO';
297             return WIKIAUTH_BOGO;
298         }
299         return false;
300     }
301
302     // Todo: try our WikiDB backends.
303     function getPreferences() {
304         // Restore saved preferences.
305
306         // I'd rather prefer only to store the UserId in the cookie or
307         // session, and get the preferences from the db or page.
308         if (!($prefs = $this->_request->getCookieVar('WIKI_PREFS2')))
309             $prefs = $this->_request->getSessionVar('wiki_prefs');
310
311         //if (!$this->_userid && !empty($GLOBALS['HTTP_COOKIE_VARS']['WIKI_ID'])) {
312         //    $this->_userid = $GLOBALS['HTTP_COOKIE_VARS']['WIKI_ID'];
313         //}
314
315         // before we get his prefs we should check if he is signed in
316         if (USE_PREFS_IN_PAGE && $this->homePage()) { // in page metadata
317             // old array
318             if ($pref = $this->_homepage->get('pref')) {
319                 //trigger_error("pref=".$pref);//debugging
320                 $prefs = unserialize($pref);
321             }
322         }
323         return new UserPreferences($prefs);
324     }
325
326     // No cookies anymore for all prefs, only the userid. PHP creates
327     // a session cookie in memory, which is much more efficient, 
328     // but not persistent. Get persistency with a homepage or DB Prefs
329     //
330     // Return the number of changed entries
331     function setPreferences($prefs, $id_only = false) {
332         if (!is_object($prefs)) {
333             $prefs = new UserPreferences($prefs);
334         }
335         // update the session and id
336         $this->_request->setSessionVar('wiki_prefs', $prefs);
337         // $this->_request->setCookieVar('WIKI_PREFS2', $this->_prefs, 365);
338         // simple unpacked cookie
339         if ($this->_userid) setcookie('WIKI_ID', $this->_userid, 365, '/');
340
341         // We must ensure that any password is encrypted.
342         // We don't need any plaintext password.
343         if (! $id_only ) {
344             if ($this->isSignedIn()) {
345                 if ($this->isAdmin())
346                     $prefs->set('passwd', '');
347                 // already stored in index.php, and it might be
348                 // plaintext! well oh well
349                 if ($homepage = $this->homePage()) {
350                     // check for page revision 0
351                     if (! $this->_dbi->isWikiPage($this->_userid)) {
352                         trigger_error(_("Your home page has not been created yet so your preferences cannot not be saved."),
353                                       E_USER_WARNING);
354                     }
355                     else {
356                         if ($this->isAdmin() || !$homepage->get('locked')) {
357                             $homepage->set('pref', serialize($prefs->_prefs));
358                             return sizeof($prefs->_prefs);
359                         }
360                         else {
361                             // An "empty" page could still be
362                             // intentionally locked by admin to
363                             // prevent its creation.
364                             //                            
365                             // FIXME: This permission situation should
366                             // probably be handled by the DB backend,
367                             // once the new WikiUser code has been
368                             // implemented.
369                             trigger_error(_("Your home page is locked so your preferences cannot not be saved.")
370                                           . " " . _("Please contact your PhpWiki administrator for assistance."),
371                                           E_USER_WARNING);
372                         }
373                     }
374                 } else {
375                     trigger_error("No homepage for user found. Creating one...",
376                                   E_USER_WARNING);
377                     $this->createHomepage($prefs);
378                     //$homepage->set('pref', serialize($prefs->_prefs));
379                     return sizeof($prefs->_prefs);
380                 }
381             } else {
382                 trigger_error("you must be signed in", E_USER_WARNING);
383             }
384         }
385         return 0;
386     }
387
388     // check for homepage with user flag.
389     // can be overriden from the auth backends
390     function exists() {
391         $homepage = $this->homePage();
392         return ($this->_userid && $homepage && $homepage->get('pref'));
393     }
394
395     // doesn't check for existance!!! hmm.
396     // how to store metadata in not existing pages? how about versions?
397     function homePage() {
398         if (!$this->_userid)
399             return false;
400         if (!empty($this->_homepage)) {
401             return $this->_homepage;
402         } else {
403             $this->_homepage = $this->_dbi->getPage($this->_userid);
404             return $this->_homepage;
405         }
406     }
407
408     function hasHomePage() {
409         return !$this->homePage();
410     }
411
412     // create user by checking his homepage
413     function createUser ($pref, $createDefaultHomepage = true) {
414         if ($this->exists())
415             return;
416         if ($createDefaultHomepage) {
417             $this->createHomepage($pref);
418         } else {
419             // empty page
420             include "lib/loadsave.php";
421             $pageinfo = array('pagedata' => array('pref' => serialize($pref->_pref)),
422                               'versiondata' => array('author' => $this->_userid),
423                               'pagename' => $this->_userid,
424                               'content' => _('CategoryHomepage'));
425             SavePage ($this->_request, $pageinfo, false, false);
426         }
427         $this->setPreferences($pref);
428     }
429
430     // create user and default user homepage
431     function createHomepage ($pref) {
432         $pagename = $this->_userid;
433         include "lib/loadsave.php";
434
435         // create default homepage:
436         //  properly expanded template and the pref metadata
437         $template = Template('homepage.tmpl', $this->_request);
438         $text  = $template->getExpansion();
439         $pageinfo = array('pagedata' => array('pref' => serialize($pref->_pref)),
440                           'versiondata' => array('author' => $this->_userid),
441                           'pagename' => $pagename,
442                           'content' => $text);
443         SavePage ($this->_request, $pageinfo, false, false);
444
445         // create Calender
446         $pagename = $this->_userid . SUBPAGE_SEPARATOR . _('Preferences');
447         if (! isWikiPage($pagename)) {
448             $pageinfo = array('pagedata' => array(),
449                               'versiondata' => array('author' => $this->_userid),
450                               'pagename' => $pagename,
451                               'content' => "<?plugin Calender ?>\n");
452             SavePage ($this->_request, $pageinfo, false, false);
453         }
454
455         // create Preferences
456         $pagename = $this->_userid . SUBPAGE_SEPARATOR . _('Preferences');
457         if (! isWikiPage($pagename)) {
458             $pageinfo = array('pagedata' => array(),
459                               'versiondata' => array('author' => $this->_userid),
460                               'pagename' => $pagename,
461                               'content' => "<?plugin UserPreferences ?>\n");
462             SavePage ($this->_request, $pageinfo, false, false);
463         }
464     }
465
466     function tryAuthBackends() {
467         return ''; // crypt('') will never be ''
468     }
469
470     // Auth backends must store the crypted password where?
471     // Not in the preferences.
472     function checkPassword($passwd) {
473         $prefs = $this->getPreferences();
474         $stored_passwd = $prefs->get('passwd'); // crypted
475         if (empty($prefs->_prefs['passwd']))    // not stored in the page
476             // allow empty passwords? At least store a '*' then.
477             // try other backend. hmm.
478             $stored_passwd = $this->tryAuthBackends($this->_userid);
479         if (empty($stored_passwd)) {
480             trigger_error(sprintf(_("Old UserPage %s without stored password updated with empty password. Set a password in your UserPreferences."),
481                                   $this->_userid), E_USER_NOTICE);
482             $prefs->set('passwd','*');
483             return true;
484         }
485         if ($stored_passwd == '*')
486             return true;
487         if ( !empty($passwd)
488              && crypt($passwd, $stored_passwd) == $stored_passwd )
489             return true;
490         else
491             return false;
492     }
493
494     function changePassword($newpasswd, $passwd2 = false) {
495         if (! $this->mayChangePass() ) {
496             trigger_error(sprintf("Attempt to change an external password for '%s'. Not allowed!",
497                                   $this->_userid), E_USER_ERROR);
498             return;
499         }
500         if ($passwd2 && $passwd2 != $newpasswd) {
501             trigger_error("The second password must be the same as the first to change it",
502                           E_USER_ERROR);
503             return;
504         }
505         $prefs = $this->getPreferences();
506         //$oldpasswd = $prefs->get('passwd');
507         $prefs->set('passwd', crypt($newpasswd));
508         $this->setPreferences($prefs);
509     }
510
511     function mayChangePass() {
512         // on external DBAuth maybe. on IMAP or LDAP not
513         // on internal DBAuth yes
514         if (in_array($this->_authmethod, array('IMAP', 'LDAP')))
515             return false;
516         if ($this->isAdmin())
517             return false;
518         if ($this->_authmethod == 'pagedata')
519             return true;
520         if ($this->_authmethod == 'authdb')
521             return true;
522     }
523                          }
524
525 // create user and default user homepage
526 // FIXME: delete this, not used?
527 /*
528 function createUser ($userid, $pref) {
529     global $request;
530     $user = new WikiUser ($request, $userid);
531     $user->createUser($pref);
532 }
533 */
534
535 class _UserPreference
536 {
537     function _UserPreference ($default_value) {
538         $this->default_value = $default_value;
539     }
540
541     function sanify ($value) {
542         return (string)$value;
543     }
544
545     function update ($value) {
546     }
547 }
548
549 class _UserPreference_numeric
550 extends _UserPreference
551 {
552     function _UserPreference_numeric ($default, $minval = false,
553                                       $maxval = false) {
554         $this->_UserPreference((double)$default);
555         $this->_minval = (double)$minval;
556         $this->_maxval = (double)$maxval;
557     }
558
559     function sanify ($value) {
560         $value = (double)$value;
561         if ($this->_minval !== false && $value < $this->_minval)
562             $value = $this->_minval;
563         if ($this->_maxval !== false && $value > $this->_maxval)
564             $value = $this->_maxval;
565         return $value;
566     }
567 }
568
569 class _UserPreference_int
570 extends _UserPreference_numeric
571 {
572     function _UserPreference_int ($default, $minval = false, $maxval = false) {
573         $this->_UserPreference_numeric((int)$default, (int)$minval,
574                                        (int)$maxval);
575     }
576
577     function sanify ($value) {
578         return (int)parent::sanify((int)$value);
579     }
580 }
581
582 class _UserPreference_bool
583 extends _UserPreference
584 {
585     function _UserPreference_bool ($default = false) {
586         $this->_UserPreference((bool)$default);
587     }
588
589     function sanify ($value) {
590         if (is_array($value)) {
591             /* This allows for constructs like:
592              *
593              *   <input type="hidden" name="pref[boolPref][]" value="0" />
594              *   <input type="checkbox" name="pref[boolPref][]" value="1" />
595              *
596              * (If the checkbox is not checked, only the hidden input
597              * gets sent. If the checkbox is sent, both inputs get
598              * sent.)
599              */
600             foreach ($value as $val) {
601                 if ($val)
602                     return true;
603             }
604             return false;
605         }
606         return (bool) $value;
607     }
608 }
609
610 class _UserPreference_language
611 extends _UserPreference
612 {
613     function _UserPreference_language ($default = DEFAULT_LANGUAGE) {
614         $this->_UserPreference($default);
615     }
616
617     // FIXME: check for valid locale
618     function sanify ($value) {
619         // Revert to DEFAULT_LANGUAGE if user does not specify
620         // language in UserPreferences or chooses <system language>.
621         if ($value == '' or empty($value))
622             $value = DEFAULT_LANGUAGE;
623
624         return (string) $value;
625     }
626 }
627
628 class _UserPreference_theme
629 extends _UserPreference
630 {
631     function _UserPreference_theme ($default = THEME) {
632         $this->_UserPreference($default);
633     }
634
635     function sanify ($value) {
636         if (findFile($this->_themefile($value), true))
637             return $value;
638         return $this->default_value;
639     }
640
641     function update ($newvalue) {
642         global $Theme;
643         include_once($this->_themefile($newvalue));
644         if (empty($Theme))
645             include_once($this->_themefile(THEME));
646     }
647
648     function _themefile ($theme) {
649         return "themes/$theme/themeinfo.php";
650     }
651 }
652
653 // don't save default preferences for efficiency.
654 class UserPreferences {
655     function UserPreferences ($saved_prefs = false) {
656         $this->_prefs = array();
657
658         if (isa($saved_prefs, 'UserPreferences') && $saved_prefs->_prefs) {
659             foreach ($saved_prefs->_prefs as $name => $value)
660                 $this->set($name, $value);
661         } elseif (is_array($saved_prefs)) {
662             foreach ($saved_prefs as $name => $value)
663                 $this->set($name, $value);
664         }
665     }
666
667     function _getPref ($name) {
668         global $UserPreferences;
669         if (!isset($UserPreferences[$name])) {
670             if ($name == 'passwd2') return false;
671             trigger_error("$name: unknown preference", E_USER_NOTICE);
672             return false;
673         }
674         return $UserPreferences[$name];
675     }
676
677     function get ($name) {
678         if (isset($this->_prefs[$name]))
679             return $this->_prefs[$name];
680         if (!($pref = $this->_getPref($name)))
681             return false;
682         return $pref->default_value;
683     }
684
685     function set ($name, $value) {
686         if (!($pref = $this->_getPref($name)))
687             return false;
688
689         $newvalue = $pref->sanify($value);
690         $oldvalue = $this->get($name);
691
692         // update on changes
693         if ($newvalue != $oldvalue)
694             $pref->update($newvalue);
695
696         // don't set default values to save space (in cookies, db and
697         // sesssion)
698         if ($value == $pref->default_value)
699             unset($this->_prefs[$name]);
700         else
701             $this->_prefs[$name] = $newvalue;
702     }
703
704     function pack ($nonpacked) {
705         return serialize($nonpacked);
706     }
707     function unpack ($packed) {
708         if (!$packed)
709             return false;
710         if (substr($packed,0,2) == "O:") {
711             // Looks like a serialized object
712             return unserialize($packed);
713         }
714         //trigger_error("DEBUG: Can't unpack bad UserPreferences",
715         //E_USER_WARNING);
716         return false;
717     }
718
719     function hash () {
720         return hash($this->_prefs);
721     }
722 }
723
724 // $Log: not supported by cvs2svn $
725 // Revision 1.53  2004/04/10 05:34:35  rurban
726 // sf bug#830912
727 //
728 // Revision 1.52  2004/04/10 02:55:48  rurban
729 // fixed old WikiUser
730 //
731 // Revision 1.51  2004/04/06 20:00:10  rurban
732 // Cleanup of special PageList column types
733 // Added support of plugin and theme specific Pagelist Types
734 // Added support for theme specific UserPreferences
735 // Added session support for ip-based throttling
736 //   sql table schema change: ALTER TABLE session ADD sess_ip CHAR(15);
737 // Enhanced postgres schema
738 // Added DB_Session_dba support
739 //
740 // Revision 1.50  2004/02/26 01:32:03  rurban
741 // fixed session login with old WikiUser object. strangely, the errormask gets corruoted to 1, Pear???
742 //
743 // Revision 1.49  2004/02/15 21:34:37  rurban
744 // PageList enhanced and improved.
745 // fixed new WikiAdmin... plugins
746 // editpage, Theme with exp. htmlarea framework
747 //   (htmlarea yet committed, this is really questionable)
748 // WikiUser... code with better session handling for prefs
749 // enhanced UserPreferences (again)
750 // RecentChanges for show_deleted: how should pages be deleted then?
751 //
752 // Revision 1.48  2004/02/01 09:14:11  rurban
753 // Started with Group_Ldap (not yet ready)
754 // added new _AuthInfo plugin to help in auth problems (warning: may display passwords)
755 // fixed some configurator vars
756 // renamed LDAP_AUTH_SEARCH to LDAP_BASE_DN
757 // changed PHPWIKI_VERSION from 1.3.8a to 1.3.8pre
758 // USE_DB_SESSION defaults to true on SQL
759 // changed GROUP_METHOD definition to string, not constants
760 // changed sample user DBAuthParams from UPDATE to REPLACE to be able to
761 //   create users. (Not to be used with external databases generally, but
762 //   with the default internal user table)
763 //
764 // fixed the IndexAsConfigProblem logic. this was flawed:
765 //   scripts which are the same virtual path defined their own lib/main call
766 //   (hmm, have to test this better, phpwiki.sf.net/demo works again)
767 //
768 // Revision 1.47  2004/01/27 23:23:39  rurban
769 // renamed ->Username => _userid for consistency
770 // renamed mayCheckPassword => mayCheckPass
771 // fixed recursion problem in WikiUserNew
772 // fixed bogo login (but not quite 100% ready yet, password storage)
773 //
774 // Revision 1.46  2004/01/26 09:17:48  rurban
775 // * changed stored pref representation as before.
776 //   the array of objects is 1) bigger and 2)
777 //   less portable. If we would import packed pref
778 //   objects and the object definition was changed, PHP would fail.
779 //   This doesn't happen with an simple array of non-default values.
780 // * use $prefs->retrieve and $prefs->store methods, where retrieve
781 //   understands the interim format of array of objects also.
782 // * simplified $prefs->get() and fixed $prefs->set()
783 // * added $user->_userid and class '_WikiUser' portability functions
784 // * fixed $user object ->_level upgrading, mostly using sessions.
785 //   this fixes yesterdays problems with loosing authorization level.
786 // * fixed WikiUserNew::checkPass to return the _level
787 // * fixed WikiUserNew::isSignedIn
788 // * added explodePageList to class PageList, support sortby arg
789 // * fixed UserPreferences for WikiUserNew
790 // * fixed WikiPlugin for empty defaults array
791 // * UnfoldSubpages: added pagename arg, renamed pages arg,
792 //   removed sort arg, support sortby arg
793 //
794 // Revision 1.45  2003/12/09 20:00:43  carstenklapp
795 // Bugfix: The last BogoUserPrefs-bugfix prevented the admin from saving
796 // prefs into his own homepage, fixed broken logic. Tightened up BogoUser
797 // prefs saving ability by checking for true existance of homepage
798 // (previously a page revision of 0 also counted as valid, again due to
799 // somewhat flawed logic).
800 //
801 // Revision 1.44  2003/12/06 04:56:23  carstenklapp
802 // Security bugfix (minor): Prevent BogoUser~s from saving extraneous
803 // _pref object meta-data within locked pages.
804 //
805 // Previously, BogoUser~s who signed in with a (valid) WikiWord such as
806 // "HomePage" could actually save preferences into that page, even though
807 // it was already locked by the administrator. Thus, any subsequent
808 // WikiLink~s to that page would become prefixed with "that nice little"
809 // UserIcon, as if that page represented a valid user.
810 //
811 // Note that the admin can lock (even) non-existant pages as desired or
812 // necessary (i.e. any DB page whose revision==0), to prevent the
813 // arbitrary BogoUser from saving preference metadata into such a page;
814 // for example, the silly WikiName "@qmgi`Vcft_x|" (that is the
815 // \$examplechars presented in login.tmpl, in case it is not visible here
816 // in the CVS comments).
817 //
818 // http://phpwiki.sourceforge.net/phpwiki/
819 // %C0%F1%ED%E7%E9%E0%D6%E3%E6%F4%DF%F8%FC?action=lock
820 //
821 // To remove the prefs metadata from a page, the admin can use the
822 // EditMetaData plugin, enter pref as the key, leave the value box empty
823 // and then submit the change. For example:
824 //
825 // http://phpwiki.sourceforge.net/phpwiki/
826 // _EditMetaData?page=%C0%F1%ED%E7%E9%E0%D6%E3%E6%F4%DF%F8%FC
827 //
828 // (It seems a rethinking of WikiUserNew.php with its WikiUser and
829 // UserPreferences classes is in order. Ideally the WikiDB would
830 // transparently handle such a situation, perhaps BogoUser~s should
831 // simply be restricted to saving preferences into a cookie until his/her
832 // e-mail address has been verified.)
833 //
834 // Revision 1.43  2003/12/04 19:33:30  carstenklapp
835 // Bugfix: Under certain PhpWiki installations (such as the PhpWiki at
836 // SF), the user was unable to select a theme other than the server's
837 // default. (Use the more robust Theme::findFile instead of PHP's
838 // file_exists function to detect installed themes).
839 //
840 // Revision 1.42  2003/11/30 18:18:13  carstenklapp
841 // Minor code optimization: use include_once instead of require_once
842 // inside functions that might not always called.
843 //
844 // Revision 1.41  2003/11/21 21:32:39  carstenklapp
845 // Bugfix: When DEFAULT_LANGUAGE was not 'en', a user's language prefs
846 // would revert to 'en' when the default <system language> was selected
847 // in UserPreferences and the user saved his preferences. (Check for
848 // empty or blank language pref in sanify function of class
849 // _UserPreference_language and return DEFAULT_LANGUAGE if nothing or
850 // default selected in UserPreferences.)
851 //
852 // Revision 1.40  2003/11/21 16:54:58  carstenklapp
853 // Bugfix: login.tmpl was always displayed in English despite
854 // DEFAULT_LANGUAGE set in index.php. (Added call to
855 // update_locale(DEFAULT_LANGUAGE) before printing login form).
856 //
857 // Revision 1.39  2003/10/28 21:13:46  carstenklapp
858 // Security bug fix for admin password, submitted by Julien Charbon.
859 //
860 // Revision 1.38  2003/09/13 22:25:38  carstenklapp
861 // Hook for new user preference 'noLinkIcons'.
862 //
863 // Revision 1.37  2003/02/22 20:49:55  dairiki
864 // Fixes for "Call-time pass by reference has been deprecated" errors.
865 //
866 // Revision 1.36  2003/02/21 22:50:51  dairiki
867 // Ensure that language preference is a string.
868 //
869 // Revision 1.35  2003/02/16 20:04:47  dairiki
870 // Refactor the HTTP validator generation/checking code.
871 //
872 // This also fixes a number of bugs with yesterdays validator mods.
873 //
874 // Revision 1.34  2003/02/15 02:21:54  dairiki
875 // API Change!  Explicit $request argument added to contructor for WikiUser.
876 //
877 // This seemed the best way to fix a problem whereby the WikiDB
878 // was being opened twice.  (Which while being merely inefficient
879 // when using an SQL backend causes hangage when using a dba backend.)
880 //
881 // Revision 1.33  2003/01/22 03:21:40  zorloc
882 // Modified WikiUser constructor to move the DB request for the homepage to
883 // the end of the logic to prevent it from being requested and then dropped.
884 // Added more phpdoc comments.
885 //
886 // Revision 1.32  2003/01/21 07:40:50  zorloc
887 // Modified WikiUser::_ok() -- Inverted the logic so the default is to return
888 // false and to return true only in the desired condition.  Added phpdoc
889 // comments
890 //
891 // Revision 1.31  2003/01/15 05:37:20  carstenklapp
892 // code reformatting
893 //
894 // Revision 1.30  2003/01/15 04:59:27  carstenklapp
895 // Bugfix: Previously stored preferences were not loading when user
896 // signed in. (Fixed... I hope.)
897 //
898
899 // Local Variables:
900 // mode: php
901 // tab-width: 8
902 // c-basic-offset: 4
903 // c-hanging-comment-ender-p: nil
904 // indent-tabs-mode: nil
905 // End:
906 ?>