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