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