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