]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/main.php
fix against switching user new/old between sessions
[SourceForge/phpwiki.git] / lib / main.php
1 <?php //-*-php-*-
2 rcs_id('$Id: main.php,v 1.185 2004-11-01 13:55:05 rurban Exp $');
3
4 define ('USE_PREFS_IN_PAGE', true);
5
6 //include "lib/config.php";
7 require_once(dirname(__FILE__)."/stdlib.php");
8 require_once('lib/Request.php');
9 require_once('lib/WikiDB.php');
10 if (ENABLE_USER_NEW)
11     require_once("lib/WikiUserNew.php");
12 else
13     require_once("lib/WikiUser.php");
14 require_once("lib/WikiGroup.php");
15 require_once("lib/PagePerm.php");
16
17 class WikiRequest extends Request {
18     // var $_dbi;
19
20     function WikiRequest () {
21         $this->_dbi = WikiDB::open($GLOBALS['DBParams']);
22         //if ((DEBUG & _DEBUG_TRACE) or (time() % 50 == 0))
23         //    $this->_dbi->_backend->optimize();
24         if (in_array('File', $this->_dbi->getAuthParam('USER_AUTH_ORDER'))) {
25             // force our local copy, until the pear version is fixed.
26             include_once(dirname(__FILE__)."/pear/File_Passwd.php");
27         }
28         if (USE_DB_SESSION) {
29             include_once('lib/DbSession.php');
30             $dbi =& $this->_dbi;
31             $this->_dbsession = & new DbSession($dbi, $dbi->getParam('prefix') . $dbi->getParam('db_session_table'));
32         }
33 // Fixme: Does pear reset the error mask to 1? We have to find the culprit
34 //$x = error_reporting();
35 $this->version = phpwiki_version();
36         $this->Request();
37
38         // Normalize args...
39         $this->setArg('pagename', $this->_deducePagename());
40         $this->setArg('action', $this->_deduceAction());
41
42         // Restore auth state. This doesn't check for proper authorization!
43         if (ENABLE_USER_NEW) {
44             $userid = $this->_deduceUsername(); 
45             if (isset($this->_user) and 
46                 !empty($this->_user->_authhow) and 
47                 $this->_user->_authhow == 'session')
48             {
49                 // users might switch in a session between the two objects.
50                 // restore old auth level here or in updateAuthAndPrefs?
51                 //$user = $this->getSessionVar('wiki_user');
52                 // revive db handle, because these don't survive sessions
53                 if (isset($this->_user) and 
54                      ( ! isa($this->_user, WikiUserClassname())
55                        or (strtolower(get_class($this->_user)) == '_passuser')))
56                 {
57                     $this->_user = WikiUser($userid, $this->_user->_prefs);
58                 }
59                 // revive other db handle
60                 if (isset($this->_user->_prefs->_method) and 
61                          ($this->_user->_prefs->_method == 'SQL' or 
62                          $this->_user->_prefs->_method == 'ADODB'))
63                     $this->_user->_HomePagehandle = $this->getPage($userid);
64                 // need to update the lockfile filehandle
65                 if (  isa($this->_user,'_FilePassUser') and 
66                       $this->_user->_file->lockfile and 
67                       !$this->_user->_file->fplock  )
68                 {
69                     //$level = $this->_user->_level;
70                     $this->_user = UpgradeUser($this->_user, 
71                                                new _FilePassUser($userid, $this->_user->_prefs, $this->_user->_file->filename));
72                     //$this->_user->_level = $level;
73                 }
74                 $this->_prefs = & $this->_user->_prefs;
75             } else {
76                 $user = WikiUser($userid);
77                 $this->_user = & $user;
78                 $this->_prefs = & $this->_user->_prefs;
79             }
80         } else {
81             $this->_user = new WikiUser($this, $this->_deduceUsername());
82             $this->_prefs = $this->_user->getPreferences();
83         }
84     }
85
86     function initializeLang () {
87         $user_lang = $this->getPref('lang');
88         $_lang = @$this->_prefs->_prefs['lang'];
89         //check changed LANG and THEME inside a session. 
90         // (e.g. by using another baseurl)
91         if (isset($this->_user->_authhow) and 
92             $this->_user->_authhow == 'session' and 
93             !isset($_lang->lang) and 
94             $user_lang != $GLOBALS['LANG'])
95         {
96             $user_lang = $GLOBALS['LANG'];
97         }
98         if (isset($user_lang)) {
99             //trigger_error("DEBUG: initializeLang() ". $user_lang ." calling update_locale()...");
100             update_locale($user_lang);
101             FindLocalizedButtonFile(".",'missing_ok','reinit');
102         }
103     }
104
105     function initializeTheme () {
106         global $WikiTheme;
107
108         // Load theme
109         $user_theme = $this->getPref('theme');
110         $_theme = @$this->_prefs->_prefs['theme'];
111         //check changed LANG and THEME inside a session. 
112         // (e.g. by using another baseurl)
113         if (isset($this->_user->_authhow) and 
114             $this->_user->_authhow == 'session' and 
115             !isset($_theme->theme) and
116             defined('THEME') and 
117             $user_theme != THEME)
118         {
119             include_once("themes/" . THEME . "/themeinfo.php");
120         }
121         if (empty($WikiTheme) and isset($user_theme)) {
122             if (strcspn($user_theme,"./\x00]") != strlen($user_theme)) {
123                 trigger_error(sprintf("invalid theme '%s': Invalid characters detected", $user_theme),
124                               E_USER_WARNING);
125                 $user_theme = "default";
126             }
127             include_once("themes/$user_theme/themeinfo.php");
128         }
129         if (empty($WikiTheme) and defined('THEME'))
130             include_once("themes/" . THEME . "/themeinfo.php");
131         if (empty($WikiTheme))
132             include_once("themes/default/themeinfo.php");
133         assert(!empty($WikiTheme));
134     }
135
136     // This really maybe should be part of the constructor, but since it
137     // may involve HTML/template output, the global $request really needs
138     // to be initialized before we do this stuff.
139     function updateAuthAndPrefs () {
140
141         if (isset($this->_user) and (!isa($this->_user,WikiUserClassname()))) {
142             $this->_user = false;       
143         }
144         // Handle authentication request, if any.
145         if ($auth_args = $this->getArg('auth')) {
146             $this->setArg('auth', false);
147             $this->_handleAuthRequest($auth_args); // possible NORETURN
148         }
149         elseif ( ! $this->_user or 
150                  (isa($this->_user,WikiUserClassname()) and ! $this->_user->isSignedIn())) {
151             // If not auth request, try to sign in as saved user.
152             if (($saved_user = $this->getPref('userid')) != false) {
153                 $this->_signIn($saved_user);
154             }
155         }
156
157         // Save preferences in session and cookie
158         if (isset($this->_user) and 
159             (!isset($this->_user->_authhow) or $this->_user->_authhow != 'session')) {
160             $id_only = true; 
161             $this->_user->setPreferences($this->_prefs, $id_only);
162         } else {
163             $this->setSessionVar('wiki_user', $this->_user);
164             //$this->setSessionVar('wiki_prefs', $this->_prefs);
165         }
166
167         // Ensure user has permissions for action
168         // HACK ALERT: We may not set the request arg to create, 
169         // since the pageeditor has an ugly logic for action == create.
170         $action = $this->getArg('action');
171         if ($action == 'edit' or $action == 'create') {
172             $page = $this->getPage();
173             if (! $page->exists() )
174                 $action = 'create';
175             else
176                 $action = 'edit';
177         }
178         $require_level = $this->requiredAuthority($action);
179         if (! $this->_user->hasAuthority($require_level))
180             $this->_notAuthorized($require_level); // NORETURN
181     }
182
183     function getUser () {
184         if (isset($this->_user))
185             return $this->_user;
186         else
187             return $GLOBALS['ForbiddenUser'];
188     }
189     
190     function & getGroup () {
191         if (isset($this->_user) and isset($this->_user->_group))
192             return $this->_user->_group;
193         else
194             return WikiGroup::getGroup();
195     }
196
197     function getPrefs () {
198         return $this->_prefs;
199     }
200
201     // Convenience function:
202     function getPref ($key) {
203         if (isset($this->_prefs)) {
204             return $this->_prefs->get($key);
205         }
206     }
207     function getDbh () {
208         return $this->_dbi;
209     }
210
211     /**
212      * Get requested page from the page database.
213      * By default it will grab the page requested via the URL
214      *
215      * This is a convenience function.
216      * @param string $pagename Name of page to get.
217      * @return WikiDB_Page Object with methods to pull data from
218      * database for the page requested.
219      */
220     function getPage ($pagename = false) {
221         //if (!isset($this->_dbi)) $this->getDbh();
222         if (!$pagename) 
223             $pagename = $this->getArg('pagename');
224         return $this->_dbi->getPage($pagename);
225     }
226
227     /** Get URL for POST actions.
228      *
229      * Officially, we should just use SCRIPT_NAME (or some such),
230      * but that causes problems when we try to issue a redirect, e.g.
231      * after saving a page.
232      *
233      * Some browsers (at least NS4 and Mozilla 0.97 won't accept
234      * a redirect from a page to itself.)
235      *
236      * So, as a HACK, we include pagename and action as query args in
237      * the URL.  (These should be ignored when we receive the POST
238      * request.)
239      */
240     function getPostURL ($pagename=false) {
241         global $HTTP_GET_VARS;
242
243         if ($pagename === false)
244             $pagename = $this->getArg('pagename');
245         $action = $this->getArg('action');
246         if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
247             return WikiURL($pagename, array('action' => $action, 'start_debug' => 1));
248         else
249             return WikiURL($pagename, array('action' => $action));
250     }
251     
252     function _handleAuthRequest ($auth_args) {
253         if (!is_array($auth_args))
254             return;
255
256         // Ignore password unless POST'ed.
257         if (!$this->isPost())
258             unset($auth_args['passwd']);
259
260         $olduser = $this->_user;
261         $user = $this->_user->AuthCheck($auth_args);
262         if (isa($user, WikiUserClassname())) {
263             // Successful login (or logout.)
264             $this->_setUser($user);
265         }
266         elseif (is_string($user)) {
267             // Login attempt failed.
268             $fail_message = $user;
269             $auth_args['pass_required'] = true;
270             // If no password was submitted, it's not really
271             // a failure --- just need to prompt for password...
272             if (!ALLOW_USER_PASSWORDS 
273                 and ALLOW_BOGO_LOGIN 
274                 and !isset($auth_args['passwd'])) 
275             {
276                 $fail_message = false;
277             }
278             $olduser->PrintLoginForm($this, $auth_args, $fail_message, 'newpage');
279             $this->finish();    //NORETURN
280         }
281         else {
282             // Login request cancelled.
283         }
284     }
285
286     /**
287      * Attempt to sign in (bogo-login).
288      *
289      * Fails silently.
290      *
291      * @param $userid string Userid to attempt to sign in as.
292      * @access private
293      */
294     function _signIn ($userid) {
295         if (ENABLE_USER_NEW) {
296             if (! $this->_user )
297                 $this->_user = new _BogoUser($userid);
298             // FIXME: is this always false? shouldn't we try passuser first?
299             if (! $this->_user ) 
300                 $this->_user = new _PassUser($userid);
301         }
302         $user = $this->_user->AuthCheck(array('userid' => $userid));
303         if (isa($user,WikiUserClassname())) {
304             $this->_setUser($user); // success!
305         }
306     }
307
308     // login or logout or restore state
309     function _setUser ($user) {
310         $this->_user = $user;
311         if (defined('MAIN_setUser')) return;
312         define('MAIN_setUser',true);
313         $this->setCookieVar('WIKI_ID', $user->getAuthenticatedId(),
314                             COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
315         if ($user->isSignedIn())
316             $user->_authhow = 'signin';
317
318         // Save userid to prefs..
319         if ( empty($this->_user->_prefs)) {
320             $this->_user->_prefs = $this->_user->getPreferences();
321             $this->_prefs =& $this->_user->_prefs;
322         }
323         $this->_user->_group = $this->getGroup();
324         // avoid recursive objects and session resource handles
325         // avoid overlarge session data (max 4000 byte!)
326         if (isset($user->_group)) {
327             unset($user->_group->_request);
328             unset($user->_group->_user);
329         }
330         if (ENABLE_USER_NEW) {
331             unset($user->_HomePagehandle);
332             unset($user->_auth_dbi);
333         } else {
334             unset($user->_dbi);
335             unset($user->_authdbi);
336             unset($user->_homepage);
337             unset($user->_request);
338         }
339         if (empty($user->page))
340             $user->page = $this->getArg('pagename');
341         if (empty($user->action))
342             $user->action = $this->getArg('action');
343         $this->setSessionVar('wiki_user', $user);
344         $this->_prefs->set('userid',
345                            $user->isSignedIn() ? $user->getId() : '');
346         $this->initializeTheme();
347     }
348
349     /* Permission system */
350     function getLevelDescription($level) {
351         static $levels = false;
352         if (!$levels) 
353             $levels = array('x-1' => _("FORBIDDEN"),
354                             'x0'  => _("ANON"),
355                             'x1'  => _("BOGO"),
356                             'x2'  => _("USER"),
357                             'x10' => _("ADMIN"),
358                             'x100'=> _("UNOBTAINABLE"));
359         return $levels["x".$level];
360     }
361     
362     function _notAuthorized ($require_level) {
363         // Display the authority message in the Wiki's default
364         // language, in case it is not english.
365         //
366         // Note that normally a user will not see such an error once
367         // logged in, unless the admin has altered the default
368         // disallowed wikiactions. In that case we should probably
369         // check the user's language prefs too at this point; this
370         // would be a situation which is not really handled with the
371         // current code.
372         if (empty($GLOBALS['LANG']))
373             update_locale(DEFAULT_LANGUAGE);
374
375         // User does not have required authority.  Prompt for login.
376         $what = $this->getActionDescription($this->getArg('action'));
377         $pass_required = ($require_level >= WIKIAUTH_USER);
378         if ($require_level == WIKIAUTH_UNOBTAINABLE) {
379             global $DisabledActions;
380             if ($DisabledActions and in_array($action, $DisabledActions)) {
381                 $msg = fmt("%s is disallowed on this wiki.",
382                            $this->getDisallowedActionDescription($this->getArg('action')));
383                 $this->finish();
384                 return;
385             }
386             if (class_exists('PagePermission')) {
387                 $user =& $this->_user;
388                 $status = $user->isAuthenticated() ? _("authenticated") : _("not authenticated");
389                 $msg = fmt("%s %s %s is disallowed on this wiki for %s user '%s' (level: %s).",
390                            _("Missing PagePermission:"),
391                            action2access($this->getArg('action')),
392                            $this->getArg('pagename'),
393                            $status, $user->getId(), $this->getLevelDescription($user->_level));
394                 // TODO: add link to action=setacl
395                 $user->PrintLoginForm($this, compact('pass_required'), $msg);
396                 $this->finish();
397                 return;
398             } else {
399                 $msg = fmt("%s is disallowed on this wiki.",
400                            $this->getDisallowedActionDescription($this->getArg('action')));
401                 $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
402                 $this->finish();
403                 return;
404             }
405         }
406         elseif ($require_level == WIKIAUTH_BOGO)
407             $msg = fmt("You must sign in to %s.", $what);
408         elseif ($require_level == WIKIAUTH_USER)
409             $msg = fmt("You must log in to %s.", $what);
410         elseif ($require_level == WIKIAUTH_ANON)
411             $msg = fmt("Access for you is forbidden to %s.", $what);
412         else
413             $msg = fmt("You must be an administrator to %s.", $what);
414
415         $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
416         $this->finish();    // NORETURN
417     }
418
419     // Fixme: for PagePermissions we'll need other strings, 
420     // relevant to the requested page, not just for the action on the whole wiki.
421     function getActionDescription($action) {
422         static $actionDescriptions;
423         if (! $actionDescriptions) {
424             $actionDescriptions
425             = array('browse'     => _("view this page"),
426                     'diff'       => _("diff this page"),
427                     'dumphtml'   => _("dump html pages"),
428                     'dumpserial' => _("dump serial pages"),
429                     'edit'       => _("edit this page"),
430                     'revert'     => _("revert to a previous version of this page"),
431                     'create'     => _("create this page"),
432                     'loadfile'   => _("load files into this wiki"),
433                     'lock'       => _("lock this page"),
434                     'remove'     => _("remove this page"),
435                     'unlock'     => _("unlock this page"),
436                     'upload'     => _("upload a zip dump"),
437                     'verify'     => _("verify the current action"),
438                     'viewsource' => _("view the source of this page"),
439                     'xmlrpc'     => _("access this wiki via XML-RPC"),
440                     'soap'       => _("access this wiki via SOAP"),
441                     'zip'        => _("download a zip dump from this wiki"),
442                     'ziphtml'    => _("download an html zip dump from this wiki")
443                     );
444         }
445         if (in_array($action, array_keys($actionDescriptions)))
446             return $actionDescriptions[$action];
447         else
448             return $action;
449     }
450     
451     /**
452 TODO: check against these cases:
453         if ($DisabledActions and in_array($action, $DisabledActions))
454             return WIKIAUTH_UNOBTAINABLE;
455
456         if (ENABLE_PAGEPERM and class_exists("PagePermission")) {
457            return requiredAuthorityForPage($action);
458            
459 => Browsing pages is disallowed on this wiki for authenticated user 'rurban' (level: BOGO).
460     */
461     function getDisallowedActionDescription($action) {
462         static $disallowedActionDescriptions;
463         
464         if (! $disallowedActionDescriptions) {
465             $disallowedActionDescriptions
466             = array('browse'     => _("Browsing pages"),
467                     'diff'       => _("Diffing pages"),
468                     'dumphtml'   => _("Dumping html pages"),
469                     'dumpserial' => _("Dumping serial pages"),
470                     'edit'       => _("Editing pages"),
471                     'revert'     => _("Reverting to a previous version of pages"),
472                     'create'     => _("Creating pages"),
473                     'loadfile'   => _("Loading files"),
474                     'lock'       => _("Locking pages"),
475                     'remove'     => _("Removing pages"),
476                     'unlock'     => _("Unlocking pages"),
477                     'upload'     => _("Uploading zip dumps"),
478                     'verify'     => _("Verify the current action"),
479                     'viewsource' => _("Viewing the source of pages"),
480                     'xmlrpc'     => _("XML-RPC access"),
481                     'soap'       => _("SOAP access"),
482                     'zip'        => _("Downloading zip dumps"),
483                     'ziphtml'    => _("Downloading html zip dumps")
484                     );
485         }
486         if (in_array($action, array_keys($disallowedActionDescriptions)))
487             return $disallowedActionDescriptions[$action];
488         else
489             return $action;
490     }
491
492     function requiredAuthority ($action) {
493         $auth = $this->requiredAuthorityForAction($action);
494         if (!ALLOW_ANON_USER) return WIKIAUTH_USER;
495         
496         /*
497          * This is a hook for plugins to require authority
498          * for posting to them.
499          *
500          * IMPORTANT: this is not a secure check, so the plugin
501          * may not assume that any POSTs to it are authorized.
502          * All this does is cause PhpWiki to prompt for login
503          * if the user doesn't have the required authority.
504          */
505         if ($this->isPost()) {
506             $post_auth = $this->getArg('require_authority_for_post');
507             if ($post_auth !== false)
508                 $auth = max($auth, $post_auth);
509         }
510         return $auth;
511     }
512         
513     function requiredAuthorityForAction ($action) {
514         global $DisabledActions;
515         
516         if ($DisabledActions and in_array($action, $DisabledActions))
517             return WIKIAUTH_UNOBTAINABLE;
518             
519         if (ENABLE_PAGEPERM and class_exists("PagePermission")) {
520            return requiredAuthorityForPage($action);
521         } else {
522           // FIXME: clean up. 
523           switch ($action) {
524             case 'browse':
525             case 'viewsource':
526             case 'diff':
527             case 'select':
528             case 'xmlrpc':
529             case 'search':
530             case 'pdf':
531                 return WIKIAUTH_ANON;
532
533             case 'zip':
534             case 'ziphtml':
535                 if (defined('ZIPDUMP_AUTH') && ZIPDUMP_AUTH)
536                     return WIKIAUTH_ADMIN;
537                 return WIKIAUTH_ANON;
538
539             case 'edit':
540             case 'revert':
541             case 'soap':
542                 if (defined('REQUIRE_SIGNIN_BEFORE_EDIT') && REQUIRE_SIGNIN_BEFORE_EDIT)
543                     return WIKIAUTH_BOGO;
544                 return WIKIAUTH_ANON;
545                 // return WIKIAUTH_BOGO;
546
547             case 'create':
548                 $page = $this->getPage();
549                 $current = $page->getCurrentRevision();
550                 if ($current->hasDefaultContents())
551                     return $this->requiredAuthorityForAction('edit');
552                 return $this->requiredAuthorityForAction('browse');
553
554             case 'upload':
555             case 'dumpserial':
556             case 'dumphtml':
557             case 'loadfile':
558             case 'remove':
559             case 'lock':
560             case 'unlock':
561             case 'upgrade':
562             case 'chown':
563             case 'setacl':
564             case 'rename':
565                 return WIKIAUTH_ADMIN;
566
567             /* authcheck occurs only in the plugin.
568                required actionpage RateIt */
569             /*
570             case 'rate':
571             case 'delete_rating':
572                 // Perhaps this should be WIKIAUTH_USER
573                 return WIKIAUTH_BOGO;
574             */
575
576             default:
577                 global $WikiNameRegexp;
578                 if (preg_match("/$WikiNameRegexp\Z/A", $action))
579                     return WIKIAUTH_ANON; // ActionPage.
580                 else
581                     return WIKIAUTH_ADMIN;
582           }
583         }
584     }
585     /* End of Permission system */
586
587     function possiblyDeflowerVirginWiki () {
588         if ($this->getArg('action') != 'browse')
589             return;
590         if ($this->getArg('pagename') != HOME_PAGE)
591             return;
592
593         $page = $this->getPage();
594         $current = $page->getCurrentRevision();
595         if ($current->getVersion() > 0)
596             return;             // Homepage exists.
597
598         include('lib/loadsave.php');
599         SetupWiki($this);
600         $this->finish();        // NORETURN
601     }
602
603     function handleAction () {
604         $action = $this->getArg('action');
605         $method = "action_$action";
606         if (method_exists($this, $method)) {
607             $this->{$method}();
608         }
609         elseif ($page = $this->findActionPage($action)) {
610             $this->actionpage($page);
611         }
612         else {
613             $this->finish(fmt("%s: Bad action", $action));
614         }
615     }
616     
617     function finish ($errormsg = false) {
618         static $in_exit = 0;
619
620         if ($in_exit)
621             exit();        // just in case CloseDataBase calls us
622         $in_exit = true;
623
624         global $ErrorManager;
625         $ErrorManager->flushPostponedErrors();
626
627         if (!empty($errormsg)) {
628             PrintXML(HTML::br(),
629                      HTML::hr(),
630                      HTML::h2(_("Fatal PhpWiki Error")),
631                      $errormsg);
632             // HACK:
633             echo "\n</body></html>";
634         }
635         if (is_object($this->_user)) {
636             $this->_user->page   = $this->getArg('pagename');
637             $this->_user->action = $this->getArg('action');
638             unset($this->_user->_HomePagehandle);
639             unset($this->_user->_auth_dbi);
640         }
641         if (!empty($this->_dbi)) {
642             session_write_close();
643             $this->_dbi->close();
644             unset($this->_dbi);
645         }
646         Request::finish();
647         exit;
648     }
649
650     /**
651      * Generally pagename is rawurlencoded for older browsers or mozilla.
652      * Typing a pagename into the IE bar will utf-8 encode it, so we have to 
653      * fix that with fixTitleEncoding().
654      * If USE_PATH_INFO = true, the pagename is stripped from the "/DATA_PATH/PageName&arg=value" line.
655      * If false, we support either "/index.php?pagename=PageName&arg=value",
656      * or the first arg (1.2.x style): "/index.php?PageName&arg=value"
657      */
658     function _deducePagename () {
659         if (trim(rawurldecode($this->getArg('pagename'))))
660             return fixTitleEncoding(rawurldecode($this->getArg('pagename')));
661
662         if (USE_PATH_INFO) {
663             $pathinfo = $this->get('PATH_INFO');
664             if (empty($pathinfo)) { // fix for CGI
665                 $path = $this->get('REQUEST_URI');
666                 $script = $this->get('SCRIPT_NAME');
667                 $pathinfo = substr($path,strlen($script));
668                 $pathinfo = preg_replace('/\?.+$/','',$pathinfo);
669             }
670             $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
671
672             if (trim($tail) != '' and $pathinfo == PATH_INFO_PREFIX . $tail) {
673                 return fixTitleEncoding($tail);
674             }
675         }
676         elseif ($this->isPost()) {
677             /*
678              * In general, for security reasons, HTTP_GET_VARS should be ignored
679              * on POST requests, but we make an exception here (only for pagename).
680              *
681              * The justification for this hack is the following
682              * asymmetry: When POSTing with USE_PATH_INFO set, the
683              * pagename can (and should) be communicated through the
684              * request URL via PATH_INFO.  When POSTing with
685              * USE_PATH_INFO off, this cannot be done --- the only way
686              * to communicate the pagename through the URL is via
687              * QUERY_ARGS (HTTP_GET_VARS).
688              */
689             global $HTTP_GET_VARS;
690             if (isset($HTTP_GET_VARS['pagename']) and trim($HTTP_GET_VARS['pagename'])) { 
691                 return fixTitleEncoding(rawurldecode($HTTP_GET_VARS['pagename']));
692             }
693         }
694
695         /*
696          * Support for PhpWiki 1.2 style requests.
697          * Strip off "&" args (?PageName&action=...&start_debug,...)
698          */
699         $query_string = $this->get('QUERY_STRING');
700         if (trim(rawurldecode($query_string)) and preg_match('/^([^&=]+)(&.+)?$/', $query_string, $m)) {
701             return fixTitleEncoding(rawurldecode($m[1]));
702         }
703
704         return fixTitleEncoding(HOME_PAGE);
705     }
706
707     function _deduceAction () {
708         if (!($action = $this->getArg('action'))) {
709             // Detect XML-RPC requests
710             if ($this->isPost()
711                 && $this->get('CONTENT_TYPE') == 'text/xml') {
712                 global $HTTP_RAW_POST_DATA;
713                 if (strstr($HTTP_RAW_POST_DATA, '<methodCall>')) {
714                     return 'xmlrpc';
715                 }
716             }
717             return 'browse';    // Default if no action specified.
718         }
719
720         if (method_exists($this, "action_$action"))
721             return $action;
722
723         // Allow for, e.g. action=LikePages
724         if ($this->isActionPage($action))
725             return $action;
726
727         // Handle untranslated actionpages in non-english
728         // (people playing with switching languages)
729         if (0 and $GLOBALS['LANG'] != 'en') {
730             require_once("lib/plugin/_WikiTranslation.php");
731             $trans = new WikiPlugin__WikiTranslation();
732             $en_action = $trans->translate($action,'en',$GLOBALS['LANG']);
733             if ($this->isActionPage($en_action))
734                 return $en_action;
735         }
736
737         trigger_error("$action: Unknown action", E_USER_NOTICE);
738         return 'browse';
739     }
740
741     function _deduceUsername() {
742         global $HTTP_SERVER_VARS, $HTTP_ENV_VARS;
743
744         if (!empty($this->args['auth']) and !empty($this->args['auth']['userid']))
745             return $this->args['auth']['userid'];
746
747         if (!empty($HTTP_SERVER_VARS['PHP_AUTH_USER']))
748             return $HTTP_SERVER_VARS['PHP_AUTH_USER'];
749         if (!empty($HTTP_ENV_VARS['REMOTE_USER']))
750             return $HTTP_ENV_VARS['REMOTE_USER'];
751             
752         if ($user = $this->getSessionVar('wiki_user')) {
753             /// switched auth between sessions
754             if (isa($user, WikiUserClassname())) {
755                 $this->_user = $user;
756                 $this->_user->_authhow = 'session';
757                 return ENABLE_USER_NEW ? $user->UserName() : $this->_user;
758             }
759         }
760         if ($userid = $this->getCookieVar('WIKI_ID')) {
761             if (!empty($userid) and substr($userid,0,2) != 's:') {
762                 $this->_user->authhow = 'cookie';
763                 return $userid;
764             }
765         }
766         return false;
767     }
768     
769     function _isActionPage ($pagename) {
770         $dbi = $this->getDbh();
771         $page = $dbi->getPage($pagename);
772         if (!$page) return false;
773         $rev = $page->getCurrentRevision();
774         // FIXME: more restrictive check for sane plugin?
775         if (strstr($rev->getPackedContent(), '<?plugin'))
776             return true;
777         if (!$rev->hasDefaultContents())
778             trigger_error("$pagename: Does not appear to be an 'action page'", E_USER_NOTICE);
779         return false;
780     }
781
782     function findActionPage ($action) {
783         static $cache;
784
785         // check for translated version, as per users preferred language
786         // (or system default in case it is not en)
787         $translation = gettext($action);
788
789         if (isset($cache) and isset($cache[$translation]))
790             return $cache[$translation];
791
792         // check for cached translated version
793         if ($this->_isActionPage($translation))
794             return $cache[$action] = $translation;
795
796         // Allow for, e.g. action=LikePages
797         if (!isWikiWord($action))
798             return $cache[$action] = false;
799
800         // check for translated version (default language)
801         global $LANG;
802         if ($LANG != "en") {
803             require_once("lib/WikiPlugin.php");
804             require_once("lib/plugin/_WikiTranslation.php");
805             $trans = new WikiPlugin__WikiTranslation();
806             $trans->lang = $LANG;
807             $default = $trans->translate_to_en($action, $LANG);
808             if ($this->_isActionPage($default))
809                 return $cache[$action] = $default;
810         } else {
811             $default = $translation;
812         }
813         
814         // check for english version
815         if ($action != $translation and $action != $default) {
816             if ($this->_isActionPage($action))
817                 return $cache[$action] = $action;
818         }
819
820         trigger_error("$action: Cannot find action page", E_USER_NOTICE);
821         return $cache[$action] = false;
822     }
823     
824     function isActionPage ($pagename) {
825         return $this->findActionPage($pagename);
826     }
827
828     function action_browse () {
829         $this->buffer_output();
830         include_once("lib/display.php");
831         displayPage($this);
832     }
833
834     function action_verify () {
835         $this->action_browse();
836     }
837
838     function actionpage ($action) {
839         $this->buffer_output();
840         include_once("lib/display.php");
841         actionPage($this, $action);
842     }
843
844     function adminActionSubpage ($subpage) {
845         $page = _("PhpWikiAdministration")."/".$subpage;
846         $action = $this->findActionPage($page);
847         if ($action) {
848             $this->setArg('s',$this->getArg('pagename'));
849             $this->setArg('verify',1);
850             $this->setArg('action',$action);
851             $this->actionpage($action);
852         } else {
853             trigger_error($page.": Cannot find action page", E_USER_WARNING);
854         }
855     }
856
857     function action_chown () {
858         $this->adminActionSubpage(_("Chown"));
859     }
860
861     function action_setacl () {
862         $this->adminActionSubpage(_("SetAcl"));
863     }
864
865     function action_rename () {
866         $this->adminActionSubpage(_("Rename"));
867     }
868
869     function action_dump () {
870         $action = $this->findActionPage(_("PageDump"));
871         if ($action) {
872             $this->actionpage($action);
873         } else {
874             // redirect to action=upgrade if admin?
875             trigger_error(_("PageDump").": Cannot find action page", E_USER_WARNING);
876         }
877     }
878
879     function action_diff () {
880         $this->buffer_output();
881         include_once "lib/diff.php";
882         showDiff($this);
883     }
884
885     function action_search () {
886         // This is obsolete: reformulate URL and redirect.
887         // FIXME: this whole section should probably be deleted.
888         if ($this->getArg('searchtype') == 'full') {
889             $search_page = _("FullTextSearch");
890         }
891         else {
892             $search_page = _("TitleSearch");
893         }
894         $this->redirect(WikiURL($search_page,
895                                 array('s' => $this->getArg('searchterm')),
896                                 'absolute_url'));
897     }
898
899     function action_edit () {
900         $this->buffer_output();
901         include "lib/editpage.php";
902         $e = new PageEditor ($this);
903         $e->editPage();
904     }
905
906     function action_create () {
907         $this->action_edit();
908     }
909     
910     function action_viewsource () {
911         $this->buffer_output();
912         include "lib/editpage.php";
913         $e = new PageEditor ($this);
914         $e->viewSource();
915     }
916
917     function action_lock () {
918         $page = $this->getPage();
919         $page->set('locked', true);
920         $this->_dbi->touch();
921         $this->action_browse();
922     }
923
924     function action_unlock () {
925         // FIXME: This check is redundant.
926         //$user->requireAuth(WIKIAUTH_ADMIN);
927         $page = $this->getPage();
928         $page->set('locked', false);
929         $this->_dbi->touch();
930         $this->action_browse();
931     }
932
933     function action_remove () {
934         // FIXME: This check is redundant.
935         //$user->requireAuth(WIKIAUTH_ADMIN);
936         $pagename = $this->getArg('pagename');
937         if (strstr($pagename,_('PhpWikiAdministration'))) {
938             $this->action_browse();
939         } else {
940             include('lib/removepage.php');
941             RemovePage($this);
942         }
943     }
944
945     function action_xmlrpc () {
946         include_once("lib/XmlRpcServer.php");
947         $xmlrpc = new XmlRpcServer($this);
948         $xmlrpc->service();
949     }
950     
951     function action_revert () {
952         include_once "lib/loadsave.php";
953         RevertPage($this);
954     }
955
956     function action_zip () {
957         include_once("lib/loadsave.php");
958         MakeWikiZip($this);
959         // I don't think it hurts to add cruft at the end of the zip file.
960         //echo "\n========================================================\n";
961         //echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
962     }
963
964     function action_ziphtml () {
965         include_once("lib/loadsave.php");
966         MakeWikiZipHtml($this);
967         // I don't think it hurts to add cruft at the end of the zip file.
968         echo "\n========================================================\n";
969         echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
970     }
971
972     function action_dumpserial () {
973         include_once("lib/loadsave.php");
974         DumpToDir($this);
975     }
976
977     function action_dumphtml () {
978         include_once("lib/loadsave.php");
979         DumpHtmlToDir($this);
980     }
981
982     function action_upload () {
983         include_once("lib/loadsave.php");
984         LoadPostFile($this);
985     }
986
987     function action_upgrade () {
988         include_once("lib/loadsave.php");
989         include_once("lib/upgrade.php");
990         DoUpgrade($this);
991     }
992
993     function action_loadfile () {
994         include_once("lib/loadsave.php");
995         LoadFileOrDir($this);
996     }
997
998     function action_pdf () {
999         include_once("lib/pdf.php");
1000         ConvertAndDisplayPdf($this);
1001     }
1002     
1003 }
1004
1005 //FIXME: deprecated
1006 function is_safe_action ($action) {
1007     return WikiRequest::requiredAuthorityForAction($action) < WIKIAUTH_ADMIN;
1008 }
1009
1010 function validateSessionPath() {
1011     // Try to defer any session.save_path PHP errors before any html
1012     // is output, which causes some versions of IE to display a blank
1013     // page (due to its strict mode while parsing a page?).
1014     if (! is_writeable(ini_get('session.save_path'))) {
1015         $tmpdir = '/tmp';
1016         trigger_error
1017             (sprintf(_("%s is not writable."),
1018                      _("The session.save_path directory"))
1019              . "\n"
1020              . sprintf(_("Please ensure that %s is writable, or redefine %s in config/config.ini."),
1021                        sprintf(_("the directory '%s'"),
1022                                ini_get('session.save_path')),
1023                        'session.save_path')
1024              . "\n"
1025              . sprintf(_("Attempting to use the directory '%s' instead."),
1026                        $tmpdir)
1027              , E_USER_NOTICE);
1028         if (! is_writeable($tmpdir)) {
1029             trigger_error
1030                 (sprintf(_("%s is not writable."), $tmpdir)
1031                  . "\n"
1032                  . _("Users will not be able to sign in.")
1033                  , E_USER_NOTICE);
1034         }
1035         else
1036             ini_set('session.save_path', $tmpdir);
1037     }
1038 }
1039
1040 function main () {
1041     if (!USE_DB_SESSION)
1042         validateSessionPath();
1043
1044     global $request;
1045     if ((DEBUG & _DEBUG_APD) and extension_loaded("apd"))
1046         apd_set_session_trace(9);
1047
1048     // Postpone warnings
1049     global $ErrorManager;
1050     if (defined('E_STRICT')) // and (E_ALL & E_STRICT)) // strict php5?
1051         $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE|E_USER_WARNING|E_WARNING|E_STRICT);
1052     else
1053         $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE|E_USER_WARNING|E_WARNING);
1054     $request = new WikiRequest();
1055
1056     $action = $request->getArg('action');
1057     if (substr($action, 0, 3) != 'zip') {
1058         if ($action == 'pdf')
1059             $ErrorManager->setPostponedErrorMask(-1); // everything
1060         //else // reject postponing of warnings
1061         //    $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
1062     }
1063
1064     /*
1065      * Allow for disabling of markup cache.
1066      * (Mostly for debugging ... hopefully.)
1067      *
1068      * See also <?plugin WikiAdminUtils action=purge-cache ?>
1069      */
1070     if (!defined('WIKIDB_NOCACHE_MARKUP') and $request->getArg('nocache'))
1071         define('WIKIDB_NOCACHE_MARKUP', $request->getArg('nocache'));
1072     
1073     // Initialize with system defaults in case user not logged in.
1074     // Should this go into constructor?
1075     $request->initializeTheme();
1076
1077     $request->updateAuthAndPrefs();
1078     $request->initializeLang();
1079     
1080     //FIXME:
1081     //if ($user->is_authenticated())
1082     //  $LogEntry->user = $user->getId();
1083
1084     // Memory optimization:
1085     // http://www.procata.com/blog/archives/2004/05/27/rephlux-and-php-memory-usage/
1086     // kill the global PEAR _PEAR_destructor_object_list
1087     if (!empty($_PEAR_destructor_object_list))
1088         $_PEAR_destructor_object_list = array();
1089     $request->possiblyDeflowerVirginWiki();
1090     
1091 // hack! define proper actions for these.
1092 if (defined('WIKI_XMLRPC') and WIKI_XMLRPC) return;
1093 if (defined('WIKI_SOAP')   and WIKI_SOAP)   return;
1094
1095     $validators = array('wikiname' => WIKI_NAME,
1096                         'args'     => hash($request->getArgs()),
1097                         'prefs'    => hash($request->getPrefs()));
1098     if (CACHE_CONTROL == 'STRICT') {
1099         $dbi = $request->getDbh();
1100         $timestamp = $dbi->getTimestamp();
1101         $validators['mtime'] = $timestamp;
1102         $validators['%mtime'] = (int)$timestamp;
1103     }
1104     // FIXME: we should try to generate strong validators when possible,
1105     // but for now, our validator is weak, since equal validators do not
1106     // indicate byte-level equality of content.  (Due to DEBUG timing output, etc...)
1107     //
1108     // (If DEBUG if off, this may be a strong validator, but I'm going
1109     // to go the paranoid route here pending further study and testing.)
1110     //
1111     $validators['%weak'] = true;
1112     $request->setValidators($validators);
1113    
1114     $request->handleAction();
1115
1116     if (DEBUG and DEBUG & _DEBUG_INFO) phpinfo(INFO_VARIABLES);
1117     $request->finish();
1118 }
1119
1120 //$x = error_reporting();  // DEBUG: why is it 1 here? should be E_ALL
1121 if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
1122     error_reporting(E_ALL & ~E_STRICT);         // exclude E_STRICT
1123 else
1124     error_reporting(E_ALL); // php4
1125 // don't run the main loop for special requests (test, getimg, xmlrpc, soap, ...)
1126 if (!defined('PHPWIKI_NOMAIN') or !PHPWIKI_NOMAIN)
1127     main();
1128
1129
1130 // $Log: not supported by cvs2svn $
1131 // Revision 1.184  2004/11/01 10:43:57  rurban
1132 // seperate PassUser methods into seperate dir (memory usage)
1133 // fix WikiUser (old) overlarge data session
1134 // remove wikidb arg from various page class methods, use global ->_dbi instead
1135 // ...
1136 //
1137 // Revision 1.183  2004/10/14 19:23:58  rurban
1138 // remove debugging prints
1139 //
1140 // Revision 1.182  2004/10/12 13:13:19  rurban
1141 // php5 compatibility (5.0.1 ok)
1142 //
1143 // Revision 1.181  2004/10/07 16:08:58  rurban
1144 // fixed broken FileUser session handling.
1145 //   thanks to Arnaud Fontaine for detecting this.
1146 // enable file user Administrator membership.
1147 //
1148 // Revision 1.180  2004/10/04 23:39:34  rurban
1149 // just aesthetics
1150 //
1151 // Revision 1.179  2004/09/25 18:57:42  rurban
1152 // better ACL error message: view not browse, change not setacl, ...
1153 //
1154 // Revision 1.178  2004/09/25 16:27:36  rurban
1155 // better not allowed description: on global disallowed, and on missing pageperms
1156 //
1157 // Revision 1.177  2004/09/14 10:31:09  rurban
1158 // exclude E_STRICT for php5: untested. I believe this must be set earlier because the parsing step is already strict, and this is called at run-time
1159 //
1160 // Revision 1.176  2004/08/05 17:33:22  rurban
1161 // aesthetic typo
1162 //
1163 // Revision 1.175  2004/07/13 13:08:25  rurban
1164 // fix PEAR memory waste issues
1165 //
1166 // Revision 1.174  2004/07/08 13:50:32  rurban
1167 // various unit test fixes: print error backtrace on _DEBUG_TRACE; allusers fix; new PHPWIKI_NOMAIN constant for omitting the mainloop
1168 //
1169 // Revision 1.173  2004/07/05 12:57:54  rurban
1170 // add mysql timeout
1171 //
1172 // Revision 1.172  2004/07/03 08:04:19  rurban
1173 // fixed implicit PersonalPage login (e.g. on edit), fixed to check against create ACL on create, not edit
1174 //
1175 // Revision 1.171  2004/06/29 09:30:42  rurban
1176 // force string hash
1177 //
1178 // Revision 1.170  2004/06/25 14:29:20  rurban
1179 // WikiGroup refactoring:
1180 //   global group attached to user, code for not_current user.
1181 //   improved helpers for special groups (avoid double invocations)
1182 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
1183 // fixed a XHTML validation error on userprefs.tmpl
1184 //
1185 // Revision 1.169  2004/06/20 14:42:54  rurban
1186 // various php5 fixes (still broken at blockparser)
1187 //
1188 // Revision 1.168  2004/06/17 10:39:18  rurban
1189 // fix reverse translation of possible actionpage
1190 //
1191 // Revision 1.167  2004/06/16 13:21:16  rurban
1192 // stabilize on failing ldap queries or bind
1193 //
1194 // Revision 1.166  2004/06/15 09:15:52  rurban
1195 // IMPORTANT: fixed passwd handling for passwords stored in prefs:
1196 //   fix encrypted usage, actually store and retrieve them from db
1197 //   fix bogologin with passwd set.
1198 // fix php crashes with call-time pass-by-reference (references wrongly used
1199 //   in declaration AND call). This affected mainly Apache2 and IIS.
1200 //   (Thanks to John Cole to detect this!)
1201 //
1202 // Revision 1.165  2004/06/14 11:31:37  rurban
1203 // renamed global $Theme to $WikiTheme (gforge nameclash)
1204 // inherit PageList default options from PageList
1205 //   default sortby=pagename
1206 // use options in PageList_Selectable (limit, sortby, ...)
1207 // added action revert, with button at action=diff
1208 // added option regex to WikiAdminSearchReplace
1209 //
1210 // Revision 1.164  2004/06/13 13:54:25  rurban
1211 // Catch fatals on the four dump calls (as file and zip, as html and mimified)
1212 // FoafViewer: Check against external requirements, instead of fatal.
1213 // Change output for xhtmldumps: using file:// urls to the local fs.
1214 // Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
1215 // Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
1216 //
1217 // Revision 1.163  2004/06/13 11:35:32  rurban
1218 // check for create action on action=edit not to fool PagePerm checks
1219 //
1220 // Revision 1.162  2004/06/08 10:05:11  rurban
1221 // simplified admin action shortcuts
1222 //
1223 // Revision 1.161  2004/06/07 22:58:40  rurban
1224 // simplified chown, setacl, dump actions
1225 //
1226 // Revision 1.160  2004/06/07 22:44:14  rurban
1227 // added simplified chown, setacl actions
1228 //
1229 // Revision 1.159  2004/06/06 16:58:51  rurban
1230 // added more required ActionPages for foreign languages
1231 // install now english ActionPages if no localized are found. (again)
1232 // fixed default anon user level to be 0, instead of -1
1233 //   (wrong "required administrator to view this page"...)
1234 //
1235 // Revision 1.158  2004/06/04 20:32:53  rurban
1236 // Several locale related improvements suggested by Pierrick Meignen
1237 // LDAP fix by John Cole
1238 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
1239 //
1240 // Revision 1.157  2004/06/04 12:40:21  rurban
1241 // Restrict valid usernames to prevent from attacks against external auth or compromise
1242 // possible holes.
1243 // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
1244 // Fxied more warnings
1245 //
1246 // Revision 1.156  2004/06/03 17:58:16  rurban
1247 // support immediate LANG and THEME switch inside a session
1248 //
1249 // Revision 1.155  2004/06/03 10:18:19  rurban
1250 // fix FileUser locking issues, new config ENABLE_PAGEPERM
1251 //
1252 // Revision 1.154  2004/06/02 18:01:46  rurban
1253 // init global FileFinder to add proper include paths at startup
1254 //   adds PHPWIKI_DIR if started from another dir, lib/pear also
1255 // fix slashify for Windows
1256 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
1257 //
1258 // Revision 1.153  2004/06/01 15:28:00  rurban
1259 // AdminUser only ADMIN_USER not member of Administrators
1260 // some RateIt improvements by dfrankow
1261 // edit_toolbar buttons
1262 //
1263 // Revision 1.152  2004/05/27 17:49:06  rurban
1264 // renamed DB_Session to DbSession (in CVS also)
1265 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
1266 // remove leading slash in error message
1267 // added force_unlock parameter to File_Passwd (no return on stale locks)
1268 // fixed adodb session AffectedRows
1269 // added FileFinder helpers to unify local filenames and DATA_PATH names
1270 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
1271 //
1272 // Revision 1.151  2004/05/25 12:40:48  rurban
1273 // trim the pagename
1274 //
1275 // Revision 1.150  2004/05/25 10:18:44  rurban
1276 // Check for UTF-8 URLs; Internet Explorer produces these if you
1277 // type non-ASCII chars in the URL bar or follow unescaped links.
1278 // Fixes sf.net bug #953949
1279 // src: languages/Language.php:checkTitleEncoding() from mediawiki
1280 //
1281 // Revision 1.149  2004/05/18 13:31:19  rurban
1282 // hold warnings until headers are sent. new Error-style with collapsed output of repeated messages
1283 //
1284 // Revision 1.148  2004/05/17 17:43:29  rurban
1285 // CGI: no PATH_INFO fix
1286 //
1287 // Revision 1.147  2004/05/15 19:48:33  rurban
1288 // fix some too loose PagePerms for signed, but not authenticated users
1289 //  (admin, owner, creator)
1290 // no double login page header, better login msg.
1291 // moved action_pdf to lib/pdf.php
1292 //
1293 // Revision 1.146  2004/05/15 18:31:01  rurban
1294 // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
1295 //
1296 // Revision 1.145  2004/05/12 10:49:55  rurban
1297 // require_once fix for those libs which are loaded before FileFinder and
1298 //   its automatic include_path fix, and where require_once doesn't grok
1299 //   dirname(__FILE__) != './lib'
1300 // upgrade fix with PearDB
1301 // navbar.tmpl: remove spaces for IE &nbsp; button alignment
1302 //
1303 // Revision 1.144  2004/05/06 19:26:16  rurban
1304 // improve stability, trying to find the InlineParser endless loop on sf.net
1305 //
1306 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
1307 //
1308 // Revision 1.143  2004/05/06 17:30:38  rurban
1309 // CategoryGroup: oops, dos2unix eol
1310 // improved phpwiki_version:
1311 //   pre -= .0001 (1.3.10pre: 1030.099)
1312 //   -p1 += .001 (1.3.9-p1: 1030.091)
1313 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
1314 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
1315 //   backend->backendType(), backend->database(),
1316 //   backend->listOfFields(),
1317 //   backend->listOfTables(),
1318 //
1319 // Revision 1.142  2004/05/04 22:34:25  rurban
1320 // more pdf support
1321 //
1322 // Revision 1.141  2004/05/03 13:16:47  rurban
1323 // fixed UserPreferences update, esp for boolean and int
1324 //
1325 // Revision 1.140  2004/05/02 21:26:38  rurban
1326 // limit user session data (HomePageHandle and auth_dbi have to invalidated anyway)
1327 //   because they will not survive db sessions, if too large.
1328 // extended action=upgrade
1329 // some WikiTranslation button work
1330 // revert WIKIAUTH_UNOBTAINABLE (need it for main.php)
1331 // some temp. session debug statements
1332 //
1333 // Revision 1.139  2004/05/02 15:10:07  rurban
1334 // new finally reliable way to detect if /index.php is called directly
1335 //   and if to include lib/main.php
1336 // new global AllActionPages
1337 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
1338 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
1339 // PageGroupTestOne => subpages
1340 // renamed PhpWikiRss to PhpWikiRecentChanges
1341 // more docs, default configs, ...
1342 //
1343 // Revision 1.138  2004/05/01 15:59:29  rurban
1344 // more php-4.0.6 compatibility: superglobals
1345 //
1346 // Revision 1.137  2004/04/29 19:39:44  rurban
1347 // special support for formatted plugins (one-liners)
1348 //   like <small><plugin BlaBla ></small>
1349 // iter->asArray() helper for PopularNearby
1350 // db_session for older php's (no &func() allowed)
1351 //
1352 // Revision 1.136  2004/04/29 17:18:19  zorloc
1353 // 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.
1354 //
1355 // Revision 1.135  2004/04/26 12:15:01  rurban
1356 // check default config values
1357 //
1358 // Revision 1.134  2004/04/23 06:46:37  zorloc
1359 // Leave DB connection open when USE_DB_SESSION is true so that session info can be written to the DB.
1360 //
1361 // Revision 1.133  2004/04/20 18:10:31  rurban
1362 // config refactoring:
1363 //   FileFinder is needed for WikiFarm scripts calling index.php
1364 //   config run-time calls moved to lib/IniConfig.php:fix_configs()
1365 //   added PHPWIKI_DIR smart-detection code (Theme finder)
1366 //   moved FileFind to lib/FileFinder.php
1367 //   cleaned lib/config.php
1368 //
1369 // Revision 1.132  2004/04/19 21:51:41  rurban
1370 // php5 compatibility: it works!
1371 //
1372 // Revision 1.131  2004/04/19 18:27:45  rurban
1373 // Prevent from some PHP5 warnings (ref args, no :: object init)
1374 //   php5 runs now through, just one wrong XmlElement object init missing
1375 // Removed unneccesary UpgradeUser lines
1376 // Changed WikiLink to omit version if current (RecentChanges)
1377 //
1378 // Revision 1.130  2004/04/18 00:25:53  rurban
1379 // allow "0" pagename
1380 //
1381 // Revision 1.129  2004/04/07 23:13:19  rurban
1382 // fixed pear/File_Passwd for Windows
1383 // fixed FilePassUser sessions (filehandle revive) and password update
1384 //
1385 // Revision 1.128  2004/04/02 15:06:55  rurban
1386 // fixed a nasty ADODB_mysql session update bug
1387 // improved UserPreferences layout (tabled hints)
1388 // fixed UserPreferences auth handling
1389 // improved auth stability
1390 // improved old cookie handling: fixed deletion of old cookies with paths
1391 //
1392 // Revision 1.127  2004/03/25 17:00:31  rurban
1393 // more code to convert old-style pref array to new hash
1394 //
1395 // Revision 1.126  2004/03/24 19:39:03  rurban
1396 // php5 workaround code (plus some interim debugging code in XmlElement)
1397 //   php5 doesn't work yet with the current XmlElement class constructors,
1398 //   WikiUserNew does work better than php4.
1399 // rewrote WikiUserNew user upgrading to ease php5 update
1400 // fixed pref handling in WikiUserNew
1401 // added Email Notification
1402 // added simple Email verification
1403 // removed emailVerify userpref subclass: just a email property
1404 // changed pref binary storage layout: numarray => hash of non default values
1405 // print optimize message only if really done.
1406 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1407 //   prefs should be stored in db or homepage, besides the current session.
1408 //
1409 // Revision 1.125  2004/03/14 16:30:52  rurban
1410 // db-handle session revivification, dba fixes
1411 //
1412 // Revision 1.124  2004/03/12 15:48:07  rurban
1413 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
1414 // simplified lib/stdlib.php:explodePageList
1415 //
1416 // Revision 1.123  2004/03/10 15:41:27  rurban
1417 // use default pref mysql table
1418 //
1419 // Revision 1.122  2004/03/08 18:17:09  rurban
1420 // added more WikiGroup::getMembersOf methods, esp. for special groups
1421 // fixed $LDAP_SET_OPTIONS
1422 // fixed _AuthInfo group methods
1423 //
1424 // Revision 1.121  2004/03/01 13:48:45  rurban
1425 // rename fix
1426 // p[] consistency fix
1427 //
1428 // Revision 1.120  2004/03/01 10:22:41  rurban
1429 // initializeTheme optimize
1430 //
1431 // Revision 1.119  2004/02/26 20:45:06  rurban
1432 // check for ALLOW_ANON_USER = false
1433 //
1434 // Revision 1.118  2004/02/26 01:32:03  rurban
1435 // fixed session login with old WikiUser object. strangely, the errormask gets corruoted to 1, Pear???
1436 //
1437 // Revision 1.117  2004/02/24 17:19:37  rurban
1438 // debugging helpers only
1439 //
1440 // Revision 1.116  2004/02/24 15:17:14  rurban
1441 // improved auth errors with individual pages. the fact that you may not browse a certain admin page does not conclude that you may not browse the whole wiki. renamed browse => view
1442 //
1443 // Revision 1.115  2004/02/15 21:34:37  rurban
1444 // PageList enhanced and improved.
1445 // fixed new WikiAdmin... plugins
1446 // editpage, Theme with exp. htmlarea framework
1447 //   (htmlarea yet committed, this is really questionable)
1448 // WikiUser... code with better session handling for prefs
1449 // enhanced UserPreferences (again)
1450 // RecentChanges for show_deleted: how should pages be deleted then?
1451 //
1452 // Revision 1.114  2004/02/15 17:30:13  rurban
1453 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
1454 // fixed getPreferences() (esp. from sessions)
1455 // fixed setPreferences() (update and set),
1456 // fixed AdoDb DB statements,
1457 // update prefs only at UserPreferences POST (for testing)
1458 // unified db prefs methods (but in external pref classes yet)
1459 //
1460 // Revision 1.113  2004/02/12 13:05:49  rurban
1461 // Rename functional for PearDB backend
1462 // some other minor changes
1463 // SiteMap comes with a not yet functional feature request: includepages (tbd)
1464 //
1465 // Revision 1.112  2004/02/09 03:58:12  rurban
1466 // for now default DB_SESSION to false
1467 // PagePerm:
1468 //   * not existing perms will now query the parent, and not
1469 //     return the default perm
1470 //   * added pagePermissions func which returns the object per page
1471 //   * added getAccessDescription
1472 // WikiUserNew:
1473 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
1474 //   * force init of authdbh in the 2 db classes
1475 // main:
1476 //   * fixed session handling (not triple auth request anymore)
1477 //   * don't store cookie prefs with sessions
1478 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
1479 //
1480 // Revision 1.111  2004/02/07 10:41:25  rurban
1481 // fixed auth from session (still double code but works)
1482 // fixed GroupDB
1483 // fixed DbPassUser upgrade and policy=old
1484 // added GroupLdap
1485 //
1486 // Revision 1.110  2004/02/03 09:45:39  rurban
1487 // LDAP cleanup, start of new Pref classes
1488 //
1489 // Revision 1.109  2004/01/30 19:57:58  rurban
1490 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
1491 //
1492 // Revision 1.108  2004/01/28 14:34:14  rurban
1493 // session table takes the common prefix
1494 // + various minor stuff
1495 // reallow password changing
1496 //
1497 // Revision 1.107  2004/01/27 23:23:39  rurban
1498 // renamed ->Username => _userid for consistency
1499 // renamed mayCheckPassword => mayCheckPass
1500 // fixed recursion problem in WikiUserNew
1501 // fixed bogo login (but not quite 100% ready yet, password storage)
1502 //
1503 // Revision 1.106  2004/01/26 09:17:49  rurban
1504 // * changed stored pref representation as before.
1505 //   the array of objects is 1) bigger and 2)
1506 //   less portable. If we would import packed pref
1507 //   objects and the object definition was changed, PHP would fail.
1508 //   This doesn't happen with an simple array of non-default values.
1509 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1510 //   understands the interim format of array of objects also.
1511 // * simplified $prefs->get() and fixed $prefs->set()
1512 // * added $user->_userid and class '_WikiUser' portability functions
1513 // * fixed $user object ->_level upgrading, mostly using sessions.
1514 //   this fixes yesterdays problems with loosing authorization level.
1515 // * fixed WikiUserNew::checkPass to return the _level
1516 // * fixed WikiUserNew::isSignedIn
1517 // * added explodePageList to class PageList, support sortby arg
1518 // * fixed UserPreferences for WikiUserNew
1519 // * fixed WikiPlugin for empty defaults array
1520 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1521 //   removed sort arg, support sortby arg
1522 //
1523 // Revision 1.105  2004/01/25 03:57:15  rurban
1524 // WikiUserNew support (temp. ENABLE_USER_NEW constant)
1525 //
1526 // Revision 1.104  2003/12/26 06:41:16  carstenklapp
1527 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
1528 // so they don't prevent IE from partially (or not at all) rendering the
1529 // page. This should help a little for the IE user who encounters trouble
1530 // when setting up a new PhpWiki for the first time.
1531 //
1532 // Revision 1.103  2003/12/02 00:10:00  carstenklapp
1533 // Bugfix: Ongoing work to untangle UserPreferences/WikiUser/request code
1534 // mess: UserPreferences should take effect immediately now upon signing
1535 // in.
1536 //
1537 // Revision 1.102  2003/11/25 22:55:32  carstenklapp
1538 // Localization bugfix: For wikis where English is not the default system
1539 // language, make sure that the authority error message (i.e. "You must
1540 // sign in to edit pages in this wiki" etc.) is displayed in the wiki's
1541 // default language. Previously it would always display in English.
1542 // (Added call to update_locale() before displaying any messages prior to
1543 // the login prompt.)
1544 //
1545 // Revision 1.101  2003/11/25 21:49:44  carstenklapp
1546 // Bugfix: For a non-english wiki or when the user's preference is not
1547 // english, the wiki would always use the english ActionPage first if it
1548 // was present rather than the appropriate localised variant. (PhpWikis
1549 // running only in english or Wikis running ONLY without any english
1550 // ActionPages would not notice this bug, only when both english and
1551 // localised ActionPages were in the DB.) Now we check for the localised
1552 // variant first.
1553 //
1554 // Revision 1.100  2003/11/18 16:54:18  carstenklapp
1555 // Reformatting only: Tabs to spaces, added rcs log.
1556 //
1557
1558
1559 // Local Variables:
1560 // mode: php
1561 // tab-width: 8
1562 // c-basic-offset: 4
1563 // c-hanging-comment-ender-p: nil
1564 // indent-tabs-mode: nil
1565 // End:
1566 ?>