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