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