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