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