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