]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/main.php
fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
[SourceForge/phpwiki.git] / lib / main.php
1 <?php //-*-php-*-
2 rcs_id('$Id: main.php,v 1.109 2004-01-30 19:57:58 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
16 class WikiRequest extends Request {
17     // var $_dbi;
18
19     function WikiRequest () {
20         $this->_dbi = WikiDB::open($GLOBALS['DBParams']);
21
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         
29         $this->Request();
30
31         // Normalize args...
32         $this->setArg('pagename', $this->_deducePagename());
33         $this->setArg('action', $this->_deduceAction());
34
35         // Restore auth state. This doesn't check for proper authorization!
36         if (ENABLE_USER_NEW) {
37             $userid = $this->_deduceUsername(); 
38             $user = WikiUser($userid);
39             if (isset($this->_user)) 
40                 $user = UpgradeUser($this->_user,$user);
41             $this->_user = $user;
42             $this->_prefs = $this->_user->_prefs;
43         } else {
44             $this->_user = new WikiUser($this, $this->_deduceUsername());
45             $this->_prefs = $this->_user->getPreferences();
46         }
47     }
48
49     function initializeLang () {
50         if ($user_lang = $this->getPref('lang')) {
51             //trigger_error("DEBUG: initializeLang() ". $user_lang ." calling update_locale()...");
52             update_locale($user_lang);
53         }
54     }
55
56     function initializeTheme () {
57         global $Theme;
58
59         // Load theme
60         if ($user_theme = $this->getPref('theme'))
61             include_once("themes/$user_theme/themeinfo.php");
62         if (empty($Theme) and defined ('THEME'))
63             include_once("themes/" . THEME . "/themeinfo.php");
64         if (empty($Theme))
65             include_once("themes/default/themeinfo.php");
66         assert(!empty($Theme));
67     }
68
69
70     // This really maybe should be part of the constructor, but since it
71     // may involve HTML/template output, the global $request really needs
72     // to be initialized before we do this stuff.
73     function updateAuthAndPrefs () {
74         
75         // Handle preference updates, and authentication requests, if any.
76         if ($new_prefs = $this->getArg('pref')) {
77             $this->setArg('pref', false);
78             if ($this->isPost() and !empty($new_prefs['passwd']) and 
79                 ($new_prefs['passwd2'] != $new_prefs['passwd'])) {
80                 // FIXME: enh?
81                 $this->_prefs->set('passwd','');
82                 // $this->_prefs->set('passwd2',''); // This is not stored anyway
83                 return false;
84             }
85             foreach ($new_prefs as $key => $val) {
86                 if ($key == 'passwd') {
87                     // FIXME: enh?
88                     $val = crypt('passwd');
89                 }
90                 $this->_prefs->set($key, $val);
91             }
92         }
93
94         // FIXME: need to move authentication request processing
95         // up to be before pref request processing, I think,
96         // since logging in may change which preferences
97         // we're talking about...
98
99         // even we have disallow anon users?
100         // if (! $this->_user ) $this->_user = new _AnonUser(); 
101
102         // Handle authentication request, if any.
103         if ($auth_args = $this->getArg('auth')) {
104             $this->setArg('auth', false);
105             $this->_handleAuthRequest($auth_args); // possible NORETURN
106         }
107         elseif ( ! $this->_user or ! $this->_user->isSignedIn() ) {
108             // If not auth request, try to sign in as saved user.
109             if (($saved_user = $this->getPref('userid')) != false) {
110                 $this->_signIn($saved_user);
111             }
112         }
113
114         // Save preferences in session and cookie
115         // FIXME: hey! what about anonymous users?   Can't they have
116         // preferences too?
117
118         $id_only = true; 
119         $this->_user->setPreferences($this->_prefs, $id_only);
120
121         // Ensure user has permissions for action
122         $require_level = $this->requiredAuthority($this->getArg('action'));
123         if (! $this->_user->hasAuthority($require_level))
124             $this->_notAuthorized($require_level); // NORETURN
125     }
126
127     function getUser () {
128         return $this->_user;
129     }
130
131     function getPrefs () {
132         return $this->_prefs;
133     }
134
135     // Convenience function:
136     function getPref ($key) {
137         if (isset($this->_prefs))
138             return $this->_prefs->get($key);
139     }
140
141     function getDbh () {
142         return $this->_dbi;
143     }
144
145     /**
146      * Get requested page from the page database.
147      * By default it will grab the page requested via the URL
148      *
149      * This is a convenience function.
150      * @param string $pagename Name of page to get.
151      * @return WikiDB_Page Object with methods to pull data from
152      * database for the page requested.
153      */
154     function getPage ($pagename = false) {
155         if (!isset($this->_dbi))
156             $this->getDbh();
157         if (!$pagename) 
158             $pagename = $this->getArg('pagename');
159         return $this->_dbi->getPage($pagename);
160     }
161
162     /** Get URL for POST actions.
163      *
164      * Officially, we should just use SCRIPT_NAME (or some such),
165      * but that causes problems when we try to issue a redirect, e.g.
166      * after saving a page.
167      *
168      * Some browsers (at least NS4 and Mozilla 0.97 won't accept
169      * a redirect from a page to itself.)
170      *
171      * So, as a HACK, we include pagename and action as query args in
172      * the URL.  (These should be ignored when we receive the POST
173      * request.)
174      */
175     function getPostURL ($pagename=false) {
176         if ($pagename === false)
177             $pagename = $this->getArg('pagename');
178         $action = $this->getArg('action');
179         if ($this->getArg('start_debug')) // zend ide support
180             return WikiURL($pagename, array('action' => $action, 'start_debug' => 1));
181         else
182             return WikiURL($pagename, array('action' => $action));
183     }
184     
185     function _handleAuthRequest ($auth_args) {
186         if (!is_array($auth_args))
187             return;
188
189         // Ignore password unless POST'ed.
190         if (!$this->isPost())
191             unset($auth_args['passwd']);
192
193         $olduser = $this->_user;
194         $user = $this->_user->AuthCheck($auth_args);
195         if (isa($user,WikiUserClassname())) {
196             // Successful login (or logout.)
197             $this->_setUser($user);
198         }
199         elseif (is_string($user)) {
200             // Login attempt failed.
201             $fail_message = $user;
202             $auth_args['pass_required'] = true;
203             // If no password was submitted, it's not really
204             // a failure --- just need to prompt for password...
205             if (!isset($auth_args['passwd'])) {
206                  //$auth_args['pass_required'] = false;
207                  $fail_message = false;
208             }
209             $olduser->PrintLoginForm($this, $auth_args, $fail_message);
210             $this->finish();    //NORETURN
211         }
212         else {
213             // Login request cancelled.
214         }
215     }
216
217     /**
218      * Attempt to sign in (bogo-login).
219      *
220      * Fails silently.
221      *
222      * @param $userid string Userid to attempt to sign in as.
223      * @access private
224      */
225     function _signIn ($userid) {
226         if (ENABLE_USER_NEW) {
227             if (! $this->_user )
228                 $this->_user = new _BogoUser($userid);
229             if (! $this->_user )
230                 $this->_user = new _PassUser($userid);
231         }
232         $user = $this->_user->AuthCheck(array('userid' => $userid));
233         if (isa($user,WikiUserClassname())) {
234             $this->_setUser($user); // success!
235         }
236     }
237
238     // login or logout or restore state
239     function _setUser ($user) {
240         $this->_user = $user;
241         $this->setCookieVar('WIKI_ID', $user->getAuthenticatedId(), 365);
242         $this->setSessionVar('wiki_user', $user);
243         if ($user->isSignedIn())
244             $user->_authhow = 'signin';
245
246         // Save userid to prefs..
247         if (!($this->_prefs = $this->_user->getPreferences()))
248             $this->_prefs = $this->_user->_prefs;
249         $this->_prefs->set('userid',
250                            $user->isSignedIn() ? $user->getId() : '');
251     }
252
253     function _notAuthorized ($require_level) {
254         // Display the authority message in the Wiki's default
255         // language, in case it is not english.
256         //
257         // Note that normally a user will not see such an error once
258         // logged in, unless the admin has altered the default
259         // disallowed wikiactions. In that case we should probably
260         // check the user's language prefs too at this point; this
261         // would be a situation which is not really handled with the
262         // current code.
263         update_locale(DEFAULT_LANGUAGE);
264
265         // User does not have required authority.  Prompt for login.
266         $what = $this->getActionDescription($this->getArg('action'));
267
268         if ($require_level == WIKIAUTH_FORBIDDEN) {
269             $this->finish(fmt("%s is disallowed on this wiki.",
270                               $this->getDisallowedActionDescription($this->getArg('action'))));
271         }
272         elseif ($require_level == WIKIAUTH_BOGO)
273             $msg = fmt("You must sign in to %s.", $what);
274         elseif ($require_level == WIKIAUTH_USER)
275             $msg = fmt("You must log in to %s.", $what);
276         else
277             $msg = fmt("You must be an administrator to %s.", $what);
278         $pass_required = ($require_level >= WIKIAUTH_USER);
279
280         $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
281         $this->finish();    // NORETURN
282     }
283
284     function getActionDescription($action) {
285         static $actionDescriptions;
286         if (! $actionDescriptions) {
287             $actionDescriptions
288             = array('browse'     => _("browse pages in this wiki"),
289                     'diff'       => _("diff pages in this wiki"),
290                     'dumphtml'   => _("dump html pages from this wiki"),
291                     'dumpserial' => _("dump serial pages from this wiki"),
292                     'edit'       => _("edit pages in this wiki"),
293                     'create'     => _("create pages in this wiki"),
294                     'loadfile'   => _("load files into this wiki"),
295                     'lock'       => _("lock pages in this wiki"),
296                     'remove'     => _("remove pages from this wiki"),
297                     'unlock'     => _("unlock pages in this wiki"),
298                     'upload'     => _("upload a zip dump to this wiki"),
299                     'verify'     => _("verify the current action"),
300                     'viewsource' => _("view the source of pages in this wiki"),
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         
342         /*
343          * This is a hook for plugins to require authority
344          * for posting to them.
345          *
346          * IMPORTANT: this is not a secure check, so the plugin
347          * may not assume that any POSTs to it are authorized.
348          * All this does is cause PhpWiki to prompt for login
349          * if the user doesn't have the required authority.
350          */
351         if ($this->isPost()) {
352             $post_auth = $this->getArg('require_authority_for_post');
353             if ($post_auth !== false)
354                 $auth = max($auth, $post_auth);
355         }
356         return $auth;
357     }
358         
359     function requiredAuthorityForAction ($action) {
360         // FIXME: clean up. 
361         // Todo: Check individual page permissions instead.
362         switch ($action) {
363             case 'browse':
364             case 'viewsource':
365             case 'diff':
366             case 'select':
367             case 'xmlrpc':
368             case 'search':
369                 return WIKIAUTH_ANON;
370
371             case 'zip':
372             case 'ziphtml':
373                 if (defined('ZIPDUMP_AUTH') && ZIPDUMP_AUTH)
374                     return WIKIAUTH_ADMIN;
375                 return WIKIAUTH_ANON;
376
377             case 'edit':
378                 if (defined('REQUIRE_SIGNIN_BEFORE_EDIT') && REQUIRE_SIGNIN_BEFORE_EDIT)
379                     return WIKIAUTH_BOGO;
380                 return WIKIAUTH_ANON;
381                 // return WIKIAUTH_BOGO;
382
383             case 'create':
384                 $page = $this->getPage();
385                 $current = $page->getCurrentRevision();
386                 if ($current->hasDefaultContents())
387                     return $this->requiredAuthorityForAction('edit');
388                 return $this->requiredAuthorityForAction('browse');
389
390             case 'upload':
391             case 'dumpserial':
392             case 'dumphtml':
393             case 'loadfile':
394             case 'remove':
395             case 'lock':
396             case 'unlock':
397                 return WIKIAUTH_ADMIN;
398             default:
399                 global $WikiNameRegexp;
400                 if (preg_match("/$WikiNameRegexp\Z/A", $action))
401                     return WIKIAUTH_ANON; // ActionPage.
402                 else
403                     return WIKIAUTH_ADMIN;
404         }
405     }
406
407     function possiblyDeflowerVirginWiki () {
408         if ($this->getArg('action') != 'browse')
409             return;
410         if ($this->getArg('pagename') != HOME_PAGE)
411             return;
412
413         $page = $this->getPage();
414         $current = $page->getCurrentRevision();
415         if ($current->getVersion() > 0)
416             return;             // Homepage exists.
417
418         include('lib/loadsave.php');
419         SetupWiki($this);
420         $this->finish();        // NORETURN
421     }
422
423     function handleAction () {
424         $action = $this->getArg('action');
425         $method = "action_$action";
426         if (method_exists($this, $method)) {
427             $this->{$method}();
428         }
429         elseif ($page = $this->findActionPage($action)) {
430             $this->actionpage($page);
431         }
432         else {
433             $this->finish(fmt("%s: Bad action", $action));
434         }
435     }
436     
437     function finish ($errormsg = false) {
438         static $in_exit = 0;
439
440         if ($in_exit)
441             exit();        // just in case CloseDataBase calls us
442         $in_exit = true;
443
444         if (!empty($this->_dbi))
445             $this->_dbi->close();
446         unset($this->_dbi);
447
448
449         global $ErrorManager;
450         $ErrorManager->flushPostponedErrors();
451
452         if (!empty($errormsg)) {
453             PrintXML(HTML::br(),
454                      HTML::hr(),
455                      HTML::h2(_("Fatal PhpWiki Error")),
456                      $errormsg);
457             // HACK:
458             echo "\n</body></html>";
459         }
460
461         Request::finish();
462         exit;
463     }
464
465     function _deducePagename () {
466         if ($this->getArg('pagename'))
467             return $this->getArg('pagename');
468
469         if (USE_PATH_INFO) {
470             $pathinfo = $this->get('PATH_INFO');
471             $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
472
473             if ($tail && $pathinfo == PATH_INFO_PREFIX . $tail) {
474                 return $tail;
475             }
476         }
477         elseif ($this->isPost()) {
478             /*
479              * In general, for security reasons, HTTP_GET_VARS should be ignored
480              * on POST requests, but we make an exception here (only for pagename).
481              *
482              * The justifcation for this hack is the following
483              * asymmetry: When POSTing with USE_PATH_INFO set, the
484              * pagename can (and should) be communicated through the
485              * request URL via PATH_INFO.  When POSTing with
486              * USE_PATH_INFO off, this cannot be done --- the only way
487              * to communicate the pagename through the URL is via
488              * QUERY_ARGS (HTTP_GET_VARS).
489              */
490             global $HTTP_GET_VARS;
491             if (isset($HTTP_GET_VARS['pagename'])) { 
492                 return $HTTP_GET_VARS['pagename'];
493             }
494         }
495
496         /*
497          * Support for PhpWiki 1.2 style requests.
498          */
499         $query_string = $this->get('QUERY_STRING');
500         if (preg_match('/^[^&=]+$/', $query_string)) {
501             return urldecode($query_string);
502         }
503
504         return HOME_PAGE;
505     }
506
507     function _deduceAction () {
508         if (!($action = $this->getArg('action'))) {
509             // Detect XML-RPC requests
510             if ($this->isPost()
511                 && $this->get('CONTENT_TYPE') == 'text/xml') {
512                 global $HTTP_RAW_POST_DATA;
513                 if (strstr($HTTP_RAW_POST_DATA, '<methodCall>')) {
514                     return 'xmlrpc';
515                 }
516             }
517
518             return 'browse';    // Default if no action specified.
519         }
520
521         if (method_exists($this, "action_$action"))
522             return $action;
523
524         // Allow for, e.g. action=LikePages
525         if ($this->isActionPage($action))
526             return $action;
527
528         trigger_error("$action: Unknown action", E_USER_NOTICE);
529         return 'browse';
530     }
531
532     function _deduceUsername() {
533         if (!empty($this->args['auth']) and !empty($this->args['auth']['userid']))
534             return $this->args['auth']['userid'];
535             
536         if ($user = $this->getSessionVar('wiki_user')) {
537             // users might switch in a session between the two objects
538             // restore old auth level?
539             if (isa($user,WikiUserClassname()) and !empty($user->_level)) {
540                 if (empty($this->_user)) {
541                     $c = get_class($user);
542                     $userid = $user->UserName();
543                     if (ENABLE_USER_NEW)
544                         $this->_user = new $c($userid);
545                     else
546                         $this->_user = new $c($this,$userid,$user->_level);
547                 }
548                 if ($user = UpgradeUser($this->_user,$user))
549                     $this->_user = $user;
550                 $this->_user->_authhow = 'session';
551                 
552             }
553             if (isa($user,WikiUserClassname()))
554                 return $user->UserName();
555         }
556         if ($userid = $this->getCookieVar('WIKI_ID')) {
557             if (!empty($this->_user))
558                 $this->_user->authhow = 'cookie';
559             return $userid;
560         }
561         return false;
562     }
563     
564     function _isActionPage ($pagename) {
565         $dbi = $this->getDbh();
566         $page = $dbi->getPage($pagename);
567         $rev = $page->getCurrentRevision();
568         // FIXME: more restrictive check for sane plugin?
569         if (strstr($rev->getPackedContent(), '<?plugin'))
570             return true;
571         if (!$rev->hasDefaultContents())
572             trigger_error("$pagename: Does not appear to be an 'action page'", E_USER_NOTICE);
573         return false;
574     }
575
576     function findActionPage ($action) {
577         static $cache;
578
579         // check for translated version, as per users preferred language
580         // (or system default in case it is not en)
581         $translation = gettext($action);
582
583         if (isset($cache) and isset($cache[$translation]))
584             return $cache[$translation];
585
586         // check for cached translated version
587         if ($this->_isActionPage($translation))
588             return $cache[$action] = $translation;
589
590         // Allow for, e.g. action=LikePages
591         global $WikiNameRegexp;
592         if (!preg_match("/$WikiNameRegexp\\Z/A", $action))
593             return $cache[$action] = false;
594
595         // check for translated version (default language)
596         global $LANG;
597         if ($LANG != DEFAULT_LANGUAGE and $LANG != "en") {
598             $save_lang = $LANG;
599             //trigger_error("DEBUG: findActionPage() ". DEFAULT_LANGUAGE." calling update_locale()...");
600             update_locale(DEFAULT_LANGUAGE);
601             $default = gettext($action);
602             //trigger_error("DEBUG: findActionPage() ". $save_lang." restoring save_lang, calling update_locale()...");
603             update_locale($save_lang);
604             if ($this->_isActionPage($default))
605                 return $cache[$action] = $default;
606         }
607         else {
608             $default = $translation;
609         }
610         
611         // check for english version
612         if ($action != $translation and $action != $default) {
613             if ($this->_isActionPage($action))
614                 return $cache[$action] = $action;
615         }
616
617         trigger_error("$action: Cannot find action page", E_USER_NOTICE);
618         return $cache[$action] = false;
619     }
620     
621     function isActionPage ($pagename) {
622         return $this->findActionPage($pagename);
623     }
624
625     function action_browse () {
626         $this->buffer_output();
627         include_once("lib/display.php");
628         displayPage($this);
629     }
630
631     function action_verify () {
632         $this->action_browse();
633     }
634
635     function actionpage ($action) {
636         $this->buffer_output();
637         include_once("lib/display.php");
638         actionPage($this, $action);
639     }
640
641     function action_diff () {
642         $this->buffer_output();
643         include_once "lib/diff.php";
644         showDiff($this);
645     }
646
647     function action_search () {
648         // This is obsolete: reformulate URL and redirect.
649         // FIXME: this whole section should probably be deleted.
650         if ($this->getArg('searchtype') == 'full') {
651             $search_page = _("FullTextSearch");
652         }
653         else {
654             $search_page = _("TitleSearch");
655         }
656         $this->redirect(WikiURL($search_page,
657                                 array('s' => $this->getArg('searchterm')),
658                                 'absolute_url'));
659     }
660
661     function action_edit () {
662         $this->buffer_output();
663         include "lib/editpage.php";
664         $e = new PageEditor ($this);
665         $e->editPage();
666     }
667
668     function action_create () {
669         $this->action_edit();
670     }
671     
672     function action_viewsource () {
673         $this->buffer_output();
674         include "lib/editpage.php";
675         $e = new PageEditor ($this);
676         $e->viewSource();
677     }
678
679     function action_lock () {
680         $page = $this->getPage();
681         $page->set('locked', true);
682         $this->action_browse();
683     }
684
685     function action_unlock () {
686         // FIXME: This check is redundant.
687         //$user->requireAuth(WIKIAUTH_ADMIN);
688         $page = $this->getPage();
689         $page->set('locked', false);
690         $this->action_browse();
691     }
692
693     function action_remove () {
694         // FIXME: This check is redundant.
695         //$user->requireAuth(WIKIAUTH_ADMIN);
696         $pagename = $this->getArg('pagename');
697         if (strstr($pagename,_('PhpWikiAdministration'))) {
698             $this->action_browse();
699         } else {
700             include('lib/removepage.php');
701             RemovePage($this);
702         }
703     }
704
705
706     function action_upload () {
707         include_once("lib/loadsave.php");
708         LoadPostFile($this);
709     }
710
711     function action_xmlrpc () {
712         include_once("lib/XmlRpcServer.php");
713         $xmlrpc = new XmlRpcServer($this);
714         $xmlrpc->service();
715     }
716     
717     function action_zip () {
718         include_once("lib/loadsave.php");
719         MakeWikiZip($this);
720         // I don't think it hurts to add cruft at the end of the zip file.
721         echo "\n========================================================\n";
722         echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
723     }
724
725     function action_ziphtml () {
726         include_once("lib/loadsave.php");
727         MakeWikiZipHtml($this);
728         // I don't think it hurts to add cruft at the end of the zip file.
729         echo "\n========================================================\n";
730         echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
731     }
732
733     function action_dumpserial () {
734         include_once("lib/loadsave.php");
735         DumpToDir($this);
736     }
737
738     function action_dumphtml () {
739         include_once("lib/loadsave.php");
740         DumpHtmlToDir($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     // initialize again with user's prefs
807     $request->initializeTheme();
808     $request->initializeLang();
809     
810     // Enable the output of most of the warning messages.
811     // The warnings will screw up zip files though.
812     global $ErrorManager;
813     if (substr($request->getArg('action'), 0, 3) != 'zip') {
814         $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
815         //$ErrorManager->setPostponedErrorMask(0);
816     }
817
818     //FIXME:
819     //if ($user->is_authenticated())
820     //  $LogEntry->user = $user->getId();
821
822     $request->possiblyDeflowerVirginWiki();
823     
824 if(defined('WIKI_XMLRPC')) return;
825
826     $validators = array('wikiname' => WIKI_NAME,
827                         'args'     => hash($request->getArgs()),
828                         'prefs'    => hash($request->getPrefs()));
829     if (CACHE_CONTROL == 'STRICT') {
830         $dbi = $request->getDbh();
831         $timestamp = $dbi->getTimestamp();
832         $validators['mtime'] = $timestamp;
833         $validators['%mtime'] = (int)$timestamp;
834     }
835     // FIXME: we should try to generate strong validators when possible,
836     // but for now, our validator is weak, since equal validators do not
837     // indicate byte-level equality of content.  (Due to DEBUG timing output, etc...)
838     //
839     // (If DEBUG if off, this may be a strong validator, but I'm going
840     // to go the paranoid route here pending further study and testing.)
841     //
842     $validators['%weak'] = true;
843     
844     $request->setValidators($validators);
845    
846     $request->handleAction();
847
848 if (defined('DEBUG') and DEBUG>1) phpinfo(INFO_VARIABLES);
849     $request->finish();
850 }
851
852
853 main();
854
855
856 // $Log: not supported by cvs2svn $
857 // Revision 1.108  2004/01/28 14:34:14  rurban
858 // session table takes the common prefix
859 // + various minor stuff
860 // reallow password changing
861 //
862 // Revision 1.107  2004/01/27 23:23:39  rurban
863 // renamed ->Username => _userid for consistency
864 // renamed mayCheckPassword => mayCheckPass
865 // fixed recursion problem in WikiUserNew
866 // fixed bogo login (but not quite 100% ready yet, password storage)
867 //
868 // Revision 1.106  2004/01/26 09:17:49  rurban
869 // * changed stored pref representation as before.
870 //   the array of objects is 1) bigger and 2)
871 //   less portable. If we would import packed pref
872 //   objects and the object definition was changed, PHP would fail.
873 //   This doesn't happen with an simple array of non-default values.
874 // * use $prefs->retrieve and $prefs->store methods, where retrieve
875 //   understands the interim format of array of objects also.
876 // * simplified $prefs->get() and fixed $prefs->set()
877 // * added $user->_userid and class '_WikiUser' portability functions
878 // * fixed $user object ->_level upgrading, mostly using sessions.
879 //   this fixes yesterdays problems with loosing authorization level.
880 // * fixed WikiUserNew::checkPass to return the _level
881 // * fixed WikiUserNew::isSignedIn
882 // * added explodePageList to class PageList, support sortby arg
883 // * fixed UserPreferences for WikiUserNew
884 // * fixed WikiPlugin for empty defaults array
885 // * UnfoldSubpages: added pagename arg, renamed pages arg,
886 //   removed sort arg, support sortby arg
887 //
888 // Revision 1.105  2004/01/25 03:57:15  rurban
889 // WikiUserNew support (temp. ENABLE_USER_NEW constant)
890 //
891 // Revision 1.104  2003/12/26 06:41:16  carstenklapp
892 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
893 // so they don't prevent IE from partially (or not at all) rendering the
894 // page. This should help a little for the IE user who encounters trouble
895 // when setting up a new PhpWiki for the first time.
896 //
897 // Revision 1.103  2003/12/02 00:10:00  carstenklapp
898 // Bugfix: Ongoing work to untangle UserPreferences/WikiUser/request code
899 // mess: UserPreferences should take effect immediately now upon signing
900 // in.
901 //
902 // Revision 1.102  2003/11/25 22:55:32  carstenklapp
903 // Localization bugfix: For wikis where English is not the default system
904 // language, make sure that the authority error message (i.e. "You must
905 // sign in to edit pages in this wiki" etc.) is displayed in the wiki's
906 // default language. Previously it would always display in English.
907 // (Added call to update_locale() before displaying any messages prior to
908 // the login prompt.)
909 //
910 // Revision 1.101  2003/11/25 21:49:44  carstenklapp
911 // Bugfix: For a non-english wiki or when the user's preference is not
912 // english, the wiki would always use the english ActionPage first if it
913 // was present rather than the appropriate localised variant. (PhpWikis
914 // running only in english or Wikis running ONLY without any english
915 // ActionPages would not notice this bug, only when both english and
916 // localised ActionPages were in the DB.) Now we check for the localised
917 // variant first.
918 //
919 // Revision 1.100  2003/11/18 16:54:18  carstenklapp
920 // Reformatting only: Tabs to spaces, added rcs log.
921 //
922
923
924 // Local Variables:
925 // mode: php
926 // tab-width: 8
927 // c-basic-offset: 4
928 // c-hanging-comment-ender-p: nil
929 // indent-tabs-mode: nil
930 // End:
931 ?>