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