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