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