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