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