]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/main.php
php5 workaround code (plus some interim debugging code in XmlElement)
[SourceForge/phpwiki.git] / lib / main.php
1 <?php //-*-php-*-
2 rcs_id('$Id: main.php,v 1.126 2004-03-24 19:39:03 rurban Exp $');
3
4 define ('USE_PREFS_IN_PAGE', true);
5
6 include "lib/config.php";
7 require_once("lib/stdlib.php");
8 require_once('lib/Request.php');
9 require_once('lib/WikiDB.php');
10 if (ENABLE_USER_NEW)
11     require_once("lib/WikiUserNew.php");
12 else
13     require_once("lib/WikiUser.php");
14 require_once("lib/WikiGroup.php");
15 require_once("lib/PagePerm.php");
16
17 class WikiRequest extends Request {
18     // var $_dbi;
19
20     function WikiRequest () {
21         $this->_dbi = WikiDB::open($GLOBALS['DBParams']);
22         if (USE_DB_SESSION) {
23             include_once('lib/DB_Session.php');
24             $prefix = isset($GLOBALS['DBParams']['prefix']) ? $GLOBALS['DBParams']['prefix'] : '';
25             $this->_dbsession = & new DB_Session($this->getDbh(),
26                                                  $prefix . $GLOBALS['DBParams']['db_session_table']);
27         }
28         // Fixme: Does pear reset the error mask to 1? We have to find the culprit
29         $x = error_reporting();
30         
31         $this->Request();
32
33         // Normalize args...
34         $this->setArg('pagename', $this->_deducePagename());
35         $this->setArg('action', $this->_deduceAction());
36
37         // Restore auth state. This doesn't check for proper authorization!
38         if (ENABLE_USER_NEW) {
39             $userid = $this->_deduceUsername(); 
40             if (isset($this->_user) and $this->_user->_authhow == 'session') {
41                 // users might switch in a session between the two objects.
42                 // restore old auth level here or in updateAuthAndPrefs?
43                 //$user = $this->getSessionVar('wiki_user');
44                 // revive db handle, because these don't survive sessions
45                 unset($this->_user->_HomePagehandle);
46                 $this->_user->hasHomePage();
47                 /*
48                 if (!isa($user,WikiUserClassname()) or empty($this->_user->_level)) {
49                     $user = UpgradeUser($this->_user,$user);
50                 }
51                 */
52                 $this->_prefs = & $this->_user->_prefs;
53             } else {
54                 $user = WikiUser($userid);
55                 //Todo: upgrade later at updateAuthAndPrefs()
56                 if (isset($this->_user)) 
57                   $user = UpgradeUser($this->_user,$user);
58                 $this->_user = $user;
59                 $this->_prefs = & $this->_user->_prefs;
60             }
61         } else {
62             $this->_user = new WikiUser($this, $this->_deduceUsername());
63             $this->_prefs = $this->_user->getPreferences();
64         }
65     }
66
67     function initializeLang () {
68         if ($user_lang = $this->getPref('lang')) {
69             //trigger_error("DEBUG: initializeLang() ". $user_lang ." calling update_locale()...");
70             update_locale($user_lang);
71             FindLocalizedButtonFile(".",'missing_ok','reinit');
72         }
73     }
74
75     function initializeTheme () {
76         global $Theme;
77
78         // Load theme
79         if ($user_theme = $this->getPref('theme'))
80             include_once("themes/$user_theme/themeinfo.php");
81         if (empty($Theme) and defined ('THEME'))
82             include_once("themes/" . THEME . "/themeinfo.php");
83         if (empty($Theme))
84             include_once("themes/default/themeinfo.php");
85         assert(!empty($Theme));
86     }
87
88     // This really maybe should be part of the constructor, but since it
89     // may involve HTML/template output, the global $request really needs
90     // to be initialized before we do this stuff.
91     function updateAuthAndPrefs () {
92
93         // Handle authentication request, if any.
94         if ($auth_args = $this->getArg('auth')) {
95             $this->setArg('auth', false);
96             $this->_handleAuthRequest($auth_args); // possible NORETURN
97         }
98         elseif ( ! $this->_user or ! $this->_user->isSignedIn() ) {
99             // If not auth request, try to sign in as saved user.
100             if (($saved_user = $this->getPref('userid')) != false) {
101                 $this->_signIn($saved_user);
102             }
103         }
104
105         // Save preferences in session and cookie
106         if (isset($this->_user) and 
107             (!isset($this->_user->_authhow) or $this->_user->_authhow != 'session')) {
108             $id_only = true; 
109             $this->_user->setPreferences($this->_prefs, $id_only);
110         } else {
111             $this->setSessionVar('wiki_user', $this->_user);
112             //$this->setSessionVar('wiki_prefs', $this->_prefs);
113         }
114
115         // Ensure user has permissions for action
116         $require_level = $this->requiredAuthority($this->getArg('action'));
117         if (! $this->_user->hasAuthority($require_level))
118             $this->_notAuthorized($require_level); // NORETURN
119     }
120
121     function getUser () {
122         return $this->_user;
123     }
124
125     function getPrefs () {
126         return $this->_prefs;
127     }
128
129     // Convenience function:
130     function getPref ($key) {
131         if (isset($this->_prefs))
132             return $this->_prefs->get($key);
133     }
134
135     function getDbh () {
136         return $this->_dbi;
137     }
138
139     /**
140      * Get requested page from the page database.
141      * By default it will grab the page requested via the URL
142      *
143      * This is a convenience function.
144      * @param string $pagename Name of page to get.
145      * @return WikiDB_Page Object with methods to pull data from
146      * database for the page requested.
147      */
148     function getPage ($pagename = false) {
149         if (!isset($this->_dbi))
150             $this->getDbh();
151         if (!$pagename) 
152             $pagename = $this->getArg('pagename');
153         return $this->_dbi->getPage($pagename);
154     }
155
156     /** Get URL for POST actions.
157      *
158      * Officially, we should just use SCRIPT_NAME (or some such),
159      * but that causes problems when we try to issue a redirect, e.g.
160      * after saving a page.
161      *
162      * Some browsers (at least NS4 and Mozilla 0.97 won't accept
163      * a redirect from a page to itself.)
164      *
165      * So, as a HACK, we include pagename and action as query args in
166      * the URL.  (These should be ignored when we receive the POST
167      * request.)
168      */
169     function getPostURL ($pagename=false) {
170         if ($pagename === false)
171             $pagename = $this->getArg('pagename');
172         $action = $this->getArg('action');
173         if (!empty($_GET['start_debug'])) // zend ide support
174             return WikiURL($pagename, array('action' => $action, 'start_debug' => 1));
175         else
176             return WikiURL($pagename, array('action' => $action));
177     }
178     
179     function _handleAuthRequest ($auth_args) {
180         if (!is_array($auth_args))
181             return;
182
183         // Ignore password unless POST'ed.
184         if (!$this->isPost())
185             unset($auth_args['passwd']);
186
187         $olduser = $this->_user;
188         $user = $this->_user->AuthCheck($auth_args);
189         if (isa($user,WikiUserClassname())) {
190             // Successful login (or logout.)
191             $this->_setUser($user);
192         }
193         elseif (is_string($user)) {
194             // Login attempt failed.
195             $fail_message = $user;
196             $auth_args['pass_required'] = true;
197             // If no password was submitted, it's not really
198             // a failure --- just need to prompt for password...
199             if (!isset($auth_args['passwd'])) {
200                  //$auth_args['pass_required'] = false;
201                  $fail_message = false;
202             }
203             $olduser->PrintLoginForm($this, $auth_args, $fail_message);
204             $this->finish();    //NORETURN
205         }
206         else {
207             // Login request cancelled.
208         }
209     }
210
211     /**
212      * Attempt to sign in (bogo-login).
213      *
214      * Fails silently.
215      *
216      * @param $userid string Userid to attempt to sign in as.
217      * @access private
218      */
219     function _signIn ($userid) {
220         if (ENABLE_USER_NEW) {
221             if (! $this->_user )
222                 $this->_user = new _BogoUser($userid);
223             if (! $this->_user )
224                 $this->_user = new _PassUser($userid);
225         }
226         $user = $this->_user->AuthCheck(array('userid' => $userid));
227         if (isa($user,WikiUserClassname())) {
228             $this->_setUser($user); // success!
229         }
230     }
231
232     // login or logout or restore state
233     function _setUser ($user) {
234         $this->_user = $user;
235         $this->setCookieVar('WIKI_ID', $user->getAuthenticatedId(), 365);
236         $this->setSessionVar('wiki_user', $user);
237         if ($user->isSignedIn())
238             $user->_authhow = 'signin';
239
240         // Save userid to prefs..
241         if (!($this->_prefs = $this->_user->getPreferences()))
242             $this->_prefs = $this->_user->_prefs;
243         $this->_prefs->set('userid',
244                            $user->isSignedIn() ? $user->getId() : '');
245         $this->initializeTheme();
246     }
247
248     /* Permission system */
249
250     function _notAuthorized ($require_level) {
251         // Display the authority message in the Wiki's default
252         // language, in case it is not english.
253         //
254         // Note that normally a user will not see such an error once
255         // logged in, unless the admin has altered the default
256         // disallowed wikiactions. In that case we should probably
257         // check the user's language prefs too at this point; this
258         // would be a situation which is not really handled with the
259         // current code.
260         if (empty($GLOBALS['LANG']))
261             update_locale(DEFAULT_LANGUAGE);
262
263         // User does not have required authority.  Prompt for login.
264         $what = $this->getActionDescription($this->getArg('action'));
265
266         if ($require_level == WIKIAUTH_FORBIDDEN) {
267             $this->finish(fmt("%s is disallowed on this wiki.",
268                               $this->getDisallowedActionDescription($this->getArg('action'))));
269         }
270         elseif ($require_level == WIKIAUTH_BOGO)
271             $msg = fmt("You must sign in to %s.", $what);
272         elseif ($require_level == WIKIAUTH_USER)
273             $msg = fmt("You must log in to %s.", $what);
274         else
275             $msg = fmt("You must be an administrator to %s.", $what);
276         $pass_required = ($require_level >= WIKIAUTH_USER);
277
278         $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
279         $this->finish();    // NORETURN
280     }
281
282     // Fixme: for PagePermissions we'll need other strings, 
283     // relevant to the requested page, not just for the action on the whole wiki.
284     function getActionDescription($action) {
285         static $actionDescriptions;
286         if (! $actionDescriptions) {
287             $actionDescriptions
288             = array('browse'     => _("view this page"),
289                     'diff'       => _("diff this page"),
290                     'dumphtml'   => _("dump html pages"),
291                     'dumpserial' => _("dump serial pages"),
292                     'edit'       => _("edit this page"),
293                     'create'     => _("create this page"),
294                     'loadfile'   => _("load files into this wiki"),
295                     'lock'       => _("lock this page"),
296                     'remove'     => _("remove this page"),
297                     'unlock'     => _("unlock this page"),
298                     'upload'     => _("upload a zip dump"),
299                     'verify'     => _("verify the current action"),
300                     'viewsource' => _("view the source of this page"),
301                     'xmlrpc'     => _("access this wiki via XML-RPC"),
302                     'zip'        => _("download a zip dump from this wiki"),
303                     'ziphtml'    => _("download an html zip dump from this wiki")
304                     );
305         }
306         if (in_array($action, array_keys($actionDescriptions)))
307             return $actionDescriptions[$action];
308         else
309             return $action;
310     }
311     function getDisallowedActionDescription($action) {
312         static $disallowedActionDescriptions;
313         if (! $disallowedActionDescriptions) {
314             $disallowedActionDescriptions
315             = array('browse'     => _("Browsing pages"),
316                     'diff'       => _("Diffing pages"),
317                     'dumphtml'   => _("Dumping html pages"),
318                     'dumpserial' => _("Dumping serial pages"),
319                     'edit'       => _("Editing pages"),
320                     'create'     => _("Creating pages"),
321                     'loadfile'   => _("Loading files"),
322                     'lock'       => _("Locking pages"),
323                     'remove'     => _("Removing pages"),
324                     'unlock'     => _("Unlocking pages"),
325                     'upload'     => _("Uploading zip dumps"),
326                     'verify'     => _("Verify the current action"),
327                     'viewsource' => _("Viewing the source of pages"),
328                     'xmlrpc'     => _("XML-RPC access"),
329                     'zip'        => _("Downloading zip dumps"),
330                     'ziphtml'    => _("Downloading html zip dumps")
331                     );
332         }
333         if (in_array($action, array_keys($disallowedActionDescriptions)))
334             return $disallowedActionDescriptions[$action];
335         else
336             return $action;
337     }
338
339     function requiredAuthority ($action) {
340         $auth = $this->requiredAuthorityForAction($action);
341         if (!ALLOW_ANON_USER) return WIKIAUTH_USER;
342         
343         /*
344          * This is a hook for plugins to require authority
345          * for posting to them.
346          *
347          * IMPORTANT: this is not a secure check, so the plugin
348          * may not assume that any POSTs to it are authorized.
349          * All this does is cause PhpWiki to prompt for login
350          * if the user doesn't have the required authority.
351          */
352         if ($this->isPost()) {
353             $post_auth = $this->getArg('require_authority_for_post');
354             if ($post_auth !== false)
355                 $auth = max($auth, $post_auth);
356         }
357         return $auth;
358     }
359         
360     function requiredAuthorityForAction ($action) {
361         if (class_exists("PagePermission")) {
362             return requiredAuthorityForPage($action);
363         } else {
364           // FIXME: clean up. 
365           switch ($action) {
366             case 'browse':
367             case 'viewsource':
368             case 'diff':
369             case 'select':
370             case 'xmlrpc':
371             case 'search':
372                 return WIKIAUTH_ANON;
373
374             case 'zip':
375             case 'ziphtml':
376                 if (defined('ZIPDUMP_AUTH') && ZIPDUMP_AUTH)
377                     return WIKIAUTH_ADMIN;
378                 return WIKIAUTH_ANON;
379
380             case 'edit':
381                 if (defined('REQUIRE_SIGNIN_BEFORE_EDIT') && REQUIRE_SIGNIN_BEFORE_EDIT)
382                     return WIKIAUTH_BOGO;
383                 return WIKIAUTH_ANON;
384                 // return WIKIAUTH_BOGO;
385
386             case 'create':
387                 $page = $this->getPage();
388                 $current = $page->getCurrentRevision();
389                 if ($current->hasDefaultContents())
390                     return $this->requiredAuthorityForAction('edit');
391                 return $this->requiredAuthorityForAction('browse');
392
393             case 'upload':
394             case 'dumpserial':
395             case 'dumphtml':
396             case 'loadfile':
397             case 'remove':
398             case 'lock':
399             case 'unlock':
400             case 'upgrade':
401                 return WIKIAUTH_ADMIN;
402             default:
403                 global $WikiNameRegexp;
404                 if (preg_match("/$WikiNameRegexp\Z/A", $action))
405                     return WIKIAUTH_ANON; // ActionPage.
406                 else
407                     return WIKIAUTH_ADMIN;
408           }
409         }
410     }
411     /* End of Permission system */
412
413     function possiblyDeflowerVirginWiki () {
414         if ($this->getArg('action') != 'browse')
415             return;
416         if ($this->getArg('pagename') != HOME_PAGE)
417             return;
418
419         $page = $this->getPage();
420         $current = $page->getCurrentRevision();
421         if ($current->getVersion() > 0)
422             return;             // Homepage exists.
423
424         include('lib/loadsave.php');
425         SetupWiki($this);
426         $this->finish();        // NORETURN
427     }
428
429     function handleAction () {
430         $action = $this->getArg('action');
431         $method = "action_$action";
432         if (method_exists($this, $method)) {
433             $this->{$method}();
434         }
435         elseif ($page = $this->findActionPage($action)) {
436             $this->actionpage($page);
437         }
438         else {
439             $this->finish(fmt("%s: Bad action", $action));
440         }
441     }
442     
443     function finish ($errormsg = false) {
444         static $in_exit = 0;
445
446         if ($in_exit)
447             exit();        // just in case CloseDataBase calls us
448         $in_exit = true;
449
450         if (!empty($this->_dbi))
451             $this->_dbi->close();
452         unset($this->_dbi);
453
454
455         global $ErrorManager;
456         $ErrorManager->flushPostponedErrors();
457
458         if (!empty($errormsg)) {
459             PrintXML(HTML::br(),
460                      HTML::hr(),
461                      HTML::h2(_("Fatal PhpWiki Error")),
462                      $errormsg);
463             // HACK:
464             echo "\n</body></html>";
465         }
466
467         Request::finish();
468         exit;
469     }
470
471     function _deducePagename () {
472         if ($this->getArg('pagename'))
473             return $this->getArg('pagename');
474
475         if (USE_PATH_INFO) {
476             $pathinfo = $this->get('PATH_INFO');
477             $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
478
479             if ($tail && $pathinfo == PATH_INFO_PREFIX . $tail) {
480                 return $tail;
481             }
482         }
483         elseif ($this->isPost()) {
484             /*
485              * In general, for security reasons, HTTP_GET_VARS should be ignored
486              * on POST requests, but we make an exception here (only for pagename).
487              *
488              * The justifcation for this hack is the following
489              * asymmetry: When POSTing with USE_PATH_INFO set, the
490              * pagename can (and should) be communicated through the
491              * request URL via PATH_INFO.  When POSTing with
492              * USE_PATH_INFO off, this cannot be done --- the only way
493              * to communicate the pagename through the URL is via
494              * QUERY_ARGS (HTTP_GET_VARS).
495              */
496             global $HTTP_GET_VARS;
497             if (isset($HTTP_GET_VARS['pagename'])) { 
498                 return $HTTP_GET_VARS['pagename'];
499             }
500         }
501
502         /*
503          * Support for PhpWiki 1.2 style requests.
504          */
505         $query_string = $this->get('QUERY_STRING');
506         if (preg_match('/^[^&=]+$/', $query_string)) {
507             return urldecode($query_string);
508         }
509
510         return HOME_PAGE;
511     }
512
513     function _deduceAction () {
514         if (!($action = $this->getArg('action'))) {
515             // Detect XML-RPC requests
516             if ($this->isPost()
517                 && $this->get('CONTENT_TYPE') == 'text/xml') {
518                 global $HTTP_RAW_POST_DATA;
519                 if (strstr($HTTP_RAW_POST_DATA, '<methodCall>')) {
520                     return 'xmlrpc';
521                 }
522             }
523
524             return 'browse';    // Default if no action specified.
525         }
526
527         if (method_exists($this, "action_$action"))
528             return $action;
529
530         // Allow for, e.g. action=LikePages
531         if ($this->isActionPage($action))
532             return $action;
533
534         trigger_error("$action: Unknown action", E_USER_NOTICE);
535         return 'browse';
536     }
537
538     function _deduceUsername() {
539         if (!empty($this->args['auth']) and !empty($this->args['auth']['userid']))
540             return $this->args['auth']['userid'];
541         if (!empty($_SERVER['PHP_AUTH_USER']))
542             return $_SERVER['PHP_AUTH_USER'];
543         if (!empty($_ENV['REMOTE_USER']))
544             return $_ENV['REMOTE_USER'];
545             
546         if ($user = $this->getSessionVar('wiki_user')) {
547             $this->_user = $user;
548             $this->_user->_authhow = 'session';
549             return ENABLE_USER_NEW ? $user->UserName() : $this->_user;
550         }
551         if ($userid = $this->getCookieVar('WIKI_ID')) {
552             if (!empty($this->_user))
553                 $this->_user->authhow = 'cookie';
554             return $userid;
555         }
556         return false;
557     }
558     
559     function _isActionPage ($pagename) {
560         $dbi = $this->getDbh();
561         $page = $dbi->getPage($pagename);
562         $rev = $page->getCurrentRevision();
563         // FIXME: more restrictive check for sane plugin?
564         if (strstr($rev->getPackedContent(), '<?plugin'))
565             return true;
566         if (!$rev->hasDefaultContents())
567             trigger_error("$pagename: Does not appear to be an 'action page'", E_USER_NOTICE);
568         return false;
569     }
570
571     function findActionPage ($action) {
572         static $cache;
573
574         // check for translated version, as per users preferred language
575         // (or system default in case it is not en)
576         $translation = gettext($action);
577
578         if (isset($cache) and isset($cache[$translation]))
579             return $cache[$translation];
580
581         // check for cached translated version
582         if ($this->_isActionPage($translation))
583             return $cache[$action] = $translation;
584
585         // Allow for, e.g. action=LikePages
586         global $WikiNameRegexp;
587         if (!preg_match("/$WikiNameRegexp\\Z/A", $action))
588             return $cache[$action] = false;
589
590         // check for translated version (default language)
591         global $LANG;
592         if ($LANG != DEFAULT_LANGUAGE and $LANG != "en") {
593             $save_lang = $LANG;
594             //trigger_error("DEBUG: findActionPage() ". DEFAULT_LANGUAGE." calling update_locale()...");
595             update_locale(DEFAULT_LANGUAGE);
596             $default = gettext($action);
597             //trigger_error("DEBUG: findActionPage() ". $save_lang." restoring save_lang, calling update_locale()...");
598             update_locale($save_lang);
599             if ($this->_isActionPage($default))
600                 return $cache[$action] = $default;
601         }
602         else {
603             $default = $translation;
604         }
605         
606         // check for english version
607         if ($action != $translation and $action != $default) {
608             if ($this->_isActionPage($action))
609                 return $cache[$action] = $action;
610         }
611
612         trigger_error("$action: Cannot find action page", E_USER_NOTICE);
613         return $cache[$action] = false;
614     }
615     
616     function isActionPage ($pagename) {
617         return $this->findActionPage($pagename);
618     }
619
620     function action_browse () {
621         $this->buffer_output();
622         include_once("lib/display.php");
623         displayPage($this);
624     }
625
626     function action_verify () {
627         $this->action_browse();
628     }
629
630     function actionpage ($action) {
631         $this->buffer_output();
632         include_once("lib/display.php");
633         actionPage($this, $action);
634     }
635
636     function action_diff () {
637         $this->buffer_output();
638         include_once "lib/diff.php";
639         showDiff($this);
640     }
641
642     function action_search () {
643         // This is obsolete: reformulate URL and redirect.
644         // FIXME: this whole section should probably be deleted.
645         if ($this->getArg('searchtype') == 'full') {
646             $search_page = _("FullTextSearch");
647         }
648         else {
649             $search_page = _("TitleSearch");
650         }
651         $this->redirect(WikiURL($search_page,
652                                 array('s' => $this->getArg('searchterm')),
653                                 'absolute_url'));
654     }
655
656     function action_edit () {
657         $this->buffer_output();
658         include "lib/editpage.php";
659         $e = new PageEditor ($this);
660         $e->editPage();
661     }
662
663     function action_create () {
664         $this->action_edit();
665     }
666     
667     function action_viewsource () {
668         $this->buffer_output();
669         include "lib/editpage.php";
670         $e = new PageEditor ($this);
671         $e->viewSource();
672     }
673
674     function action_lock () {
675         $page = $this->getPage();
676         $page->set('locked', true);
677         $this->action_browse();
678     }
679
680     function action_unlock () {
681         // FIXME: This check is redundant.
682         //$user->requireAuth(WIKIAUTH_ADMIN);
683         $page = $this->getPage();
684         $page->set('locked', false);
685         $this->action_browse();
686     }
687
688     function action_remove () {
689         // FIXME: This check is redundant.
690         //$user->requireAuth(WIKIAUTH_ADMIN);
691         $pagename = $this->getArg('pagename');
692         if (strstr($pagename,_('PhpWikiAdministration'))) {
693             $this->action_browse();
694         } else {
695             include('lib/removepage.php');
696             RemovePage($this);
697         }
698     }
699
700     function action_xmlrpc () {
701         include_once("lib/XmlRpcServer.php");
702         $xmlrpc = new XmlRpcServer($this);
703         $xmlrpc->service();
704     }
705     
706     function action_zip () {
707         include_once("lib/loadsave.php");
708         MakeWikiZip($this);
709         // I don't think it hurts to add cruft at the end of the zip file.
710         echo "\n========================================================\n";
711         echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
712     }
713
714     function action_ziphtml () {
715         include_once("lib/loadsave.php");
716         MakeWikiZipHtml($this);
717         // I don't think it hurts to add cruft at the end of the zip file.
718         echo "\n========================================================\n";
719         echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
720     }
721
722     function action_dumpserial () {
723         include_once("lib/loadsave.php");
724         DumpToDir($this);
725     }
726
727     function action_dumphtml () {
728         include_once("lib/loadsave.php");
729         DumpHtmlToDir($this);
730     }
731
732     function action_upload () {
733         include_once("lib/loadsave.php");
734         LoadPostFile($this);
735     }
736
737     function action_upgrade () {
738         include_once("lib/loadsave.php");
739         include_once("lib/upgrade.php");
740         DoUpgrade($this);
741     }
742
743     function action_loadfile () {
744         include_once("lib/loadsave.php");
745         LoadFileOrDir($this);
746     }
747 }
748
749 //FIXME: deprecated
750 function is_safe_action ($action) {
751     return WikiRequest::requiredAuthorityForAction($action) < WIKIAUTH_ADMIN;
752 }
753
754 function validateSessionPath() {
755     // Try to defer any session.save_path PHP errors before any html
756     // is output, which causes some versions of IE to display a blank
757     // page (due to its strict mode while parsing a page?).
758     if (! is_writeable(ini_get('session.save_path'))) {
759         $tmpdir = '/tmp';
760         trigger_error
761             (sprintf(_("%s is not writable."),
762                      _("The session.save_path directory"))
763              . "\n"
764              . sprintf(_("Please ensure that %s is writable, or redefine %s in index.php."),
765                        sprintf(_("the directory '%s'"),
766                                ini_get('session.save_path')),
767                        'session.save_path')
768              . "\n"
769              . sprintf(_("Attempting to use the directory '%s' instead."),
770                        $tmpdir)
771              , E_USER_NOTICE);
772         if (! is_writeable($tmpdir)) {
773             trigger_error
774                 (sprintf(_("%s is not writable."), $tmpdir)
775                  . "\n"
776                  . _("Users will not be able to sign in.")
777                  , E_USER_NOTICE);
778         }
779         else
780             ini_set('session.save_path', $tmpdir);
781     }
782 }
783
784 function main () {
785     if (!USE_DB_SESSION)
786         validateSessionPath();
787
788     global $request;
789
790     $request = new WikiRequest();
791
792     /*
793      * Allow for disabling of markup cache.
794      * (Mostly for debugging ... hopefully.)
795      *
796      * See also <?plugin WikiAdminUtils action=purge-cache ?>
797      */
798     if (!defined('WIKIDB_NOCACHE_MARKUP') and $request->getArg('nocache'))
799         define('WIKIDB_NOCACHE_MARKUP', $request->getArg('nocache'));
800     
801     // Initialize with system defaults in case user not logged in.
802     // Should this go into constructor?
803     $request->initializeTheme();
804
805     $request->updateAuthAndPrefs();
806     $request->initializeLang();
807     
808     // Enable the output of most of the warning messages.
809     // The warnings will screw up zip files though.
810     global $ErrorManager;
811     if (substr($request->getArg('action'), 0, 3) != 'zip') {
812         $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
813         //$ErrorManager->setPostponedErrorMask(0);
814     }
815
816     //FIXME:
817     //if ($user->is_authenticated())
818     //  $LogEntry->user = $user->getId();
819
820     $request->possiblyDeflowerVirginWiki();
821     
822 if (defined('WIKI_XMLRPC') and WIKI_XMLRPC) return;
823 if (defined('WIKI_SOAP')   and WIKI_SOAP)   return;
824
825     $validators = array('wikiname' => WIKI_NAME,
826                         'args'     => hash($request->getArgs()),
827                         'prefs'    => hash($request->getPrefs()));
828     if (CACHE_CONTROL == 'STRICT') {
829         $dbi = $request->getDbh();
830         $timestamp = $dbi->getTimestamp();
831         $validators['mtime'] = $timestamp;
832         $validators['%mtime'] = (int)$timestamp;
833     }
834     // FIXME: we should try to generate strong validators when possible,
835     // but for now, our validator is weak, since equal validators do not
836     // indicate byte-level equality of content.  (Due to DEBUG timing output, etc...)
837     //
838     // (If DEBUG if off, this may be a strong validator, but I'm going
839     // to go the paranoid route here pending further study and testing.)
840     //
841     $validators['%weak'] = true;
842     
843     $request->setValidators($validators);
844    
845     $request->handleAction();
846
847 if (defined('DEBUG') and DEBUG & 4) phpinfo(INFO_VARIABLES);
848     $request->finish();
849 }
850
851 $x = error_reporting(); // why is it 1 here? should be E_ALL
852 error_reporting(E_ALL);
853 main();
854
855
856 // $Log: not supported by cvs2svn $
857 // Revision 1.125  2004/03/14 16:30:52  rurban
858 // db-handle session revivification, dba fixes
859 //
860 // Revision 1.124  2004/03/12 15:48:07  rurban
861 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
862 // simplified lib/stdlib.php:explodePageList
863 //
864 // Revision 1.123  2004/03/10 15:41:27  rurban
865 // use default pref mysql table
866 //
867 // Revision 1.122  2004/03/08 18:17:09  rurban
868 // added more WikiGroup::getMembersOf methods, esp. for special groups
869 // fixed $LDAP_SET_OPTIONS
870 // fixed _AuthInfo group methods
871 //
872 // Revision 1.121  2004/03/01 13:48:45  rurban
873 // rename fix
874 // p[] consistency fix
875 //
876 // Revision 1.120  2004/03/01 10:22:41  rurban
877 // initializeTheme optimize
878 //
879 // Revision 1.119  2004/02/26 20:45:06  rurban
880 // check for ALLOW_ANON_USER = false
881 //
882 // Revision 1.118  2004/02/26 01:32:03  rurban
883 // fixed session login with old WikiUser object. strangely, the errormask gets corruoted to 1, Pear???
884 //
885 // Revision 1.117  2004/02/24 17:19:37  rurban
886 // debugging helpers only
887 //
888 // Revision 1.116  2004/02/24 15:17:14  rurban
889 // 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
890 //
891 // Revision 1.115  2004/02/15 21:34:37  rurban
892 // PageList enhanced and improved.
893 // fixed new WikiAdmin... plugins
894 // editpage, Theme with exp. htmlarea framework
895 //   (htmlarea yet committed, this is really questionable)
896 // WikiUser... code with better session handling for prefs
897 // enhanced UserPreferences (again)
898 // RecentChanges for show_deleted: how should pages be deleted then?
899 //
900 // Revision 1.114  2004/02/15 17:30:13  rurban
901 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
902 // fixed getPreferences() (esp. from sessions)
903 // fixed setPreferences() (update and set),
904 // fixed AdoDb DB statements,
905 // update prefs only at UserPreferences POST (for testing)
906 // unified db prefs methods (but in external pref classes yet)
907 //
908 // Revision 1.113  2004/02/12 13:05:49  rurban
909 // Rename functional for PearDB backend
910 // some other minor changes
911 // SiteMap comes with a not yet functional feature request: includepages (tbd)
912 //
913 // Revision 1.112  2004/02/09 03:58:12  rurban
914 // for now default DB_SESSION to false
915 // PagePerm:
916 //   * not existing perms will now query the parent, and not
917 //     return the default perm
918 //   * added pagePermissions func which returns the object per page
919 //   * added getAccessDescription
920 // WikiUserNew:
921 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
922 //   * force init of authdbh in the 2 db classes
923 // main:
924 //   * fixed session handling (not triple auth request anymore)
925 //   * don't store cookie prefs with sessions
926 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
927 //
928 // Revision 1.111  2004/02/07 10:41:25  rurban
929 // fixed auth from session (still double code but works)
930 // fixed GroupDB
931 // fixed DbPassUser upgrade and policy=old
932 // added GroupLdap
933 //
934 // Revision 1.110  2004/02/03 09:45:39  rurban
935 // LDAP cleanup, start of new Pref classes
936 //
937 // Revision 1.109  2004/01/30 19:57:58  rurban
938 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
939 //
940 // Revision 1.108  2004/01/28 14:34:14  rurban
941 // session table takes the common prefix
942 // + various minor stuff
943 // reallow password changing
944 //
945 // Revision 1.107  2004/01/27 23:23:39  rurban
946 // renamed ->Username => _userid for consistency
947 // renamed mayCheckPassword => mayCheckPass
948 // fixed recursion problem in WikiUserNew
949 // fixed bogo login (but not quite 100% ready yet, password storage)
950 //
951 // Revision 1.106  2004/01/26 09:17:49  rurban
952 // * changed stored pref representation as before.
953 //   the array of objects is 1) bigger and 2)
954 //   less portable. If we would import packed pref
955 //   objects and the object definition was changed, PHP would fail.
956 //   This doesn't happen with an simple array of non-default values.
957 // * use $prefs->retrieve and $prefs->store methods, where retrieve
958 //   understands the interim format of array of objects also.
959 // * simplified $prefs->get() and fixed $prefs->set()
960 // * added $user->_userid and class '_WikiUser' portability functions
961 // * fixed $user object ->_level upgrading, mostly using sessions.
962 //   this fixes yesterdays problems with loosing authorization level.
963 // * fixed WikiUserNew::checkPass to return the _level
964 // * fixed WikiUserNew::isSignedIn
965 // * added explodePageList to class PageList, support sortby arg
966 // * fixed UserPreferences for WikiUserNew
967 // * fixed WikiPlugin for empty defaults array
968 // * UnfoldSubpages: added pagename arg, renamed pages arg,
969 //   removed sort arg, support sortby arg
970 //
971 // Revision 1.105  2004/01/25 03:57:15  rurban
972 // WikiUserNew support (temp. ENABLE_USER_NEW constant)
973 //
974 // Revision 1.104  2003/12/26 06:41:16  carstenklapp
975 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
976 // so they don't prevent IE from partially (or not at all) rendering the
977 // page. This should help a little for the IE user who encounters trouble
978 // when setting up a new PhpWiki for the first time.
979 //
980 // Revision 1.103  2003/12/02 00:10:00  carstenklapp
981 // Bugfix: Ongoing work to untangle UserPreferences/WikiUser/request code
982 // mess: UserPreferences should take effect immediately now upon signing
983 // in.
984 //
985 // Revision 1.102  2003/11/25 22:55:32  carstenklapp
986 // Localization bugfix: For wikis where English is not the default system
987 // language, make sure that the authority error message (i.e. "You must
988 // sign in to edit pages in this wiki" etc.) is displayed in the wiki's
989 // default language. Previously it would always display in English.
990 // (Added call to update_locale() before displaying any messages prior to
991 // the login prompt.)
992 //
993 // Revision 1.101  2003/11/25 21:49:44  carstenklapp
994 // Bugfix: For a non-english wiki or when the user's preference is not
995 // english, the wiki would always use the english ActionPage first if it
996 // was present rather than the appropriate localised variant. (PhpWikis
997 // running only in english or Wikis running ONLY without any english
998 // ActionPages would not notice this bug, only when both english and
999 // localised ActionPages were in the DB.) Now we check for the localised
1000 // variant first.
1001 //
1002 // Revision 1.100  2003/11/18 16:54:18  carstenklapp
1003 // Reformatting only: Tabs to spaces, added rcs log.
1004 //
1005
1006
1007 // Local Variables:
1008 // mode: php
1009 // tab-width: 8
1010 // c-basic-offset: 4
1011 // c-hanging-comment-ender-p: nil
1012 // indent-tabs-mode: nil
1013 // End:
1014 ?>