]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/main.php
use default pref mysql table
[SourceForge/phpwiki.git] / lib / main.php
1 <?php //-*-php-*-
2 rcs_id('$Id: main.php,v 1.123 2004-03-10 15:41:27 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                 return WIKIAUTH_ADMIN;
394             default:
395                 global $WikiNameRegexp;
396                 if (preg_match("/$WikiNameRegexp\Z/A", $action))
397                     return WIKIAUTH_ANON; // ActionPage.
398                 else
399                     return WIKIAUTH_ADMIN;
400           }
401         }
402     }
403     /* End of Permission system */
404
405     function possiblyDeflowerVirginWiki () {
406         if ($this->getArg('action') != 'browse')
407             return;
408         if ($this->getArg('pagename') != HOME_PAGE)
409             return;
410
411         $page = $this->getPage();
412         $current = $page->getCurrentRevision();
413         if ($current->getVersion() > 0)
414             return;             // Homepage exists.
415
416         include('lib/loadsave.php');
417         SetupWiki($this);
418         $this->finish();        // NORETURN
419     }
420
421     function handleAction () {
422         $action = $this->getArg('action');
423         $method = "action_$action";
424         if (method_exists($this, $method)) {
425             $this->{$method}();
426         }
427         elseif ($page = $this->findActionPage($action)) {
428             $this->actionpage($page);
429         }
430         else {
431             $this->finish(fmt("%s: Bad action", $action));
432         }
433     }
434     
435     function finish ($errormsg = false) {
436         static $in_exit = 0;
437
438         if ($in_exit)
439             exit();        // just in case CloseDataBase calls us
440         $in_exit = true;
441
442         if (!empty($this->_dbi))
443             $this->_dbi->close();
444         unset($this->_dbi);
445
446
447         global $ErrorManager;
448         $ErrorManager->flushPostponedErrors();
449
450         if (!empty($errormsg)) {
451             PrintXML(HTML::br(),
452                      HTML::hr(),
453                      HTML::h2(_("Fatal PhpWiki Error")),
454                      $errormsg);
455             // HACK:
456             echo "\n</body></html>";
457         }
458
459         Request::finish();
460         exit;
461     }
462
463     function _deducePagename () {
464         if ($this->getArg('pagename'))
465             return $this->getArg('pagename');
466
467         if (USE_PATH_INFO) {
468             $pathinfo = $this->get('PATH_INFO');
469             $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
470
471             if ($tail && $pathinfo == PATH_INFO_PREFIX . $tail) {
472                 return $tail;
473             }
474         }
475         elseif ($this->isPost()) {
476             /*
477              * In general, for security reasons, HTTP_GET_VARS should be ignored
478              * on POST requests, but we make an exception here (only for pagename).
479              *
480              * The justifcation for this hack is the following
481              * asymmetry: When POSTing with USE_PATH_INFO set, the
482              * pagename can (and should) be communicated through the
483              * request URL via PATH_INFO.  When POSTing with
484              * USE_PATH_INFO off, this cannot be done --- the only way
485              * to communicate the pagename through the URL is via
486              * QUERY_ARGS (HTTP_GET_VARS).
487              */
488             global $HTTP_GET_VARS;
489             if (isset($HTTP_GET_VARS['pagename'])) { 
490                 return $HTTP_GET_VARS['pagename'];
491             }
492         }
493
494         /*
495          * Support for PhpWiki 1.2 style requests.
496          */
497         $query_string = $this->get('QUERY_STRING');
498         if (preg_match('/^[^&=]+$/', $query_string)) {
499             return urldecode($query_string);
500         }
501
502         return HOME_PAGE;
503     }
504
505     function _deduceAction () {
506         if (!($action = $this->getArg('action'))) {
507             // Detect XML-RPC requests
508             if ($this->isPost()
509                 && $this->get('CONTENT_TYPE') == 'text/xml') {
510                 global $HTTP_RAW_POST_DATA;
511                 if (strstr($HTTP_RAW_POST_DATA, '<methodCall>')) {
512                     return 'xmlrpc';
513                 }
514             }
515
516             return 'browse';    // Default if no action specified.
517         }
518
519         if (method_exists($this, "action_$action"))
520             return $action;
521
522         // Allow for, e.g. action=LikePages
523         if ($this->isActionPage($action))
524             return $action;
525
526         trigger_error("$action: Unknown action", E_USER_NOTICE);
527         return 'browse';
528     }
529
530     function _deduceUsername() {
531         if (!empty($this->args['auth']) and !empty($this->args['auth']['userid']))
532             return $this->args['auth']['userid'];
533         if (!empty($_SERVER['PHP_AUTH_USER']))
534             return $_SERVER['PHP_AUTH_USER'];
535             
536         if ($user = $this->getSessionVar('wiki_user')) {
537             $this->_user = $user;
538             $this->_user->_authhow = 'session';
539             return ENABLE_USER_NEW ? $user->UserName() : $this->_user;
540         }
541         if ($userid = $this->getCookieVar('WIKI_ID')) {
542             if (!empty($this->_user))
543                 $this->_user->authhow = 'cookie';
544             return $userid;
545         }
546         return false;
547     }
548     
549     function _isActionPage ($pagename) {
550         $dbi = $this->getDbh();
551         $page = $dbi->getPage($pagename);
552         $rev = $page->getCurrentRevision();
553         // FIXME: more restrictive check for sane plugin?
554         if (strstr($rev->getPackedContent(), '<?plugin'))
555             return true;
556         if (!$rev->hasDefaultContents())
557             trigger_error("$pagename: Does not appear to be an 'action page'", E_USER_NOTICE);
558         return false;
559     }
560
561     function findActionPage ($action) {
562         static $cache;
563
564         // check for translated version, as per users preferred language
565         // (or system default in case it is not en)
566         $translation = gettext($action);
567
568         if (isset($cache) and isset($cache[$translation]))
569             return $cache[$translation];
570
571         // check for cached translated version
572         if ($this->_isActionPage($translation))
573             return $cache[$action] = $translation;
574
575         // Allow for, e.g. action=LikePages
576         global $WikiNameRegexp;
577         if (!preg_match("/$WikiNameRegexp\\Z/A", $action))
578             return $cache[$action] = false;
579
580         // check for translated version (default language)
581         global $LANG;
582         if ($LANG != DEFAULT_LANGUAGE and $LANG != "en") {
583             $save_lang = $LANG;
584             //trigger_error("DEBUG: findActionPage() ". DEFAULT_LANGUAGE." calling update_locale()...");
585             update_locale(DEFAULT_LANGUAGE);
586             $default = gettext($action);
587             //trigger_error("DEBUG: findActionPage() ". $save_lang." restoring save_lang, calling update_locale()...");
588             update_locale($save_lang);
589             if ($this->_isActionPage($default))
590                 return $cache[$action] = $default;
591         }
592         else {
593             $default = $translation;
594         }
595         
596         // check for english version
597         if ($action != $translation and $action != $default) {
598             if ($this->_isActionPage($action))
599                 return $cache[$action] = $action;
600         }
601
602         trigger_error("$action: Cannot find action page", E_USER_NOTICE);
603         return $cache[$action] = false;
604     }
605     
606     function isActionPage ($pagename) {
607         return $this->findActionPage($pagename);
608     }
609
610     function action_browse () {
611         $this->buffer_output();
612         include_once("lib/display.php");
613         displayPage($this);
614     }
615
616     function action_verify () {
617         $this->action_browse();
618     }
619
620     function actionpage ($action) {
621         $this->buffer_output();
622         include_once("lib/display.php");
623         actionPage($this, $action);
624     }
625
626     function action_diff () {
627         $this->buffer_output();
628         include_once "lib/diff.php";
629         showDiff($this);
630     }
631
632     function action_search () {
633         // This is obsolete: reformulate URL and redirect.
634         // FIXME: this whole section should probably be deleted.
635         if ($this->getArg('searchtype') == 'full') {
636             $search_page = _("FullTextSearch");
637         }
638         else {
639             $search_page = _("TitleSearch");
640         }
641         $this->redirect(WikiURL($search_page,
642                                 array('s' => $this->getArg('searchterm')),
643                                 'absolute_url'));
644     }
645
646     function action_edit () {
647         $this->buffer_output();
648         include "lib/editpage.php";
649         $e = new PageEditor ($this);
650         $e->editPage();
651     }
652
653     function action_create () {
654         $this->action_edit();
655     }
656     
657     function action_viewsource () {
658         $this->buffer_output();
659         include "lib/editpage.php";
660         $e = new PageEditor ($this);
661         $e->viewSource();
662     }
663
664     function action_lock () {
665         $page = $this->getPage();
666         $page->set('locked', true);
667         $this->action_browse();
668     }
669
670     function action_unlock () {
671         // FIXME: This check is redundant.
672         //$user->requireAuth(WIKIAUTH_ADMIN);
673         $page = $this->getPage();
674         $page->set('locked', false);
675         $this->action_browse();
676     }
677
678     function action_remove () {
679         // FIXME: This check is redundant.
680         //$user->requireAuth(WIKIAUTH_ADMIN);
681         $pagename = $this->getArg('pagename');
682         if (strstr($pagename,_('PhpWikiAdministration'))) {
683             $this->action_browse();
684         } else {
685             include('lib/removepage.php');
686             RemovePage($this);
687         }
688     }
689
690     function action_xmlrpc () {
691         include_once("lib/XmlRpcServer.php");
692         $xmlrpc = new XmlRpcServer($this);
693         $xmlrpc->service();
694     }
695     
696     function action_zip () {
697         include_once("lib/loadsave.php");
698         MakeWikiZip($this);
699         // I don't think it hurts to add cruft at the end of the zip file.
700         echo "\n========================================================\n";
701         echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
702     }
703
704     function action_ziphtml () {
705         include_once("lib/loadsave.php");
706         MakeWikiZipHtml($this);
707         // I don't think it hurts to add cruft at the end of the zip file.
708         echo "\n========================================================\n";
709         echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
710     }
711
712     function action_dumpserial () {
713         include_once("lib/loadsave.php");
714         DumpToDir($this);
715     }
716
717     function action_dumphtml () {
718         include_once("lib/loadsave.php");
719         DumpHtmlToDir($this);
720     }
721
722     function action_upload () {
723         include_once("lib/loadsave.php");
724         LoadPostFile($this);
725     }
726
727     function action_upgrade () {
728         include_once("lib/upgrade.php");
729         DoUpgrade($this);
730     }
731
732     function action_loadfile () {
733         include_once("lib/loadsave.php");
734         LoadFileOrDir($this);
735     }
736 }
737
738 //FIXME: deprecated
739 function is_safe_action ($action) {
740     return WikiRequest::requiredAuthorityForAction($action) < WIKIAUTH_ADMIN;
741 }
742
743 function validateSessionPath() {
744     // Try to defer any session.save_path PHP errors before any html
745     // is output, which causes some versions of IE to display a blank
746     // page (due to its strict mode while parsing a page?).
747     if (! is_writeable(ini_get('session.save_path'))) {
748         $tmpdir = '/tmp';
749         trigger_error
750             (sprintf(_("%s is not writable."),
751                      _("The session.save_path directory"))
752              . "\n"
753              . sprintf(_("Please ensure that %s is writable, or redefine %s in index.php."),
754                        sprintf(_("the directory '%s'"),
755                                ini_get('session.save_path')),
756                        'session.save_path')
757              . "\n"
758              . sprintf(_("Attempting to use the directory '%s' instead."),
759                        $tmpdir)
760              , E_USER_NOTICE);
761         if (! is_writeable($tmpdir)) {
762             trigger_error
763                 (sprintf(_("%s is not writable."), $tmpdir)
764                  . "\n"
765                  . _("Users will not be able to sign in.")
766                  , E_USER_NOTICE);
767         }
768         else
769             ini_set('session.save_path', $tmpdir);
770     }
771 }
772
773 function main () {
774     if (!USE_DB_SESSION)
775         validateSessionPath();
776
777     global $request;
778
779     $request = new WikiRequest();
780
781     /*
782      * Allow for disabling of markup cache.
783      * (Mostly for debugging ... hopefully.)
784      *
785      * See also <?plugin WikiAdminUtils action=purge-cache ?>
786      */
787     if (!defined('WIKIDB_NOCACHE_MARKUP') and $request->getArg('nocache'))
788         define('WIKIDB_NOCACHE_MARKUP', $request->getArg('nocache'));
789     
790     // Initialize with system defaults in case user not logged in.
791     // Should this go into constructor?
792     $request->initializeTheme();
793
794     $request->updateAuthAndPrefs();
795     $request->initializeLang();
796     
797     // Enable the output of most of the warning messages.
798     // The warnings will screw up zip files though.
799     global $ErrorManager;
800     if (substr($request->getArg('action'), 0, 3) != 'zip') {
801         $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
802         //$ErrorManager->setPostponedErrorMask(0);
803     }
804
805     //FIXME:
806     //if ($user->is_authenticated())
807     //  $LogEntry->user = $user->getId();
808
809     $request->possiblyDeflowerVirginWiki();
810     
811 if (defined('WIKI_XMLRPC') and WIKI_XMLRPC) return;
812 if (defined('WIKI_SOAP')   and WIKI_SOAP)   return;
813
814     $validators = array('wikiname' => WIKI_NAME,
815                         'args'     => hash($request->getArgs()),
816                         'prefs'    => hash($request->getPrefs()));
817     if (CACHE_CONTROL == 'STRICT') {
818         $dbi = $request->getDbh();
819         $timestamp = $dbi->getTimestamp();
820         $validators['mtime'] = $timestamp;
821         $validators['%mtime'] = (int)$timestamp;
822     }
823     // FIXME: we should try to generate strong validators when possible,
824     // but for now, our validator is weak, since equal validators do not
825     // indicate byte-level equality of content.  (Due to DEBUG timing output, etc...)
826     //
827     // (If DEBUG if off, this may be a strong validator, but I'm going
828     // to go the paranoid route here pending further study and testing.)
829     //
830     $validators['%weak'] = true;
831     
832     $request->setValidators($validators);
833    
834     $request->handleAction();
835
836 if (defined('DEBUG') and DEBUG & 4) phpinfo(INFO_VARIABLES);
837     $request->finish();
838 }
839
840 $x = error_reporting(); // why is it 1 here? should be E_ALL
841 error_reporting(E_ALL);
842 main();
843
844
845 // $Log: not supported by cvs2svn $
846 // Revision 1.122  2004/03/08 18:17:09  rurban
847 // added more WikiGroup::getMembersOf methods, esp. for special groups
848 // fixed $LDAP_SET_OPTIONS
849 // fixed _AuthInfo group methods
850 //
851 // Revision 1.121  2004/03/01 13:48:45  rurban
852 // rename fix
853 // p[] consistency fix
854 //
855 // Revision 1.120  2004/03/01 10:22:41  rurban
856 // initializeTheme optimize
857 //
858 // Revision 1.119  2004/02/26 20:45:06  rurban
859 // check for ALLOW_ANON_USER = false
860 //
861 // Revision 1.118  2004/02/26 01:32:03  rurban
862 // fixed session login with old WikiUser object. strangely, the errormask gets corruoted to 1, Pear???
863 //
864 // Revision 1.117  2004/02/24 17:19:37  rurban
865 // debugging helpers only
866 //
867 // Revision 1.116  2004/02/24 15:17:14  rurban
868 // 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
869 //
870 // Revision 1.115  2004/02/15 21:34:37  rurban
871 // PageList enhanced and improved.
872 // fixed new WikiAdmin... plugins
873 // editpage, Theme with exp. htmlarea framework
874 //   (htmlarea yet committed, this is really questionable)
875 // WikiUser... code with better session handling for prefs
876 // enhanced UserPreferences (again)
877 // RecentChanges for show_deleted: how should pages be deleted then?
878 //
879 // Revision 1.114  2004/02/15 17:30:13  rurban
880 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
881 // fixed getPreferences() (esp. from sessions)
882 // fixed setPreferences() (update and set),
883 // fixed AdoDb DB statements,
884 // update prefs only at UserPreferences POST (for testing)
885 // unified db prefs methods (but in external pref classes yet)
886 //
887 // Revision 1.113  2004/02/12 13:05:49  rurban
888 // Rename functional for PearDB backend
889 // some other minor changes
890 // SiteMap comes with a not yet functional feature request: includepages (tbd)
891 //
892 // Revision 1.112  2004/02/09 03:58:12  rurban
893 // for now default DB_SESSION to false
894 // PagePerm:
895 //   * not existing perms will now query the parent, and not
896 //     return the default perm
897 //   * added pagePermissions func which returns the object per page
898 //   * added getAccessDescription
899 // WikiUserNew:
900 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
901 //   * force init of authdbh in the 2 db classes
902 // main:
903 //   * fixed session handling (not triple auth request anymore)
904 //   * don't store cookie prefs with sessions
905 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
906 //
907 // Revision 1.111  2004/02/07 10:41:25  rurban
908 // fixed auth from session (still double code but works)
909 // fixed GroupDB
910 // fixed DbPassUser upgrade and policy=old
911 // added GroupLdap
912 //
913 // Revision 1.110  2004/02/03 09:45:39  rurban
914 // LDAP cleanup, start of new Pref classes
915 //
916 // Revision 1.109  2004/01/30 19:57:58  rurban
917 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
918 //
919 // Revision 1.108  2004/01/28 14:34:14  rurban
920 // session table takes the common prefix
921 // + various minor stuff
922 // reallow password changing
923 //
924 // Revision 1.107  2004/01/27 23:23:39  rurban
925 // renamed ->Username => _userid for consistency
926 // renamed mayCheckPassword => mayCheckPass
927 // fixed recursion problem in WikiUserNew
928 // fixed bogo login (but not quite 100% ready yet, password storage)
929 //
930 // Revision 1.106  2004/01/26 09:17:49  rurban
931 // * changed stored pref representation as before.
932 //   the array of objects is 1) bigger and 2)
933 //   less portable. If we would import packed pref
934 //   objects and the object definition was changed, PHP would fail.
935 //   This doesn't happen with an simple array of non-default values.
936 // * use $prefs->retrieve and $prefs->store methods, where retrieve
937 //   understands the interim format of array of objects also.
938 // * simplified $prefs->get() and fixed $prefs->set()
939 // * added $user->_userid and class '_WikiUser' portability functions
940 // * fixed $user object ->_level upgrading, mostly using sessions.
941 //   this fixes yesterdays problems with loosing authorization level.
942 // * fixed WikiUserNew::checkPass to return the _level
943 // * fixed WikiUserNew::isSignedIn
944 // * added explodePageList to class PageList, support sortby arg
945 // * fixed UserPreferences for WikiUserNew
946 // * fixed WikiPlugin for empty defaults array
947 // * UnfoldSubpages: added pagename arg, renamed pages arg,
948 //   removed sort arg, support sortby arg
949 //
950 // Revision 1.105  2004/01/25 03:57:15  rurban
951 // WikiUserNew support (temp. ENABLE_USER_NEW constant)
952 //
953 // Revision 1.104  2003/12/26 06:41:16  carstenklapp
954 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
955 // so they don't prevent IE from partially (or not at all) rendering the
956 // page. This should help a little for the IE user who encounters trouble
957 // when setting up a new PhpWiki for the first time.
958 //
959 // Revision 1.103  2003/12/02 00:10:00  carstenklapp
960 // Bugfix: Ongoing work to untangle UserPreferences/WikiUser/request code
961 // mess: UserPreferences should take effect immediately now upon signing
962 // in.
963 //
964 // Revision 1.102  2003/11/25 22:55:32  carstenklapp
965 // Localization bugfix: For wikis where English is not the default system
966 // language, make sure that the authority error message (i.e. "You must
967 // sign in to edit pages in this wiki" etc.) is displayed in the wiki's
968 // default language. Previously it would always display in English.
969 // (Added call to update_locale() before displaying any messages prior to
970 // the login prompt.)
971 //
972 // Revision 1.101  2003/11/25 21:49:44  carstenklapp
973 // Bugfix: For a non-english wiki or when the user's preference is not
974 // english, the wiki would always use the english ActionPage first if it
975 // was present rather than the appropriate localised variant. (PhpWikis
976 // running only in english or Wikis running ONLY without any english
977 // ActionPages would not notice this bug, only when both english and
978 // localised ActionPages were in the DB.) Now we check for the localised
979 // variant first.
980 //
981 // Revision 1.100  2003/11/18 16:54:18  carstenklapp
982 // Reformatting only: Tabs to spaces, added rcs log.
983 //
984
985
986 // Local Variables:
987 // mode: php
988 // tab-width: 8
989 // c-basic-offset: 4
990 // c-hanging-comment-ender-p: nil
991 // indent-tabs-mode: nil
992 // End:
993 ?>