]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/main.php
for the previous pcre short-cut
[SourceForge/phpwiki.git] / lib / main.php
1 <?php //-*-php-*-
2 rcs_id('$Id: main.php,v 1.243 2008-03-22 21:49:18 rurban Exp $');
3 /*
4  Copyright 1999-2007 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 define ('USE_PREFS_IN_PAGE', true);
24
25 //include "lib/config.php";
26 require_once(dirname(__FILE__)."/stdlib.php");
27 require_once('lib/Request.php');
28 require_once('lib/WikiDB.php');
29 if (ENABLE_USER_NEW)
30     require_once("lib/WikiUserNew.php");
31 else
32     require_once("lib/WikiUser.php");
33 require_once("lib/WikiGroup.php");
34 if (ENABLE_PAGEPERM)
35     require_once("lib/PagePerm.php");
36
37 /**
38  * Check permission per page.
39  * Returns true or false.
40  */
41 function mayAccessPage ($access, $pagename) {
42     if (ENABLE_PAGEPERM)
43         return _requiredAuthorityForPagename($access, $pagename); // typically [10-20ms per page]
44     else
45         return true;
46 }
47
48 class WikiRequest extends Request {
49     // var $_dbi;
50
51     function WikiRequest () {
52         $this->_dbi = WikiDB::open($GLOBALS['DBParams']);
53          // first mysql request costs [958ms]! [670ms] is mysql_connect()
54         
55         if (in_array('File', $this->_dbi->getAuthParam('USER_AUTH_ORDER'))) {
56             // force our local copy, until the pear version is fixed.
57             include_once(dirname(__FILE__)."/pear/File_Passwd.php");
58         }
59         if (ENABLE_USER_NEW) {
60             // Preload all necessary userclasses. Otherwise session => __PHP_Incomplete_Class_Name
61             // There's no way to demand-load it later. This way it's much slower, but needs slightly
62             // less memory than loading all.
63             if (ALLOW_BOGO_LOGIN)
64                 include_once("lib/WikiUser/BogoLogin.php");
65             // UserPreferences POST Update doesn't reach this.
66             foreach ($GLOBALS['USER_AUTH_ORDER'] as $method) {
67                 include_once("lib/WikiUser/$method.php");
68                 if ($method == 'Db')
69                     switch( DATABASE_TYPE ) {
70                         case 'SQL'  : include_once("lib/WikiUser/PearDb.php"); break;
71                         case 'ADODB': include_once("lib/WikiUser/AdoDb.php"); break;
72                         case 'PDO'  : include_once("lib/WikiUser/PdoDb.php"); break;
73                     }
74             }
75             unset($method);
76         }
77         if (USE_DB_SESSION) {
78             include_once('lib/DbSession.php');
79             $dbi =& $this->_dbi;
80             $this->_dbsession = new DbSession($dbi, $dbi->getParam('prefix') 
81                                               . $dbi->getParam('db_session_table'));
82         }
83
84 // Fixme: Does pear reset the error mask to 1? We have to find the culprit
85 //$x = error_reporting();
86
87         $this->version = phpwiki_version();
88         $this->Request(); // [90ms]
89
90         // Normalize args...
91         $this->setArg('pagename', $this->_deducePagename());
92         $this->setArg('action', $this->_deduceAction());
93
94         if ((DEBUG & _DEBUG_SQL)
95             or (DATABASE_OPTIMISE_FREQUENCY > 0 and 
96                 (time() % DATABASE_OPTIMISE_FREQUENCY == 0))) {
97             if ($this->_dbi->_backend->optimize())
98                 trigger_error(_("Optimizing database"), E_USER_NOTICE);
99         }
100
101         // Restore auth state. This doesn't check for proper authorization!
102         $userid = $this->_deduceUsername();     
103         if (ENABLE_USER_NEW) {
104             if (isset($this->_user) and 
105                 !empty($this->_user->_authhow) and 
106                 $this->_user->_authhow == 'session')
107             {
108                 // users might switch in a session between the two objects.
109                 // restore old auth level here or in updateAuthAndPrefs?
110                 //$user = $this->getSessionVar('wiki_user');
111                 // revive db handle, because these don't survive sessions
112                 if (isset($this->_user) and 
113                      ( ! isa($this->_user, WikiUserClassname())
114                        or (strtolower(get_class($this->_user)) == '_passuser')))
115                 {
116                     $this->_user = WikiUser($userid, $this->_user->_prefs);
117                 }
118                 // revive other db handle
119                 if (isset($this->_user->_prefs->_method)
120                     and ($this->_user->_prefs->_method == 'SQL' 
121                          or $this->_user->_prefs->_method == 'ADODB' 
122                          or $this->_user->_prefs->_method == 'PDO' 
123                          or $this->_user->_prefs->_method == 'HomePage')) {
124                     $this->_user->_HomePagehandle = $this->getPage($userid);
125                 }
126                 // need to update the lockfile filehandle
127                 if ( isa($this->_user, '_FilePassUser') 
128                      and $this->_user->_file->lockfile 
129                      and !$this->_user->_file->fplock )
130                 {
131                     //$level = $this->_user->_level;
132                     $this->_user = UpgradeUser($this->_user, 
133                                                new _FilePassUser($userid, 
134                                                                  $this->_user->_prefs, 
135                                                                  $this->_user->_file->filename));
136                     //$this->_user->_level = $level;
137                 }
138                 $this->_prefs = & $this->_user->_prefs;
139             } else {
140                 $user = WikiUser($userid);
141                 $this->_user = & $user;
142                 $this->_prefs = & $this->_user->_prefs;
143             }
144         } else {
145             $this->_user = new WikiUser($this, $userid);
146             $this->_prefs = $this->_user->getPreferences();
147         }
148     }
149
150     function initializeLang () {
151         // check non-default pref lang
152         if (empty($this->_prefs->_prefs['lang']))
153             return;
154         $_lang = $this->_prefs->_prefs['lang'];
155         if (isset($_lang->lang) and $_lang->lang != $GLOBALS['LANG']) {
156             $user_lang = $_lang->lang;
157             //check changed LANG and THEME inside a session. 
158             // (e.g. by using another baseurl)
159             if (isset($this->_user->_authhow) and $this->_user->_authhow == 'session')
160                 $user_lang = $GLOBALS['LANG'];
161             update_locale($user_lang);
162             FindLocalizedButtonFile(".",'missing_ok','reinit');
163         }
164     }
165
166     function initializeTheme ($when = 'default') {
167         global $WikiTheme;
168         // if when = 'default', then first time init (default theme, ...)
169         // if when = 'login', then check some callbacks
170         //                    and maybe the theme changed (other theme defined in pref)
171         // if when = 'logout', then check other callbacks
172         //                    and maybe the theme changed (back to default theme)
173
174         // Load non-default theme (when = login)
175         if (!empty($this->_prefs->_prefs['theme'])) {
176             $_theme = $this->_prefs->_prefs['theme'];
177             if (isset($_theme) and isset($_theme->theme))
178                 $user_theme = $_theme->theme;
179             else 
180                 $user_theme = '';
181         }
182         else 
183             $user_theme = $this->getPref('theme');
184
185         //check changed LANG and THEME inside a session. 
186         // (e.g. by using another baseurl)
187         if (isset($this->_user->_authhow) 
188             and $this->_user->_authhow == 'session' 
189             and !isset($_theme->theme) 
190             and defined('THEME') 
191             and $user_theme != THEME)
192         {
193             include_once("themes/" . THEME . "/themeinfo.php");
194         }
195         if (empty($WikiTheme) and isset($user_theme)) {
196             if (strcspn($user_theme,"./\x00]") != strlen($user_theme)) {
197                 trigger_error(sprintf("invalid theme '%s': Invalid characters detected", $user_theme),
198                               E_USER_WARNING);
199                 $user_theme = "default";
200             }
201             include_once("themes/$user_theme/themeinfo.php");
202         }
203         if (empty($WikiTheme) and defined('THEME'))
204             include_once("themes/" . THEME . "/themeinfo.php");
205         if (empty($WikiTheme))
206             include_once("themes/default/themeinfo.php");
207         assert(!empty($WikiTheme));
208
209         // Do not execute global init code anymore
210
211         // Theme callbacks
212         if ($when == 'login') {
213             $WikiTheme->CbUserLogin($this, $this->_user->_userid);
214             if (!$this->_user->hasHomePage()) { // NewUser
215                 $WikiTheme->CbNewUserLogin($this, $this->_user->_userid);
216                 if (in_array($this->getArg('action'), array('edit','create')))
217                     $WikiTheme->CbNewUserEdit($this, $this->_user->_userid);
218             }
219         }
220         elseif ($when == 'logout') {
221             $WikiTheme->CbUserLogout($this, $this->_user->_userid);
222         }
223         elseif ($when == 'default') {
224             $WikiTheme->load();
225             if ($this->_user->_level > 0 and !$this->_user->hasHomePage()) { // NewUser
226                 if (in_array($this->getArg('action'), array('edit','create')))
227                     $WikiTheme->CbNewUserEdit($this, $this->_user->_userid);
228             }
229         }
230     }
231
232     // This really maybe should be part of the constructor, but since it
233     // may involve HTML/template output, the global $request really needs
234     // to be initialized before we do this stuff.
235     // [50ms]: 36ms if wikidb_page::exists
236     function updateAuthAndPrefs () {
237
238         if (isset($this->_user) and (!isa($this->_user, WikiUserClassname()))) {
239             $this->_user = false;       
240         }
241         // Handle authentication request, if any.
242         if ($auth_args = $this->getArg('auth')) {
243             $this->setArg('auth', false);
244             $this->_handleAuthRequest($auth_args); // possible NORETURN
245         }
246         elseif ( ! $this->_user 
247                  or (isa($this->_user, WikiUserClassname()) 
248                      and ! $this->_user->isSignedIn())) {
249             // If not auth request, try to sign in as saved user.
250             if (($saved_user = $this->getPref('userid')) != false) {
251                 $this->_signIn($saved_user);
252             }
253         }
254         
255         $action = $this->getArg('action');
256
257         // Save preferences in session and cookie
258         if ((defined('WIKI_XMLRPC') and !WIKI_XMLRPC) or $action != 'xmlrpc') {
259             if (isset($this->_user) and $this->_user->_userid) {
260                 if (!isset($this->_user->_authhow) or $this->_user->_authhow != 'session') {
261                     $this->_user->setPreferences($this->_prefs, true);
262                 }
263             }
264             $tmpuser = $this->_user; // clone it
265             $this->setSessionVar('wiki_user', $tmpuser);
266             unset($tmpuser);
267         }
268
269         // Ensure user has permissions for action
270         // HACK ALERT: We may not set the request arg to create, 
271         // since the pageeditor has an ugly logic for action == create.
272         if ($action == 'edit' or $action == 'create') {
273             $page = $this->getPage();
274             if (! $page->exists() )
275                 $action = 'create';
276             else
277                 $action = 'edit';
278         }
279         if (! ENABLE_PAGEPERM) { // Bug #1438392 by Matt Brown
280             $require_level = $this->requiredAuthority($action);
281             if (! $this->_user->hasAuthority($require_level))
282                 $this->_notAuthorized($require_level); // NORETURN
283         } else {
284             // novatrope patch to let only _AUTHENTICATED view pages.
285             // If there's not enough authority or forbidden, ask for a password, 
286             // unless it's explicitly unobtainable. Some bad magic though.
287             if ($this->requiredAuthorityForAction($action) == WIKIAUTH_UNOBTAINABLE) {
288                 $require_level = $this->requiredAuthority($action);
289                 $this->_notAuthorized($require_level); // NORETURN
290             }
291         }
292     }
293
294     function & getUser () {
295         if (isset($this->_user))
296             return $this->_user;
297         else
298             return $GLOBALS['ForbiddenUser'];
299     }
300     
301     function & getGroup () {
302         if (isset($this->_user) and isset($this->_user->_group))
303             return $this->_user->_group;
304         else {
305             // Debug Strict: Only variable references should be returned by reference
306             $this->_user->_group = WikiGroup::getGroup();
307             return $this->_user->_group;
308         }
309     }
310
311     function & getPrefs () {
312         return $this->_prefs;
313     }
314
315     // Convenience function:
316     function getPref ($key) {
317         if (isset($this->_prefs)) {
318             return $this->_prefs->get($key);
319         }
320     }
321     function & getDbh () {
322         return $this->_dbi;
323     }
324
325     /**
326      * Get requested page from the page database.
327      * By default it will grab the page requested via the URL
328      *
329      * This is a convenience function.
330      * @param string $pagename Name of page to get.
331      * @return WikiDB_Page Object with methods to pull data from
332      * database for the page requested.
333      */
334     function getPage ($pagename = false) {
335         //if (!isset($this->_dbi)) $this->getDbh();
336         if (!$pagename) 
337             $pagename = $this->getArg('pagename');
338         return $this->_dbi->getPage($pagename);
339     }
340
341     /** Get URL for POST actions.
342      *
343      * Officially, we should just use SCRIPT_NAME (or some such),
344      * but that causes problems when we try to issue a redirect, e.g.
345      * after saving a page.
346      *
347      * Some browsers (at least NS4 and Mozilla 0.97 won't accept
348      * a redirect from a page to itself.)
349      *
350      * So, as a HACK, we include pagename and action as query args in
351      * the URL.  (These should be ignored when we receive the POST
352      * request.)
353      */
354     function getPostURL ($pagename = false) {
355         global $HTTP_GET_VARS;
356
357         if ($pagename === false)
358             $pagename = $this->getArg('pagename');
359         $action = $this->getArg('action');
360         if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
361             return WikiURL($pagename, array('action' => $action, 'start_debug' => 1));
362         elseif ($action == 'edit')
363             return WikiURL($pagename);
364         else
365             return WikiURL($pagename, array('action' => $action));
366     }
367     
368     function _handleAuthRequest ($auth_args) {
369         if (!is_array($auth_args))
370             return;
371
372         // Ignore password unless POST'ed.
373         if (!$this->isPost())
374             unset($auth_args['passwd']);
375
376         $olduser = $this->_user;
377         $user = $this->_user->AuthCheck($auth_args);
378         if (is_string($user)) {
379             // Login attempt failed.
380             $fail_message = $user;
381             $auth_args['pass_required'] = true;
382             // if clicked just on to the "sign in as:" button dont print invalid username.
383             if (!empty($auth_args['login']) and empty($auth_args['userid']))
384                 $fail_message = '';
385             // If no password was submitted, it's not really
386             // a failure --- just need to prompt for password...
387             if (!ALLOW_USER_PASSWORDS 
388                 and ALLOW_BOGO_LOGIN 
389                 and !isset($auth_args['passwd'])) 
390             {
391                 $fail_message = false;
392             }
393             $olduser->PrintLoginForm($this, $auth_args, $fail_message, 'newpage');
394             $this->finish();    //NORETURN
395         }
396         elseif (isa($user, WikiUserClassname())) {
397             // Successful login (or logout.)
398             $this->_setUser($user);
399         }
400         else {
401             // Login request cancelled.
402         }
403     }
404
405     /**
406      * Attempt to sign in (bogo-login).
407      *
408      * Fails silently.
409      *
410      * @param $userid string Userid to attempt to sign in as.
411      * @access private
412      */
413     function _signIn ($userid) {
414         if (ENABLE_USER_NEW) {
415             if (! $this->_user )
416                 $this->_user = new _BogoUser($userid);
417             // FIXME: is this always false? shouldn't we try passuser first?
418             if (! $this->_user ) 
419                 $this->_user = new _PassUser($userid);
420         } else {
421             if (! $this->_user )
422                 $this->_user = new WikiUser($this, $userid);
423         }
424         $user = $this->_user->AuthCheck(array('userid' => $userid));
425         if (isa($user, WikiUserClassname())) {
426             $this->_setUser($user); // success!
427         }
428     }
429
430     // login or logout or restore state
431     function _setUser (&$user) {
432         $this->_user =& $user;
433         if (defined('MAIN_setUser')) return; // don't set cookies twice
434         $this->setCookieVar(getCookieName(), $user->getAuthenticatedId(),
435                             COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
436         $isSignedIn = $user->isSignedIn();
437         if ($isSignedIn) {
438             $user->_authhow = 'signin';
439         }
440
441         // Save userid to prefs..
442         if ( empty($this->_user->_prefs)) {
443             $this->_user->_prefs = $this->_user->getPreferences();
444             $this->_prefs =& $this->_user->_prefs;
445         }
446         $this->_user->_group = $this->getGroup();
447         $this->setSessionVar('wiki_user', $user);
448         $this->_prefs->set('userid',
449                            $isSignedIn ? $user->getId() : '');
450         if (!ENABLE_USER_NEW) {
451             if (empty($this->_user->_request))
452                 $this->_user->_request =& $this;
453             if (empty($this->_user->_dbi))
454                 $this->_user->_dbi =& $this->_dbi;
455         }
456         $this->initializeTheme($isSignedIn ? 'login' : 'logout');
457         define('MAIN_setUser', true);
458     }
459
460     /* Permission system */
461     function getLevelDescription($level) {
462         static $levels = false;
463         if (!$levels) // This looks like a Visual Basic hack. For the very same reason. "0"
464             $levels = array('x-1' => _("FORBIDDEN"),
465                             'x0'  => _("ANON"),
466                             'x1'  => _("BOGO"),
467                             'x2'  => _("USER"),
468                             'x10' => _("ADMIN"),
469                             'x100'=> _("UNOBTAINABLE"));
470         if (!empty($level))
471             $level = '0';
472         if (!empty($levels["x".$level]))
473             return $levels["x".$level];
474         else
475             return _("ANON");
476     }
477     
478     function _notAuthorized ($require_level) {
479         // Display the authority message in the Wiki's default
480         // language, in case it is not english.
481         //
482         // Note that normally a user will not see such an error once
483         // logged in, unless the admin has altered the default
484         // disallowed wikiactions. In that case we should probably
485         // check the user's language prefs too at this point; this
486         // would be a situation which is not really handled with the
487         // current code.
488         if (empty($GLOBALS['LANG']))
489             update_locale(DEFAULT_LANGUAGE);
490
491         // User does not have required authority.  Prompt for login.
492         $what = $this->getActionDescription($this->getArg('action'));
493         $pass_required = ($require_level >= WIKIAUTH_USER);
494         if ($require_level == WIKIAUTH_UNOBTAINABLE) {
495             global $DisabledActions;
496             if ($DisabledActions and in_array($action, $DisabledActions)) {
497                 $msg = fmt("%s is disallowed on this wiki.",
498                            $this->getDisallowedActionDescription($this->getArg('action')));
499                 $this->finish();
500                 return;
501             }
502             // Is the reason a missing ACL or just wrong user or password?
503             if (class_exists('PagePermission')) {
504                 $user =& $this->_user;
505                 $status = $user->isAuthenticated() ? _("authenticated") : _("not authenticated");
506                 $msg = fmt("%s %s %s is disallowed on this wiki for %s user '%s' (level: %s).",
507                            _("Missing PagePermission:"),
508                            action2access($this->getArg('action')),
509                            $this->getArg('pagename'),
510                            $status, $user->getId(), $this->getLevelDescription($user->_level));
511                 // TODO: add link to action=setacl
512                 $user->PrintLoginForm($this, compact('pass_required'), $msg);
513                 $this->finish();
514                 return;
515             } else {
516                 $msg = fmt("%s is disallowed on this wiki.",
517                            $this->getDisallowedActionDescription($this->getArg('action')));
518                 $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
519                 $this->finish();
520                 return;
521             }
522         }
523         elseif ($require_level == WIKIAUTH_BOGO)
524             $msg = fmt("You must sign in to %s.", $what);
525         elseif ($require_level == WIKIAUTH_USER) {
526             if (!ALLOW_ANON_USER)
527                 $msg = fmt("You must log in first to %s", $what);
528             else        
529                 $msg = fmt("You must log in to %s.", $what);
530         } elseif ($require_level == WIKIAUTH_ANON)
531             $msg = fmt("Access for you is forbidden to %s.", $what);
532         else
533             $msg = fmt("You must be an administrator to %s.", $what);
534
535         $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), 
536                                      $msg);
537         if (!$GLOBALS['WikiTheme']->DUMP_MODE)
538             $this->finish();    // NORETURN
539     }
540
541     // Fixme: for PagePermissions we'll need other strings, 
542     // relevant to the requested page, not just for the action on the whole wiki.
543     function getActionDescription($action) {
544         static $actionDescriptions;
545         if (! $actionDescriptions) {
546             $actionDescriptions
547             = array('browse'     => _("view this page"),
548                     'diff'       => _("diff this page"),
549                     'dumphtml'   => _("dump html pages"),
550                     'dumpserial' => _("dump serial pages"),
551                     'edit'       => _("edit this page"),
552                     'rename'     => _("rename this page"),
553                     'revert'     => _("revert to a previous version of this page"),
554                     'create'     => _("create this page"),
555                     'loadfile'   => _("load files into this wiki"),
556                     'lock'       => _("lock this page"),
557                     'remove'     => _("remove this page"),
558                     'unlock'     => _("unlock this page"),
559                     'upload'     => _("upload a zip dump"),
560                     'verify'     => _("verify the current action"),
561                     'viewsource' => _("view the source of this page"),
562                     'xmlrpc'     => _("access this wiki via XML-RPC"),
563                     'soap'       => _("access this wiki via SOAP"),
564                     'zip'        => _("download a zip dump from this wiki"),
565                     'ziphtml'    => _("download a html zip dump from this wiki")
566                     );
567         }
568         if (in_array($action, array_keys($actionDescriptions)))
569             return $actionDescriptions[$action];
570         else
571             return _("use")." ".$action;
572     }
573     
574     /**
575      TODO: check against these cases:
576         if ($DisabledActions and in_array($action, $DisabledActions))
577             return WIKIAUTH_UNOBTAINABLE;
578
579         if (ENABLE_PAGEPERM and class_exists("PagePermission")) {
580            return requiredAuthorityForPage($action);
581            
582 => Browsing pages is disallowed on this wiki for authenticated user 'rurban' (level: BOGO).
583     */
584     function getDisallowedActionDescription($action) {
585         static $disallowedActionDescriptions;
586         
587         if (! $disallowedActionDescriptions) {
588             $disallowedActionDescriptions
589             = array('browse'     => _("Browsing pages"),
590                     'diff'       => _("Diffing pages"),
591                     'dumphtml'   => _("Dumping html pages"),
592                     'dumpserial' => _("Dumping serial pages"),
593                     'edit'       => _("Editing pages"),
594                     'revert'     => _("Reverting to a previous version of pages"),
595                     'create'     => _("Creating pages"),
596                     'loadfile'   => _("Loading files"),
597                     'lock'       => _("Locking pages"),
598                     'remove'     => _("Removing pages"),
599                     'unlock'     => _("Unlocking pages"),
600                     'upload'     => _("Uploading zip dumps"),
601                     'verify'     => _("Verify the current action"),
602                     'viewsource' => _("Viewing the source of pages"),
603                     'xmlrpc'     => _("XML-RPC access"),
604                     'soap'       => _("SOAP access"),
605                     'zip'        => _("Downloading zip dumps"),
606                     'ziphtml'    => _("Downloading html zip dumps")
607                     );
608         }
609         if (in_array($action, array_keys($disallowedActionDescriptions)))
610             return $disallowedActionDescriptions[$action];
611         else
612             return $action;
613     }
614
615     function requiredAuthority ($action) {
616         $auth = $this->requiredAuthorityForAction($action);
617         if (!ALLOW_ANON_USER) return WIKIAUTH_USER;
618         
619         /*
620          * This is a hook for plugins to require authority
621          * for posting to them.
622          *
623          * IMPORTANT: This is not a secure check, so the plugin
624          * may not assume that any POSTs to it are authorized.
625          * All this does is cause PhpWiki to prompt for login
626          * if the user doesn't have the required authority.
627          */
628         if ($this->isPost()) {
629             $post_auth = $this->getArg('require_authority_for_post');
630             if ($post_auth !== false)
631                 $auth = max($auth, $post_auth);
632         }
633         return $auth;
634     }
635         
636     function requiredAuthorityForAction ($action) {
637         global $DisabledActions;
638         
639         if ($DisabledActions and in_array($action, $DisabledActions))
640             return WIKIAUTH_UNOBTAINABLE;
641             
642         if (ENABLE_PAGEPERM and class_exists("PagePermission")) {
643            return requiredAuthorityForPage($action);
644         } else {
645           // FIXME: clean up. 
646           switch ($action) {
647             case 'browse':
648             case 'viewsource':
649             case 'diff':
650             case 'select':
651             case 'search':
652             case 'pdf':
653             case 'captcha':
654             case 'wikitohtml':
655             case 'setpref':
656                 return WIKIAUTH_ANON;
657
658             case 'xmlrpc':
659             case 'soap':
660             case 'dumphtml':
661                 if (INSECURE_ACTIONS_LOCALHOST_ONLY and !is_localhost())
662                     return WIKIAUTH_ADMIN;
663                 return WIKIAUTH_ANON;
664
665             case 'ziphtml':
666                 if (ZIPDUMP_AUTH)
667                     return WIKIAUTH_ADMIN;
668                 if (INSECURE_ACTIONS_LOCALHOST_ONLY and !is_localhost())
669                     return WIKIAUTH_ADMIN;
670                 return WIKIAUTH_ANON;
671
672             case 'dumpserial':
673                 if (INSECURE_ACTIONS_LOCALHOST_ONLY and is_localhost())
674                     return WIKIAUTH_ANON;
675                 return WIKIAUTH_ADMIN;
676
677             case 'zip':
678                 if (ZIPDUMP_AUTH)
679                     return WIKIAUTH_ADMIN;
680                 return WIKIAUTH_ANON;
681
682             case 'edit':
683             case 'revert':
684             case 'rename':
685                 if (defined('REQUIRE_SIGNIN_BEFORE_EDIT') && REQUIRE_SIGNIN_BEFORE_EDIT)
686                     return WIKIAUTH_BOGO;
687                 return WIKIAUTH_ANON;
688                 // return WIKIAUTH_BOGO;
689
690             case 'create':
691                 $page = $this->getPage();
692                 $current = $page->getCurrentRevision();
693                 if ($current->hasDefaultContents())
694                     return $this->requiredAuthorityForAction('edit');
695                 return $this->requiredAuthorityForAction('browse');
696
697             case 'upload':
698             case 'loadfile':
699             case 'remove':
700             case 'lock':
701             case 'unlock':
702             case 'upgrade':
703             case 'chown':
704             case 'setacl':
705                 return WIKIAUTH_ADMIN;
706
707             /* authcheck occurs only in the plugin.
708                required actionpage RateIt */
709             /*
710             case 'rate':
711             case 'delete_rating':
712                 // Perhaps this should be WIKIAUTH_USER
713                 return WIKIAUTH_BOGO;
714             */
715
716             default:
717                 global $WikiNameRegexp;
718                 if (preg_match("/$WikiNameRegexp\Z/A", $action))
719                     return WIKIAUTH_ANON; // ActionPage.
720                 else
721                     return WIKIAUTH_ADMIN;
722           }
723         }
724     }
725     /* End of Permission system */
726
727     function possiblyDeflowerVirginWiki () {
728         if ($this->getArg('action') != 'browse')
729             return;
730         if ($this->getArg('pagename') != HOME_PAGE)
731             return;
732
733         $page = $this->getPage();
734         $current = $page->getCurrentRevision();
735         if ($current->getVersion() > 0)
736             return;             // Homepage exists.
737
738         include_once('lib/loadsave.php');
739         SetupWiki($this);
740         $this->finish();        // NORETURN
741     }
742     
743     // [574ms] mainly template:printexpansion: 393ms and template::expandsubtemplate [100+70+60ms]
744     function handleAction () {
745         $action = $this->getArg('action');
746         if ($this->isPost()  
747             and !$this->_user->isAdmin()
748             and $action != 'browse' 
749             and $action != 'wikitohtml' 
750             )
751         {
752             $page = $this->getPage();
753             if ( $page->get('moderation') ) {
754                 require_once("lib/WikiPlugin.php");
755                 $loader = new WikiPluginLoader();
756                 $plugin = $loader->getPlugin("ModeratedPage");
757                 if ($plugin->handler($this, $page)) {
758                     $CONTENT = HTML::div
759                         (
760                          array('class' => 'wiki-edithelp'),
761                          fmt("%s: action forwarded to a moderator.", 
762                              $action), 
763                          HTML::br(),
764                          _("This action requires moderator approval. Please be patient."));
765                     if (!empty($plugin->_tokens['CONTENT']))
766                         $plugin->_tokens['CONTENT']->pushContent
767                             (
768                              HTML::br(),
769                              _("You must wait for moderator approval."));
770                     else
771                         $plugin->_tokens['CONTENT'] = $CONTENT;
772                     require_once("lib/Template.php");
773                     $title = WikiLink($page->getName());
774                     $title->pushContent(' : ', WikiLink(_("ModeratedPage")));
775                     GeneratePage(Template('browse', $plugin->_tokens), 
776                                  $title,
777                                  $page->getCurrentRevision());
778                     $this->finish();
779                 }
780             }
781         }
782         $method = "action_$action";
783         if (method_exists($this, $method)) {
784             $this->{$method}();
785         }
786         elseif ($page = $this->findActionPage($action)) {
787             $this->actionpage($page);
788         }
789         else {
790             $this->finish(fmt("%s: Bad action", $action));
791         }
792     }
793     
794     function finish ($errormsg = false) {
795         static $in_exit = 0;
796
797         if ($in_exit)
798             exit();        // just in case CloseDataBase calls us
799         $in_exit = true;
800
801         global $ErrorManager;
802         $ErrorManager->flushPostponedErrors();
803
804         if (!empty($errormsg)) {
805             PrintXML(HTML::br(),
806                      HTML::hr(),
807                      HTML::h2(_("Fatal PhpWiki Error")),
808                      $errormsg);
809             // HACK:
810             echo "\n</body></html>";
811         }
812         if (is_object($this->_user)) {
813             $this->_user->page   = $this->getArg('pagename');
814             $this->_user->action = $this->getArg('action');
815             unset($this->_user->_HomePagehandle);
816             unset($this->_user->_auth_dbi);
817             unset($this->_user->_dbi);
818             unset($this->_user->_request);
819         }
820         Request::finish();
821         exit;
822     }
823
824     /**
825      * Generally pagename is rawurlencoded for older browsers or mozilla.
826      * Typing a pagename into the IE bar will utf-8 encode it, so we have to 
827      * fix that with fixTitleEncoding().
828      * If USE_PATH_INFO = true, the pagename is stripped from the "/DATA_PATH/PageName&arg=value" line.
829      * If false, we support either "/index.php?pagename=PageName&arg=value",
830      * or the first arg (1.2.x style): "/index.php?PageName&arg=value"
831      */
832     function _deducePagename () {
833         if (trim(rawurldecode($this->getArg('pagename'))))
834             return fixTitleEncoding(rawurldecode($this->getArg('pagename')));
835
836         if (USE_PATH_INFO) {
837             $pathinfo = $this->get('PATH_INFO');
838             if (empty($pathinfo)) { // fix for CGI
839                 $path = $this->get('REQUEST_URI');
840                 $script = $this->get('SCRIPT_NAME');
841                 $pathinfo = substr($path,strlen($script));
842                 $pathinfo = preg_replace('/\?.+$/','',$pathinfo);
843             }
844             $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
845
846             if (trim($tail) != '' and $pathinfo == PATH_INFO_PREFIX . $tail) {
847                 return fixTitleEncoding($tail);
848             }
849         }
850         elseif ($this->isPost()) {
851             /*
852              * In general, for security reasons, HTTP_GET_VARS should be ignored
853              * on POST requests, but we make an exception here (only for pagename).
854              *
855              * The justification for this hack is the following
856              * asymmetry: When POSTing with USE_PATH_INFO set, the
857              * pagename can (and should) be communicated through the
858              * request URL via PATH_INFO.  When POSTing with
859              * USE_PATH_INFO off, this cannot be done --- the only way
860              * to communicate the pagename through the URL is via
861              * QUERY_ARGS (HTTP_GET_VARS).
862              */
863             global $HTTP_GET_VARS;
864             if (isset($HTTP_GET_VARS['pagename']) and trim($HTTP_GET_VARS['pagename'])) { 
865                 return fixTitleEncoding(rawurldecode($HTTP_GET_VARS['pagename']));
866             }
867         }
868
869         /*
870          * Support for PhpWiki 1.2 style requests.
871          * Strip off "&" args (?PageName&action=...&start_debug,...)
872          */
873         $query_string = $this->get('QUERY_STRING');
874         if (trim(rawurldecode($query_string)) and preg_match('/^([^&=]+)(&.+)?$/', $query_string, $m)) {
875             return fixTitleEncoding(rawurldecode($m[1]));
876         }
877
878         return fixTitleEncoding(HOME_PAGE);
879     }
880
881     function _deduceAction () {
882         if (!($action = $this->getArg('action'))) {
883             // TODO: improve this SOAP.php hack by letting SOAP use index.php 
884             // or any other virtual url as with xmlrpc
885             if (defined('WIKI_SOAP') and WIKI_SOAP)
886                 return 'soap';
887             // Detect XML-RPC requests.
888             if ($this->isPost()
889                 && ($this->get('CONTENT_TYPE') == 'text/xml' 
890                     or $this->get('CONTENT_TYPE') == 'application/xml')
891                 && strstr($GLOBALS['HTTP_RAW_POST_DATA'], '<methodCall>')
892                )
893             {
894                 return 'xmlrpc';
895             }
896             return 'browse';    // Default if no action specified.
897         }
898
899         if (method_exists($this, "action_$action"))
900             return $action;
901
902         // Allow for, e.g. action=LikePages
903         if ($this->isActionPage($action))
904             return $action;
905
906         // Handle untranslated actionpages in non-english
907         // (people playing with switching languages)
908         if (0 and $GLOBALS['LANG'] != 'en') {
909             require_once("lib/plugin/_WikiTranslation.php");
910             $trans = new WikiPlugin__WikiTranslation();
911             $en_action = $trans->translate($action,'en',$GLOBALS['LANG']);
912             if ($this->isActionPage($en_action))
913                 return $en_action;
914         }
915
916         trigger_error("$action: Unknown action", E_USER_NOTICE);
917         return 'browse';
918     }
919
920     function _deduceUsername() {
921         global $HTTP_SERVER_VARS, $HTTP_ENV_VARS;
922
923         if (!empty($this->args['auth']) and !empty($this->args['auth']['userid']))
924             return $this->args['auth']['userid'];
925
926         if ($user = $this->getSessionVar('wiki_user')) {
927             // Switched auth between sessions. 
928             // Note: There's no way to demandload a missing class-definition 
929             // afterwards! Stupid php.
930             if (isa($user, WikiUserClassname())) {
931                 $this->_user = $user;
932                 $this->_user->_authhow = 'session';
933                 return ENABLE_USER_NEW ? $user->UserName() : $this->_user;
934             }
935         }
936
937         // Sessions override http auth
938         if (!empty($HTTP_SERVER_VARS['PHP_AUTH_USER']))
939             return $HTTP_SERVER_VARS['PHP_AUTH_USER'];
940         // pubcookie et al
941         if (!empty($HTTP_SERVER_VARS['REMOTE_USER']))
942             return $HTTP_SERVER_VARS['REMOTE_USER'];
943         if (!empty($HTTP_ENV_VARS['REMOTE_USER']))
944             return $HTTP_ENV_VARS['REMOTE_USER'];
945
946         if ($userid = $this->getCookieVar(getCookieName())) {
947             if (!empty($userid) and substr($userid,0,2) != 's:') {
948                 $this->_user->authhow = 'cookie';
949                 return $userid;
950             }
951         }
952
953         if ($this->getArg('action') == 'xmlrpc') { // how about SOAP?
954             if (empty($GLOBALS['HTTP_RAW_POST_DATA']))
955                 trigger_error("Wrong always_populate_raw_post_data = Off setting in your php.ini\nCannot use xmlrpc!", E_USER_ERROR);
956             // wiki.putPage has special otional userid/passwd arguments. check that later.
957             $userid = '';
958             if (isset($HTTP_SERVER_VARS['REMOTE_USER']))
959                 $userid = $HTTP_SERVER_VARS['REMOTE_USER'];
960             elseif (isset($HTTP_SERVER_VARS['REMOTE_ADDR']))
961                 $userid = $HTTP_SERVER_VARS['REMOTE_ADDR'];
962             elseif (isset($HTTP_ENV_VARS['REMOTE_ADDR']))
963                 $userid = $HTTP_ENV_VARS['REMOTE_ADDR'];
964             elseif (isset($GLOBALS['REMOTE_ADDR']))
965                 $userid = $GLOBALS['REMOTE_ADDR'];
966             return $userid;
967         }
968
969         return false;
970     }
971     
972     function _isActionPage ($pagename, $verbose = true) {
973         $dbi = $this->getDbh();
974         $page = $dbi->getPage($pagename);
975         if (!$page) return false;
976         $rev = $page->getCurrentRevision();
977         // FIXME: more restrictive check for sane plugin?
978         if (strstr($rev->getPackedContent(), '<?plugin'))
979             return true;
980         if ($verbose and !$rev->hasDefaultContents())
981             trigger_error("$pagename: Does not appear to be an 'action page'", E_USER_NOTICE);
982         return false;
983     }
984
985     function findActionPage ($action) {
986         static $cache;
987         if (!$action) return false;
988
989         // check for translated version, as per users preferred language
990         // (or system default in case it is not en)
991         $translation = gettext($action);
992
993         if (isset($cache) and isset($cache[$translation]))
994             return $cache[$translation];
995
996         // check for cached translated version
997         if ($translation and $this->_isActionPage($translation, false))
998             return $cache[$action] = $translation;
999
1000         // Allow for, e.g. action=LikePages
1001         if (!isWikiWord($action))
1002             return $cache[$action] = false;
1003
1004         // check for translated version (default language)
1005         global $LANG;
1006         if ($LANG != "en") {
1007             require_once("lib/WikiPlugin.php");
1008             require_once("lib/plugin/_WikiTranslation.php");
1009             $trans = new WikiPlugin__WikiTranslation();
1010             $trans->lang = $LANG;
1011             $default = $trans->translate_to_en($action, $LANG);
1012             if ($default and $this->_isActionPage($default, false))
1013                 return $cache[$action] = $default;
1014         } else {
1015             $default = $translation;
1016         }
1017         
1018         // check for english version
1019         if ($action != $translation and $action != $default) {
1020             if ($this->_isActionPage($action))
1021                 return $cache[$action] = $action;
1022         }
1023
1024         trigger_error("$action: Cannot find action page", E_USER_NOTICE);
1025         return $cache[$action] = false;
1026     }
1027     
1028     function isActionPage ($pagename) {
1029         return $this->findActionPage($pagename);
1030     }
1031
1032     function action_browse () {
1033         $this->buffer_output();
1034         include_once("lib/display.php");
1035         displayPage($this);
1036     }
1037
1038     function action_verify () {
1039         $this->action_browse();
1040     }
1041
1042     function actionpage ($action) {
1043         $this->buffer_output();
1044         include_once("lib/display.php");
1045         actionPage($this, $action);
1046     }
1047
1048     function adminActionSubpage ($subpage) {
1049         $page = _("PhpWikiAdministration")."/".$subpage;
1050         $action = $this->findActionPage($page);
1051         if ($action) {
1052             if (!$this->getArg('s'))
1053                 $this->setArg('s', $this->getArg('pagename'));
1054             $this->setArg('verify',1);
1055             if ($this->getArg('action') != 'rename')
1056                 $this->setArg('action',  $action);
1057             $this->actionpage($action);
1058         } else {
1059             trigger_error($page.": Cannot find action page", E_USER_WARNING);
1060         }
1061     }
1062
1063     function action_chown () {
1064         $this->adminActionSubpage(_("Chown"));
1065     }
1066
1067     function action_setacl () {
1068         $this->adminActionSubpage(_("SetAcl"));
1069     }
1070
1071     function action_rename () {
1072         $this->adminActionSubpage(_("Rename"));
1073     }
1074
1075     function action_dump () {
1076         $action = $this->findActionPage(_("PageDump"));
1077         if ($action) {
1078             $this->actionpage($action);
1079         } else {
1080             // redirect to action=upgrade if admin?
1081             trigger_error(_("PageDump").": Cannot find action page", E_USER_WARNING);
1082         }
1083     }
1084
1085     function action_diff () {
1086         $this->buffer_output();
1087         include_once "lib/diff.php";
1088         showDiff($this);
1089     }
1090
1091     function action_search () {
1092         // Decide between title or fulltextsearch (e.g. both buttons available).
1093         // Reformulate URL and redirect.
1094         $searchtype = $this->getArg('searchtype');
1095         $args = array('s' => $this->getArg('searchterm') 
1096                                ? $this->getArg('searchterm') 
1097                                : $this->getArg('s'));
1098         if ($searchtype == 'full' or $searchtype == 'fulltext') {
1099             $search_page = _("FullTextSearch");
1100         }
1101         elseif ($searchtype == 'external') {
1102             $s = $args['s'];
1103             $link = new WikiPageName("Search:$s"); // Expand interwiki url. I use xapian-omega
1104             $this->redirect($link->url);
1105         }
1106         else {
1107             $search_page = _("TitleSearch");
1108             $args['auto_redirect'] = 1;
1109         }
1110         $this->redirect(WikiURL($search_page, $args, 'absolute_url'));
1111     }
1112
1113     function action_edit () {
1114         $this->buffer_output();
1115         include "lib/editpage.php";
1116         $e = new PageEditor ($this);
1117         $e->editPage();
1118     }
1119
1120     function action_create () {
1121         $this->action_edit();
1122     }
1123     
1124     function action_viewsource () {
1125         $this->buffer_output();
1126         include "lib/editpage.php";
1127         $e = new PageEditor ($this);
1128         $e->viewSource();
1129     }
1130
1131     function action_lock () {
1132         $page = $this->getPage();
1133         $page->set('locked', true);
1134         $this->_dbi->touch();
1135         // check ModeratedPage hook
1136         if ($moderated = $page->get('moderation')) {
1137             require_once("lib/WikiPlugin.php");
1138             $plugin = WikiPluginLoader::getPlugin("ModeratedPage");
1139             if ($retval = $plugin->lock_check($this, $page, $moderated))
1140                 $this->setArg('errormsg', $retval);
1141         } 
1142         // check if a link to ModeratedPage exists
1143         elseif ($action_page = $page->existLink(_("ModeratedPage"))) {
1144             require_once("lib/WikiPlugin.php");
1145             $plugin = WikiPluginLoader::getPlugin("ModeratedPage");
1146             if ($retval = $plugin->lock_add($this, $page, $action_page))
1147                 $this->setArg('errormsg', $retval);
1148         }
1149         $this->action_browse();
1150     }
1151
1152     function action_unlock () {
1153         $page = $this->getPage();
1154         $page->set('locked', false);
1155         $this->_dbi->touch();
1156         $this->action_browse();
1157     }
1158
1159     function action_remove () {
1160         // This check is now redundant.
1161         //$user->requireAuth(WIKIAUTH_ADMIN);
1162         $pagename = $this->getArg('pagename');
1163         if (strstr($pagename, _("PhpWikiAdministration"))) {
1164             $this->action_browse();
1165         } else {
1166             include('lib/removepage.php');
1167             RemovePage($this);
1168         }
1169     }
1170
1171     function action_xmlrpc () {
1172         include_once("lib/XmlRpcServer.php");
1173         $xmlrpc = new XmlRpcServer($this);
1174         $xmlrpc->service();
1175     }
1176     
1177     function action_soap () {
1178         if (defined("WIKI_SOAP") and WIKI_SOAP) // already loaded
1179             return;
1180         /*
1181           allow VIRTUAL_PATH or action=soap SOAP access
1182          */
1183         include_once("SOAP.php");
1184     }
1185
1186     function action_revert () {
1187         include_once "lib/loadsave.php";
1188         RevertPage($this);
1189     }
1190
1191     function action_zip () {
1192         include_once("lib/loadsave.php");
1193         MakeWikiZip($this);
1194         // I don't think it hurts to add cruft at the end of the zip file.
1195         //echo "\n========================================================\n";
1196         //echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
1197     }
1198
1199     function action_ziphtml () {
1200         include_once("lib/loadsave.php");
1201         MakeWikiZipHtml($this);
1202         // I don't think it hurts to add cruft at the end of the zip file.
1203         echo "\n========================================================\n";
1204         echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
1205     }
1206
1207     function action_dumpserial () {
1208         include_once("lib/loadsave.php");
1209         DumpToDir($this);
1210     }
1211
1212     function action_dumphtml () {
1213         include_once("lib/loadsave.php");
1214         DumpHtmlToDir($this);
1215     }
1216
1217     function action_upload () {
1218         include_once("lib/loadsave.php");
1219         LoadPostFile($this);
1220     }
1221
1222     function action_upgrade () {
1223         include_once("lib/loadsave.php");
1224         include_once("lib/upgrade.php");
1225         DoUpgrade($this);
1226     }
1227
1228     function action_loadfile () {
1229         include_once("lib/loadsave.php");
1230         LoadFileOrDir($this);
1231     }
1232
1233     function action_pdf () {
1234         include_once("lib/pdf.php");
1235         ConvertAndDisplayPdf($this);
1236     }
1237
1238     function action_captcha () {
1239         include_once "lib/Captcha.php";
1240         $captcha = new Captcha();
1241         $captcha->image ( $captcha->captchaword() ); 
1242     }
1243     
1244     function action_wikitohtml () {
1245        include_once("lib/WysiwygEdit/Wikiwyg.php");
1246        $wikitohtml = new WikiToHtml( $this->getArg("content") , $this);
1247        $wikitohtml->send();
1248     }
1249
1250     function action_setpref () {
1251         $what = $this->getArg('pref');
1252         $value = $this->getArg('value');
1253         $prefs =& $this->_user->_prefs;
1254         $prefs->set($what, $value);
1255         $num = $this->_user->setPreferences($prefs);
1256     }
1257 }
1258
1259 //FIXME: deprecated with ENABLE_PAGEPERM (?)
1260 function is_safe_action ($action) {
1261     global $request;
1262     return $request->requiredAuthorityForAction($action) < WIKIAUTH_ADMIN;
1263 }
1264
1265 function validateSessionPath() {
1266     // Try to defer any session.save_path PHP errors before any html
1267     // is output, which causes some versions of IE to display a blank
1268     // page (due to its strict mode while parsing a page?).
1269     if (! is_writeable(ini_get('session.save_path'))) {
1270         $tmpdir = (defined('SESSION_SAVE_PATH') and SESSION_SAVE_PATH) ? SESSION_SAVE_PATH : '/tmp';
1271         if (!is_writeable($tmpdir))
1272             $tmpdir = '/tmp';
1273         trigger_error
1274             (sprintf(_("%s is not writable."),
1275                      _("The session.save_path directory"))
1276              . "\n"
1277              . sprintf(_("Please ensure that %s is writable, or redefine %s in config/config.ini."),
1278                        sprintf(_("the session.save_path directory '%s'"),
1279                                ini_get('session.save_path')),
1280                        'SESSION_SAVE_PATH')
1281              . "\n"
1282              . sprintf(_("Attempting to use the directory '%s' instead."),
1283                        $tmpdir)
1284              , E_USER_NOTICE);
1285         if (! is_writeable($tmpdir)) {
1286             trigger_error
1287                 (sprintf(_("%s is not writable."), $tmpdir)
1288                  . "\n"
1289                  . _("Users will not be able to sign in.")
1290                  , E_USER_NOTICE);
1291         }
1292         else
1293             @ini_set('session.save_path', $tmpdir);
1294     }
1295 }
1296
1297 function main () {
1298     if ( !USE_DB_SESSION )
1299         validateSessionPath();
1300
1301     global $request;
1302     if ((DEBUG & _DEBUG_APD) and extension_loaded("apd")) { 
1303         //apd_set_session_trace(9);
1304         apd_set_pprof_trace();
1305     }
1306
1307     // Postpone warnings
1308     global $ErrorManager;
1309     if (defined('E_STRICT')) // and (E_ALL & E_STRICT)) // strict php5?
1310         $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE|E_USER_WARNING|E_WARNING|E_STRICT);
1311     else
1312         $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE|E_USER_WARNING|E_WARNING);
1313     $request = new WikiRequest();
1314
1315     $action = $request->getArg('action');
1316     if (substr($action, 0, 3) != 'zip') {
1317         if ($action == 'pdf')
1318             $ErrorManager->setPostponedErrorMask(-1); // everything
1319         //else // reject postponing of warnings
1320         //    $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
1321     }
1322
1323     /*
1324      * Allow for disabling of markup cache.
1325      * (Mostly for debugging ... hopefully.)
1326      *
1327      * See also <?plugin WikiAdminUtils action=purge-cache ?>
1328      */
1329     if (!defined('WIKIDB_NOCACHE_MARKUP')) {
1330         if ($request->getArg('nocache')) // 1 or purge
1331             define('WIKIDB_NOCACHE_MARKUP', $request->getArg('nocache'));
1332         else
1333             define('WIKIDB_NOCACHE_MARKUP', false); // redundant, but explicit
1334     }
1335     
1336     // Initialize with system defaults in case user not logged in.
1337     // Should this go into the constructor?
1338     $request->initializeTheme('default');
1339     $request->updateAuthAndPrefs();
1340     $request->initializeLang();
1341     
1342     //FIXME:
1343     //if ($user->is_authenticated())
1344     //  $LogEntry->user = $user->getId();
1345
1346     // Memory optimization:
1347     // http://www.procata.com/blog/archives/2004/05/27/rephlux-and-php-memory-usage/
1348     // kill the global PEAR _PEAR_destructor_object_list
1349     if (!empty($_PEAR_destructor_object_list))
1350         $_PEAR_destructor_object_list = array();
1351     $request->possiblyDeflowerVirginWiki();
1352     
1353 // hack! define proper actions for these.
1354 //if (defined('WIKI_XMLRPC') and WIKI_XMLRPC) return;
1355 //if (defined('WIKI_SOAP')   and WIKI_SOAP)   return;
1356
1357     $validators = array('wikiname' => WIKI_NAME,
1358                         'args'     => wikihash($request->getArgs()),
1359                         'prefs'    => wikihash($request->getPrefs()));
1360     if (CACHE_CONTROL == 'STRICT') {
1361         $dbi = $request->getDbh();
1362         $timestamp = $dbi->getTimestamp();
1363         $validators['mtime'] = $timestamp;
1364         $validators['%mtime'] = (int)$timestamp;
1365     }
1366     // FIXME: we should try to generate strong validators when possible,
1367     // but for now, our validator is weak, since equal validators do not
1368     // indicate byte-level equality of content.  (Due to DEBUG timing output, etc...)
1369     //
1370     // (If DEBUG if off, this may be a strong validator, but I'm going
1371     // to go the paranoid route here pending further study and testing.)
1372     // access hits and edit stats in the footer violate strong ETags also. 
1373     if (1 or DEBUG) {
1374         $validators['%weak'] = true;
1375     }
1376     $request->setValidators($validators);
1377    
1378     $request->handleAction();
1379
1380     if (DEBUG and DEBUG & _DEBUG_INFO) phpinfo(INFO_VARIABLES | INFO_MODULES);
1381     $request->finish();
1382 }
1383
1384 //$x = error_reporting();  // DEBUG: why is it 1 here? should be E_ALL
1385 if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
1386     error_reporting(E_ALL & ~E_STRICT);         // exclude E_STRICT
1387 else
1388     error_reporting(E_ALL); // php4
1389 // don't run the main loop for special requests (test, getimg, xmlrpc, soap, ...)
1390 if (!defined('PHPWIKI_NOMAIN') or !PHPWIKI_NOMAIN)
1391     main();
1392
1393
1394 // $Log: not supported by cvs2svn $
1395 // Revision 1.242  2008/02/14 18:27:49  rurban
1396 // signin fixes for !ENABLE_USER_NEW (to overcome php-5.2 recursion login
1397 // problems)
1398 //
1399 // Revision 1.241  2007/09/22 12:39:32  rurban
1400 // fix unknown variable WikiTheme
1401 //
1402 // Revision 1.240  2007/09/19 18:02:12  rurban
1403 // htmldump optimization: continue dump on access denied
1404 //
1405 // Revision 1.239  2007/09/12 19:41:01  rurban
1406 // revise INSECURE_ACTIONS_LOCALHOST_ONLY actions
1407 //
1408 // Revision 1.238  2007/09/01 13:24:23  rurban
1409 // add INSECURE_ACTIONS_LOCALHOST_ONLY. advanced security settings
1410 //
1411 // Revision 1.237  2007/08/25 18:03:34  rurban
1412 // change rename action from access perm change to edit: allow the signed in user to rename.
1413 //
1414 // Revision 1.236  2007/07/21 18:08:49  rurban
1415 // more searchtypes
1416 //
1417 // Revision 1.235  2007/07/14 12:04:19  rurban
1418 // support searchtype=external (mediawiki like search buttons: Text, Title, External)
1419 //
1420 // Revision 1.234  2007/07/01 09:36:10  rurban
1421 // themes are now easier derivable classes from other themes.
1422 // removed global code setters, switched to $WikiTheme->load() in main
1423 //
1424 // Revision 1.233  2007/06/02 21:07:21  rurban
1425 // _isActionPage ($pagename, $verbose = true)
1426 //
1427 // Revision 1.232  2007/05/13 18:13:20  rurban
1428 // improve prefs: only save with userid
1429 //
1430 // Revision 1.231  2007/02/17 14:16:44  rurban
1431 // action_soap, action_setpref, anon perms for wikitohtml, setpref
1432 //
1433 // Revision 1.230  2007/01/27 21:52:15  rurban
1434 // Improved login header for !ALLOW_ANON_USER
1435 //
1436 // Revision 1.229  2007/01/07 18:44:30  rurban
1437 // Fix typo for moderation
1438 //
1439 // Revision 1.228  2007/01/02 13:22:17  rurban
1440 // allow application/xml for xmlrpc detection: acdropdown uses this type. silence findActionPage warnings
1441 //
1442 // Revision 1.227  2006/12/22 17:53:55  rurban
1443 // Remove action from edited url
1444 // move wikitohtml to lib/WysiwygEdit/Wikiwyg.php
1445 //
1446 // Revision 1.226  2006/09/06 06:01:45  rurban
1447 // minor cleanup
1448 //
1449 // Revision 1.225  2006/05/31 19:59:57  jeannicolas
1450 //
1451 //
1452 // Added wysiwyg_editor 1.1b
1453 //
1454 // Revision 1.224  2006/05/13 19:59:55  rurban
1455 // added wysiwyg_editor-1.3a feature by Jean-Nicolas GEREONE <jean-nicolas.gereone@st.com>
1456 // converted wysiwyg_editor-1.3a js to WysiwygEdit framework
1457 // changed default ENABLE_WYSIWYG = true and added WYSIWYG_BACKEND = Wikiwyg
1458 //
1459 // Revision 1.223  2006/03/19 15:01:00  rurban
1460 // sf.net patch #1333957 by Matt Brown: Authentication cookie identical across all wikis on a host
1461 //
1462 // Revision 1.222  2006/03/19 14:53:12  rurban
1463 // sf.net patch #1438392 by Matt Brown: Bogo Login is broken when ENABLE_PAGEPERM=false
1464 //
1465 // Revision 1.221  2006/03/19 14:23:51  rurban
1466 // sf.net patch #1377011 by Matt Brown: add DATABASE_OPTIMISE_FREQUENCY
1467 //
1468 // Revision 1.220  2006/03/07 21:04:15  rurban
1469 // wikihash for php-5.1
1470 //
1471 // Revision 1.219  2005/10/30 14:20:42  rurban
1472 // move Captcha specific vars and methods into a Captcha object
1473 // randomize Captcha chars positions and angles (smoothly)
1474 //
1475 // Revision 1.218  2005/10/29 14:18:06  rurban
1476 // fix typo
1477 //
1478 // Revision 1.217  2005/09/18 12:44:00  rurban
1479 // novatrope patch to let only _AUTHENTICATED view pages
1480 //
1481 // Revision 1.216  2005/08/27 09:40:46  rurban
1482 // fix login with HttpAuth
1483 //
1484 // Revision 1.215  2005/08/07 10:50:27  rurban
1485 // postpone guard
1486 //
1487 // Revision 1.214  2005/08/07 09:14:03  rurban
1488 // fix cookie logout; let the WIKI_ID cookie get deleted
1489 //
1490 // Revision 1.213  2005/06/10 06:10:35  rurban
1491 // ensure Update Preferences gets through
1492 //
1493 // Revision 1.212  2005/04/25 20:17:14  rurban
1494 // captcha feature by Benjamin Drieu. Patch #1110699
1495 //
1496 // Revision 1.211  2005/04/11 19:42:54  rurban
1497 // reformatting, SESSION_SAVE_PATH check
1498 //
1499 // Revision 1.210  2005/04/07 06:06:34  rurban
1500 // add _SERVER[REMOTE_USER] check for pubcookie et al, Bug #1177259 (iamjpr)
1501 //
1502 // Revision 1.209  2005/04/06 06:19:30  rurban
1503 // Revert the previous wrong bugfix #1175761: USECACHE was mixed with WIKIDB_NOCACHE_MARKUP.
1504 // Fix WIKIDB_NOCACHE_MARKUP in main (always set it) and clarify it in WikiDB
1505 //
1506 // Revision 1.208  2005/02/28 21:24:32  rurban
1507 // ignore forbidden ini_set warnings. Bug #1117254 by Xavier Roche
1508 //
1509 // Revision 1.207  2005/02/10 19:03:37  rurban
1510 // try to avoid duoplicate lang/theme init
1511 //
1512 // Revision 1.206  2005/02/04 11:30:10  rurban
1513 // remove old comments
1514 //
1515 // Revision 1.205  2005/01/29 20:41:47  rurban
1516 // some minor php5 strictness fixes
1517 //
1518 // Revision 1.204  2005/01/25 07:35:42  rurban
1519 // add TODO comment
1520 //
1521 // Revision 1.203  2005/01/21 14:11:23  rurban
1522 // better moderation class tag
1523 //
1524 // Revision 1.202  2005/01/21 12:02:32  rurban
1525 // deduce username for xmlrpc also
1526 //
1527 // Revision 1.201  2005/01/20 10:18:17  rurban
1528 // reformatting
1529 //
1530 // Revision 1.200  2004/12/26 17:08:36  rurban
1531 // php5 fixes: case-sensitivity, no & new
1532 //
1533 // Revision 1.199  2004/12/19 00:58:01  rurban
1534 // Enforce PASSWORD_LENGTH_MINIMUM in almost all PassUser checks,
1535 // Provide an errormessage if so. Just PersonalPage and BogoLogin not.
1536 // Simplify httpauth logout handling and set sessions for all methods.
1537 // fix main.php unknown index "x" getLevelDescription() warning.
1538 //
1539 // Revision 1.198  2004/12/17 16:49:51  rurban
1540 // avoid Invalid username message on Sign In button click
1541 //
1542 // Revision 1.197  2004/12/17 16:39:55  rurban
1543 // enable sessions for HttpAuth
1544 //
1545 // Revision 1.196  2004/12/10 02:36:43  rurban
1546 // More help with the new native xmlrpc lib. no warnings, no user cookie on xmlrpc.
1547 //
1548 // Revision 1.195  2004/12/09 22:24:44  rurban
1549 // optimize on _DEBUG_SQL only. but now again on every 50th request, not just save.
1550 //
1551 // Revision 1.194  2004/11/30 17:46:49  rurban
1552 // added ModeratedPage POST action hook (part 2/3)
1553 //
1554 // Revision 1.193  2004/11/30 07:51:08  rurban
1555 // fixed SESSION_SAVE_PATH warning msg
1556 //
1557 // Revision 1.192  2004/11/21 11:59:20  rurban
1558 // remove final \n to be ob_cache independent
1559 //
1560 // Revision 1.191  2004/11/19 19:22:03  rurban
1561 // ModeratePage part1: change status
1562 //
1563 // Revision 1.190  2004/11/15 15:56:40  rurban
1564 // don't load PagePerm on ENABLE_PAGEPERM = false to save memory. Move mayAccessPage() to main.php
1565 //
1566 // Revision 1.189  2004/11/09 17:11:16  rurban
1567 // * revert to the wikidb ref passing. there's no memory abuse there.
1568 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
1569 //   store page ids with getPageLinks (GleanDescription) of all existing pages, which
1570 //   are also needed at the rendering for linkExistingWikiWord().
1571 //   pass options to pageiterator.
1572 //   use this cache also for _get_pageid()
1573 //   This saves about 8 SELECT count per page (num all pagelinks).
1574 // * fix passing of all page fields to the pageiterator.
1575 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
1576 //
1577 // Revision 1.188  2004/11/07 16:02:52  rurban
1578 // new sql access log (for spam prevention), and restructured access log class
1579 // dbh->quote (generic)
1580 // pear_db: mysql specific parts seperated (using replace)
1581 //
1582 // Revision 1.187  2004/11/05 22:08:52  rurban
1583 // Ok: Fix loading all required userclasses beforehand. This is much slower than before but safes a few bytes RAM
1584 //
1585 // Revision 1.186  2004/11/05 20:53:35  rurban
1586 // login cleanup: better debug msg on failing login,
1587 // checked password less immediate login (bogo or anon),
1588 // checked olduser pref session error,
1589 // better PersonalPage without password warning on minimal password length=0
1590 //   (which is default now)
1591 //
1592 // Revision 1.185  2004/11/01 13:55:05  rurban
1593 // fix against switching user new/old between sessions
1594 //
1595 // Revision 1.184  2004/11/01 10:43:57  rurban
1596 // seperate PassUser methods into seperate dir (memory usage)
1597 // fix WikiUser (old) overlarge data session
1598 // remove wikidb arg from various page class methods, use global ->_dbi instead
1599 // ...
1600 //
1601 // Revision 1.183  2004/10/14 19:23:58  rurban
1602 // remove debugging prints
1603 //
1604 // Revision 1.182  2004/10/12 13:13:19  rurban
1605 // php5 compatibility (5.0.1 ok)
1606 //
1607 // Revision 1.181  2004/10/07 16:08:58  rurban
1608 // fixed broken FileUser session handling.
1609 //   thanks to Arnaud Fontaine for detecting this.
1610 // enable file user Administrator membership.
1611 //
1612 // Revision 1.180  2004/10/04 23:39:34  rurban
1613 // just aesthetics
1614 //
1615 // Revision 1.179  2004/09/25 18:57:42  rurban
1616 // better ACL error message: view not browse, change not setacl, ...
1617 //
1618 // Revision 1.178  2004/09/25 16:27:36  rurban
1619 // better not allowed description: on global disallowed, and on missing pageperms
1620 //
1621 // Revision 1.177  2004/09/14 10:31:09  rurban
1622 // 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
1623 //
1624 // Revision 1.176  2004/08/05 17:33:22  rurban
1625 // aesthetic typo
1626 //
1627 // Revision 1.175  2004/07/13 13:08:25  rurban
1628 // fix PEAR memory waste issues
1629 //
1630 // Revision 1.174  2004/07/08 13:50:32  rurban
1631 // various unit test fixes: print error backtrace on _DEBUG_TRACE; allusers fix; new PHPWIKI_NOMAIN constant for omitting the mainloop
1632 //
1633 // Revision 1.173  2004/07/05 12:57:54  rurban
1634 // add mysql timeout
1635 //
1636 // Revision 1.172  2004/07/03 08:04:19  rurban
1637 // fixed implicit PersonalPage login (e.g. on edit), fixed to check against create ACL on create, not edit
1638 //
1639 // Revision 1.171  2004/06/29 09:30:42  rurban
1640 // force string hash
1641 //
1642 // Revision 1.170  2004/06/25 14:29:20  rurban
1643 // WikiGroup refactoring:
1644 //   global group attached to user, code for not_current user.
1645 //   improved helpers for special groups (avoid double invocations)
1646 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
1647 // fixed a XHTML validation error on userprefs.tmpl
1648 //
1649 // Revision 1.169  2004/06/20 14:42:54  rurban
1650 // various php5 fixes (still broken at blockparser)
1651 //
1652 // Revision 1.168  2004/06/17 10:39:18  rurban
1653 // fix reverse translation of possible actionpage
1654 //
1655 // Revision 1.167  2004/06/16 13:21:16  rurban
1656 // stabilize on failing ldap queries or bind
1657 //
1658 // Revision 1.166  2004/06/15 09:15:52  rurban
1659 // IMPORTANT: fixed passwd handling for passwords stored in prefs:
1660 //   fix encrypted usage, actually store and retrieve them from db
1661 //   fix bogologin with passwd set.
1662 // fix php crashes with call-time pass-by-reference (references wrongly used
1663 //   in declaration AND call). This affected mainly Apache2 and IIS.
1664 //   (Thanks to John Cole to detect this!)
1665 //
1666 // Revision 1.165  2004/06/14 11:31:37  rurban
1667 // renamed global $Theme to $WikiTheme (gforge nameclash)
1668 // inherit PageList default options from PageList
1669 //   default sortby=pagename
1670 // use options in PageList_Selectable (limit, sortby, ...)
1671 // added action revert, with button at action=diff
1672 // added option regex to WikiAdminSearchReplace
1673 //
1674 // Revision 1.164  2004/06/13 13:54:25  rurban
1675 // Catch fatals on the four dump calls (as file and zip, as html and mimified)
1676 // FoafViewer: Check against external requirements, instead of fatal.
1677 // Change output for xhtmldumps: using file:// urls to the local fs.
1678 // Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
1679 // Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
1680 //
1681 // Revision 1.163  2004/06/13 11:35:32  rurban
1682 // check for create action on action=edit not to fool PagePerm checks
1683 //
1684 // Revision 1.162  2004/06/08 10:05:11  rurban
1685 // simplified admin action shortcuts
1686 //
1687 // Revision 1.161  2004/06/07 22:58:40  rurban
1688 // simplified chown, setacl, dump actions
1689 //
1690 // Revision 1.160  2004/06/07 22:44:14  rurban
1691 // added simplified chown, setacl actions
1692 //
1693 // Revision 1.159  2004/06/06 16:58:51  rurban
1694 // added more required ActionPages for foreign languages
1695 // install now english ActionPages if no localized are found. (again)
1696 // fixed default anon user level to be 0, instead of -1
1697 //   (wrong "required administrator to view this page"...)
1698 //
1699 // Revision 1.158  2004/06/04 20:32:53  rurban
1700 // Several locale related improvements suggested by Pierrick Meignen
1701 // LDAP fix by John Cole
1702 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
1703 //
1704 // Revision 1.157  2004/06/04 12:40:21  rurban
1705 // Restrict valid usernames to prevent from attacks against external auth or compromise
1706 // possible holes.
1707 // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
1708 // Fxied more warnings
1709 //
1710 // Revision 1.156  2004/06/03 17:58:16  rurban
1711 // support immediate LANG and THEME switch inside a session
1712 //
1713 // Revision 1.155  2004/06/03 10:18:19  rurban
1714 // fix FileUser locking issues, new config ENABLE_PAGEPERM
1715 //
1716 // Revision 1.154  2004/06/02 18:01:46  rurban
1717 // init global FileFinder to add proper include paths at startup
1718 //   adds PHPWIKI_DIR if started from another dir, lib/pear also
1719 // fix slashify for Windows
1720 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
1721 //
1722 // Revision 1.153  2004/06/01 15:28:00  rurban
1723 // AdminUser only ADMIN_USER not member of Administrators
1724 // some RateIt improvements by dfrankow
1725 // edit_toolbar buttons
1726 //
1727 // Revision 1.152  2004/05/27 17:49:06  rurban
1728 // renamed DB_Session to DbSession (in CVS also)
1729 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
1730 // remove leading slash in error message
1731 // added force_unlock parameter to File_Passwd (no return on stale locks)
1732 // fixed adodb session AffectedRows
1733 // added FileFinder helpers to unify local filenames and DATA_PATH names
1734 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
1735 //
1736 // Revision 1.151  2004/05/25 12:40:48  rurban
1737 // trim the pagename
1738 //
1739 // Revision 1.150  2004/05/25 10:18:44  rurban
1740 // Check for UTF-8 URLs; Internet Explorer produces these if you
1741 // type non-ASCII chars in the URL bar or follow unescaped links.
1742 // Fixes sf.net bug #953949
1743 // src: languages/Language.php:checkTitleEncoding() from mediawiki
1744 //
1745 // Revision 1.149  2004/05/18 13:31:19  rurban
1746 // hold warnings until headers are sent. new Error-style with collapsed output of repeated messages
1747 //
1748 // Revision 1.148  2004/05/17 17:43:29  rurban
1749 // CGI: no PATH_INFO fix
1750 //
1751 // Revision 1.147  2004/05/15 19:48:33  rurban
1752 // fix some too loose PagePerms for signed, but not authenticated users
1753 //  (admin, owner, creator)
1754 // no double login page header, better login msg.
1755 // moved action_pdf to lib/pdf.php
1756 //
1757 // Revision 1.146  2004/05/15 18:31:01  rurban
1758 // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
1759 //
1760 // Revision 1.145  2004/05/12 10:49:55  rurban
1761 // require_once fix for those libs which are loaded before FileFinder and
1762 //   its automatic include_path fix, and where require_once doesn't grok
1763 //   dirname(__FILE__) != './lib'
1764 // upgrade fix with PearDB
1765 // navbar.tmpl: remove spaces for IE &nbsp; button alignment
1766 //
1767 // Revision 1.144  2004/05/06 19:26:16  rurban
1768 // improve stability, trying to find the InlineParser endless loop on sf.net
1769 //
1770 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
1771 //
1772 // Revision 1.143  2004/05/06 17:30:38  rurban
1773 // CategoryGroup: oops, dos2unix eol
1774 // improved phpwiki_version:
1775 //   pre -= .0001 (1.3.10pre: 1030.099)
1776 //   -p1 += .001 (1.3.9-p1: 1030.091)
1777 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
1778 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
1779 //   backend->backendType(), backend->database(),
1780 //   backend->listOfFields(),
1781 //   backend->listOfTables(),
1782 //
1783 // Revision 1.142  2004/05/04 22:34:25  rurban
1784 // more pdf support
1785 //
1786 // Revision 1.141  2004/05/03 13:16:47  rurban
1787 // fixed UserPreferences update, esp for boolean and int
1788 //
1789 // Revision 1.140  2004/05/02 21:26:38  rurban
1790 // limit user session data (HomePageHandle and auth_dbi have to invalidated anyway)
1791 //   because they will not survive db sessions, if too large.
1792 // extended action=upgrade
1793 // some WikiTranslation button work
1794 // revert WIKIAUTH_UNOBTAINABLE (need it for main.php)
1795 // some temp. session debug statements
1796 //
1797 // Revision 1.139  2004/05/02 15:10:07  rurban
1798 // new finally reliable way to detect if /index.php is called directly
1799 //   and if to include lib/main.php
1800 // new global AllActionPages
1801 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
1802 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
1803 // PageGroupTestOne => subpages
1804 // renamed PhpWikiRss to PhpWikiRecentChanges
1805 // more docs, default configs, ...
1806 //
1807 // Revision 1.138  2004/05/01 15:59:29  rurban
1808 // more php-4.0.6 compatibility: superglobals
1809 //
1810 // Revision 1.137  2004/04/29 19:39:44  rurban
1811 // special support for formatted plugins (one-liners)
1812 //   like <small><plugin BlaBla ></small>
1813 // iter->asArray() helper for PopularNearby
1814 // db_session for older php's (no &func() allowed)
1815 //
1816 // Revision 1.136  2004/04/29 17:18:19  zorloc
1817 // Fixes permission failure issues.  With PagePermissions and Disabled
1818 // Actions when user did not have permission WIKIAUTH_FORBIDDEN was
1819 // returned.  In WikiUser this was ok because WIKIAUTH_FORBIDDEN had a
1820 // value of 11 -- thus no user could perform that action.  But
1821 // WikiUserNew has a WIKIAUTH_FORBIDDEN value of -1 -- thus a user
1822 // without sufficent permission to do anything.  The solution is a new
1823 // high value permission level (WIKIAUTH_UNOBTAINABLE) to be the
1824 // default level for access failure.
1825 //
1826 // Revision 1.135  2004/04/26 12:15:01  rurban
1827 // check default config values
1828 //
1829 // Revision 1.134  2004/04/23 06:46:37  zorloc
1830 // Leave DB connection open when USE_DB_SESSION is true so that session info can be written to the DB.
1831 //
1832 // Revision 1.133  2004/04/20 18:10:31  rurban
1833 // config refactoring:
1834 //   FileFinder is needed for WikiFarm scripts calling index.php
1835 //   config run-time calls moved to lib/IniConfig.php:fix_configs()
1836 //   added PHPWIKI_DIR smart-detection code (Theme finder)
1837 //   moved FileFind to lib/FileFinder.php
1838 //   cleaned lib/config.php
1839 //
1840 // Revision 1.132  2004/04/19 21:51:41  rurban
1841 // php5 compatibility: it works!
1842 //
1843 // Revision 1.131  2004/04/19 18:27:45  rurban
1844 // Prevent from some PHP5 warnings (ref args, no :: object init)
1845 //   php5 runs now through, just one wrong XmlElement object init missing
1846 // Removed unneccesary UpgradeUser lines
1847 // Changed WikiLink to omit version if current (RecentChanges)
1848 //
1849 // Revision 1.130  2004/04/18 00:25:53  rurban
1850 // allow "0" pagename
1851 //
1852 // Revision 1.129  2004/04/07 23:13:19  rurban
1853 // fixed pear/File_Passwd for Windows
1854 // fixed FilePassUser sessions (filehandle revive) and password update
1855 //
1856 // Revision 1.128  2004/04/02 15:06:55  rurban
1857 // fixed a nasty ADODB_mysql session update bug
1858 // improved UserPreferences layout (tabled hints)
1859 // fixed UserPreferences auth handling
1860 // improved auth stability
1861 // improved old cookie handling: fixed deletion of old cookies with paths
1862 //
1863 // Revision 1.127  2004/03/25 17:00:31  rurban
1864 // more code to convert old-style pref array to new hash
1865 //
1866 // Revision 1.126  2004/03/24 19:39:03  rurban
1867 // php5 workaround code (plus some interim debugging code in XmlElement)
1868 //   php5 doesn't work yet with the current XmlElement class constructors,
1869 //   WikiUserNew does work better than php4.
1870 // rewrote WikiUserNew user upgrading to ease php5 update
1871 // fixed pref handling in WikiUserNew
1872 // added Email Notification
1873 // added simple Email verification
1874 // removed emailVerify userpref subclass: just a email property
1875 // changed pref binary storage layout: numarray => hash of non default values
1876 // print optimize message only if really done.
1877 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1878 //   prefs should be stored in db or homepage, besides the current session.
1879 //
1880 // Revision 1.125  2004/03/14 16:30:52  rurban
1881 // db-handle session revivification, dba fixes
1882 //
1883 // Revision 1.124  2004/03/12 15:48:07  rurban
1884 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
1885 // simplified lib/stdlib.php:explodePageList
1886 //
1887 // Revision 1.123  2004/03/10 15:41:27  rurban
1888 // use default pref mysql table
1889 //
1890 // Revision 1.122  2004/03/08 18:17:09  rurban
1891 // added more WikiGroup::getMembersOf methods, esp. for special groups
1892 // fixed $LDAP_SET_OPTIONS
1893 // fixed _AuthInfo group methods
1894 //
1895 // Revision 1.121  2004/03/01 13:48:45  rurban
1896 // rename fix
1897 // p[] consistency fix
1898 //
1899 // Revision 1.120  2004/03/01 10:22:41  rurban
1900 // initializeTheme optimize
1901 //
1902 // Revision 1.119  2004/02/26 20:45:06  rurban
1903 // check for ALLOW_ANON_USER = false
1904 //
1905 // Revision 1.118  2004/02/26 01:32:03  rurban
1906 // fixed session login with old WikiUser object. 
1907 // strangely, the errormask gets corrupted to 1, Pear???
1908 //
1909 // Revision 1.117  2004/02/24 17:19:37  rurban
1910 // debugging helpers only
1911 //
1912 // Revision 1.116  2004/02/24 15:17:14  rurban
1913 // improved auth errors with individual pages. the fact that you may
1914 // not browse a certain admin page does not conclude that you may not
1915 // browse the whole wiki. renamed browse => view
1916 //
1917 // Revision 1.115  2004/02/15 21:34:37  rurban
1918 // PageList enhanced and improved.
1919 // fixed new WikiAdmin... plugins
1920 // editpage, Theme with exp. htmlarea framework
1921 //   (htmlarea yet committed, this is really questionable)
1922 // WikiUser... code with better session handling for prefs
1923 // enhanced UserPreferences (again)
1924 // RecentChanges for show_deleted: how should pages be deleted then?
1925 //
1926 // Revision 1.114  2004/02/15 17:30:13  rurban
1927 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
1928 // fixed getPreferences() (esp. from sessions)
1929 // fixed setPreferences() (update and set),
1930 // fixed AdoDb DB statements,
1931 // update prefs only at UserPreferences POST (for testing)
1932 // unified db prefs methods (but in external pref classes yet)
1933 //
1934 // Revision 1.113  2004/02/12 13:05:49  rurban
1935 // Rename functional for PearDB backend
1936 // some other minor changes
1937 // SiteMap comes with a not yet functional feature request: includepages (tbd)
1938 //
1939 // Revision 1.112  2004/02/09 03:58:12  rurban
1940 // for now default DB_SESSION to false
1941 // PagePerm:
1942 //   * not existing perms will now query the parent, and not
1943 //     return the default perm
1944 //   * added pagePermissions func which returns the object per page
1945 //   * added getAccessDescription
1946 // WikiUserNew:
1947 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
1948 //   * force init of authdbh in the 2 db classes
1949 // main:
1950 //   * fixed session handling (not triple auth request anymore)
1951 //   * don't store cookie prefs with sessions
1952 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
1953 //
1954 // Revision 1.111  2004/02/07 10:41:25  rurban
1955 // fixed auth from session (still double code but works)
1956 // fixed GroupDB
1957 // fixed DbPassUser upgrade and policy=old
1958 // added GroupLdap
1959 //
1960 // Revision 1.110  2004/02/03 09:45:39  rurban
1961 // LDAP cleanup, start of new Pref classes
1962 //
1963 // Revision 1.109  2004/01/30 19:57:58  rurban
1964 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
1965 //
1966 // Revision 1.108  2004/01/28 14:34:14  rurban
1967 // session table takes the common prefix
1968 // + various minor stuff
1969 // reallow password changing
1970 //
1971 // Revision 1.107  2004/01/27 23:23:39  rurban
1972 // renamed ->Username => _userid for consistency
1973 // renamed mayCheckPassword => mayCheckPass
1974 // fixed recursion problem in WikiUserNew
1975 // fixed bogo login (but not quite 100% ready yet, password storage)
1976 //
1977 // Revision 1.106  2004/01/26 09:17:49  rurban
1978 // * changed stored pref representation as before.
1979 //   the array of objects is 1) bigger and 2)
1980 //   less portable. If we would import packed pref
1981 //   objects and the object definition was changed, PHP would fail.
1982 //   This doesn't happen with an simple array of non-default values.
1983 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1984 //   understands the interim format of array of objects also.
1985 // * simplified $prefs->get() and fixed $prefs->set()
1986 // * added $user->_userid and class '_WikiUser' portability functions
1987 // * fixed $user object ->_level upgrading, mostly using sessions.
1988 //   this fixes yesterdays problems with loosing authorization level.
1989 // * fixed WikiUserNew::checkPass to return the _level
1990 // * fixed WikiUserNew::isSignedIn
1991 // * added explodePageList to class PageList, support sortby arg
1992 // * fixed UserPreferences for WikiUserNew
1993 // * fixed WikiPlugin for empty defaults array
1994 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1995 //   removed sort arg, support sortby arg
1996 //
1997 // Revision 1.105  2004/01/25 03:57:15  rurban
1998 // WikiUserNew support (temp. ENABLE_USER_NEW constant)
1999 //
2000 // Revision 1.104  2003/12/26 06:41:16  carstenklapp
2001 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
2002 // so they don't prevent IE from partially (or not at all) rendering the
2003 // page. This should help a little for the IE user who encounters trouble
2004 // when setting up a new PhpWiki for the first time.
2005 //
2006 // Revision 1.103  2003/12/02 00:10:00  carstenklapp
2007 // Bugfix: Ongoing work to untangle UserPreferences/WikiUser/request code
2008 // mess: UserPreferences should take effect immediately now upon signing
2009 // in.
2010 //
2011 // Revision 1.102  2003/11/25 22:55:32  carstenklapp
2012 // Localization bugfix: For wikis where English is not the default system
2013 // language, make sure that the authority error message (i.e. "You must
2014 // sign in to edit pages in this wiki" etc.) is displayed in the wiki's
2015 // default language. Previously it would always display in English.
2016 // (Added call to update_locale() before displaying any messages prior to
2017 // the login prompt.)
2018 //
2019 // Revision 1.101  2003/11/25 21:49:44  carstenklapp
2020 // Bugfix: For a non-english wiki or when the user's preference is not
2021 // english, the wiki would always use the english ActionPage first if it
2022 // was present rather than the appropriate localised variant. (PhpWikis
2023 // running only in english or Wikis running ONLY without any english
2024 // ActionPages would not notice this bug, only when both english and
2025 // localised ActionPages were in the DB.) Now we check for the localised
2026 // variant first.
2027 //
2028 // Revision 1.100  2003/11/18 16:54:18  carstenklapp
2029 // Reformatting only: Tabs to spaces, added rcs log.
2030 //
2031
2032
2033 // Local Variables:
2034 // mode: php
2035 // tab-width: 8
2036 // c-basic-offset: 4
2037 // c-hanging-comment-ender-p: nil
2038 // indent-tabs-mode: nil
2039 // End:
2040 ?>