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