2 rcs_id('$Id: main.php,v 1.142 2004-05-04 22:34:25 rurban Exp $');
4 define ('USE_PREFS_IN_PAGE', true);
6 //include "lib/config.php";
7 require_once("lib/stdlib.php");
8 require_once('lib/Request.php');
9 require_once('lib/WikiDB.php');
11 require_once("lib/WikiUserNew.php");
13 require_once("lib/WikiUser.php");
14 require_once("lib/WikiGroup.php");
15 require_once("lib/PagePerm.php");
17 class WikiRequest extends Request {
20 function WikiRequest () {
21 $this->_dbi = WikiDB::open($GLOBALS['DBParams']);
23 include_once('lib/DB_Session.php');
24 $prefix = isset($GLOBALS['DBParams']['prefix']) ? $GLOBALS['DBParams']['prefix'] : '';
25 if (in_array('File',$GLOBALS['USER_AUTH_ORDER'])) {
26 include_once('lib/pear/File_Passwd.php');
28 $dbi = $this->getDbh();
29 $this->_dbsession = & new DB_Session($dbi,$prefix . $GLOBALS['DBParams']['db_session_table']);
31 // Fixme: Does pear reset the error mask to 1? We have to find the culprit
32 $x = error_reporting();
37 $this->setArg('pagename', $this->_deducePagename());
38 $this->setArg('action', $this->_deduceAction());
40 // Restore auth state. This doesn't check for proper authorization!
41 if (ENABLE_USER_NEW) {
42 $userid = $this->_deduceUsername();
43 if (isset($this->_user) and
44 !empty($this->_user->_authhow) and
45 $this->_user->_authhow == 'session')
47 // users might switch in a session between the two objects.
48 // restore old auth level here or in updateAuthAndPrefs?
49 //$user = $this->getSessionVar('wiki_user');
50 // revive db handle, because these don't survive sessions
51 if (isset($this->_user) and
52 ( ! isa($this->_user,WikiUserClassname())
53 or (strtolower(get_class($this->_user)) == '_passuser')))
55 $this->_user = WikiUser($userid,$this->_user->_prefs);
57 unset($this->_user->_HomePagehandle);
58 $this->_user->hasHomePage();
59 // update the lockfile filehandle
60 if ( isa($this->_user,'_FilePassUser') and
61 $this->_user->_file->lockfile and
62 !$this->_user->_file->fplock )
64 $this->_user = new _FilePassUser($userid,$this->_user->_prefs,$this->_user->_file->filename);
67 if (!isa($user,WikiUserClassname()) or empty($this->_user->_level)) {
68 $user = UpgradeUser($this->_user,$user);
71 $this->_prefs = & $this->_user->_prefs;
73 $user = WikiUser($userid);
74 $this->_user = & $user;
75 $this->_prefs = & $this->_user->_prefs;
78 $this->_user = new WikiUser($this, $this->_deduceUsername());
79 $this->_prefs = $this->_user->getPreferences();
83 function initializeLang () {
84 if ($user_lang = $this->getPref('lang')) {
85 //trigger_error("DEBUG: initializeLang() ". $user_lang ." calling update_locale()...");
86 update_locale($user_lang);
87 FindLocalizedButtonFile(".",'missing_ok','reinit');
91 function initializeTheme () {
95 if ($user_theme = $this->getPref('theme'))
96 include_once("themes/$user_theme/themeinfo.php");
97 if (empty($Theme) and defined('THEME'))
98 include_once("themes/" . THEME . "/themeinfo.php");
100 include_once("themes/default/themeinfo.php");
101 assert(!empty($Theme));
104 // This really maybe should be part of the constructor, but since it
105 // may involve HTML/template output, the global $request really needs
106 // to be initialized before we do this stuff.
107 function updateAuthAndPrefs () {
109 if (isset($this->_user) and (!isa($this->_user,WikiUserClassname()))) {
110 $this->_user = false;
112 // Handle authentication request, if any.
113 if ($auth_args = $this->getArg('auth')) {
114 $this->setArg('auth', false);
115 $this->_handleAuthRequest($auth_args); // possible NORETURN
117 elseif ( ! $this->_user or
118 (isa($this->_user,WikiUserClassname()) and ! $this->_user->isSignedIn())) {
119 // If not auth request, try to sign in as saved user.
120 if (($saved_user = $this->getPref('userid')) != false) {
121 $this->_signIn($saved_user);
125 // Save preferences in session and cookie
126 if (isset($this->_user) and
127 (!isset($this->_user->_authhow) or $this->_user->_authhow != 'session')) {
129 $this->_user->setPreferences($this->_prefs, $id_only);
131 $this->setSessionVar('wiki_user', $this->_user);
132 //$this->setSessionVar('wiki_prefs', $this->_prefs);
135 // Ensure user has permissions for action
136 $require_level = $this->requiredAuthority($this->getArg('action'));
137 if (! $this->_user->hasAuthority($require_level))
138 $this->_notAuthorized($require_level); // NORETURN
141 function getUser () {
142 if (isset($this->_user))
145 return $GLOBALS['ForbiddenUser'];
148 function getPrefs () {
149 return $this->_prefs;
152 // Convenience function:
153 function getPref ($key) {
154 if (isset($this->_prefs))
155 return $this->_prefs->get($key);
163 * Get requested page from the page database.
164 * By default it will grab the page requested via the URL
166 * This is a convenience function.
167 * @param string $pagename Name of page to get.
168 * @return WikiDB_Page Object with methods to pull data from
169 * database for the page requested.
171 function getPage ($pagename = false) {
172 if (!isset($this->_dbi))
175 $pagename = $this->getArg('pagename');
176 return $this->_dbi->getPage($pagename);
179 /** Get URL for POST actions.
181 * Officially, we should just use SCRIPT_NAME (or some such),
182 * but that causes problems when we try to issue a redirect, e.g.
183 * after saving a page.
185 * Some browsers (at least NS4 and Mozilla 0.97 won't accept
186 * a redirect from a page to itself.)
188 * So, as a HACK, we include pagename and action as query args in
189 * the URL. (These should be ignored when we receive the POST
192 function getPostURL ($pagename=false) {
193 if ($pagename === false)
194 $pagename = $this->getArg('pagename');
195 $action = $this->getArg('action');
196 if (!empty($_GET['start_debug'])) // zend ide support
197 return WikiURL($pagename, array('action' => $action, 'start_debug' => 1));
199 return WikiURL($pagename, array('action' => $action));
202 function _handleAuthRequest ($auth_args) {
203 if (!is_array($auth_args))
206 // Ignore password unless POST'ed.
207 if (!$this->isPost())
208 unset($auth_args['passwd']);
210 $olduser = $this->_user;
211 $user = $this->_user->AuthCheck($auth_args);
212 if (isa($user,WikiUserClassname())) {
213 // Successful login (or logout.)
214 $this->_setUser($user);
216 elseif (is_string($user)) {
217 // Login attempt failed.
218 $fail_message = $user;
219 $auth_args['pass_required'] = true;
220 // If no password was submitted, it's not really
221 // a failure --- just need to prompt for password...
222 if (!ALLOW_USER_PASSWORDS
224 and !isset($auth_args['passwd']))
226 $fail_message = false;
228 $olduser->PrintLoginForm($this, $auth_args, $fail_message);
229 $this->finish(); //NORETURN
232 // Login request cancelled.
237 * Attempt to sign in (bogo-login).
241 * @param $userid string Userid to attempt to sign in as.
244 function _signIn ($userid) {
245 if (ENABLE_USER_NEW) {
247 $this->_user = new _BogoUser($userid);
249 $this->_user = new _PassUser($userid);
251 $user = $this->_user->AuthCheck(array('userid' => $userid));
252 if (isa($user,WikiUserClassname())) {
253 $this->_setUser($user); // success!
257 // login or logout or restore state
258 function _setUser ($user) {
259 $this->_user = $user;
260 define('MAIN_setUser',true);
261 $this->setCookieVar('WIKI_ID', $user->getAuthenticatedId(), COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
262 $this->setSessionVar('wiki_user', $user);
263 if ($user->isSignedIn())
264 $user->_authhow = 'signin';
266 // Save userid to prefs..
267 if ( ! $this->_user->_prefs ) {
268 $this->_user->_prefs = $this->_user->getPreferences();
269 $this->_prefs =& $this->_user->_prefs;
271 $this->_prefs->set('userid',
272 $user->isSignedIn() ? $user->getId() : '');
273 $this->initializeTheme();
276 /* Permission system */
278 function _notAuthorized ($require_level) {
279 // Display the authority message in the Wiki's default
280 // language, in case it is not english.
282 // Note that normally a user will not see such an error once
283 // logged in, unless the admin has altered the default
284 // disallowed wikiactions. In that case we should probably
285 // check the user's language prefs too at this point; this
286 // would be a situation which is not really handled with the
288 if (empty($GLOBALS['LANG']))
289 update_locale(DEFAULT_LANGUAGE);
291 // User does not have required authority. Prompt for login.
292 $what = $this->getActionDescription($this->getArg('action'));
294 if ($require_level == WIKIAUTH_UNOBTAINABLE) {
295 if (class_exists('PagePermission'))
296 $this->finish(fmt("%s is disallowed on this wiki for user %s (level: %d).",
297 $this->getDisallowedActionDescription($this->getArg('action')),
298 $this->_user->UserName(),$this->_user->_level));
300 $this->finish(fmt("%s is disallowed on this wiki.",
301 $this->getDisallowedActionDescription($this->getArg('action'))));
303 elseif ($require_level == WIKIAUTH_BOGO)
304 $msg = fmt("You must sign in to %s.", $what);
305 elseif ($require_level == WIKIAUTH_USER)
306 $msg = fmt("You must log in to %s.", $what);
308 $msg = fmt("You must be an administrator to %s.", $what);
309 $pass_required = ($require_level >= WIKIAUTH_USER);
311 $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
312 $this->finish(); // NORETURN
315 // Fixme: for PagePermissions we'll need other strings,
316 // relevant to the requested page, not just for the action on the whole wiki.
317 function getActionDescription($action) {
318 static $actionDescriptions;
319 if (! $actionDescriptions) {
321 = array('browse' => _("view this page"),
322 'diff' => _("diff this page"),
323 'dumphtml' => _("dump html pages"),
324 'dumpserial' => _("dump serial pages"),
325 'edit' => _("edit this page"),
326 'create' => _("create this page"),
327 'loadfile' => _("load files into this wiki"),
328 'lock' => _("lock this page"),
329 'remove' => _("remove this page"),
330 'unlock' => _("unlock this page"),
331 'upload' => _("upload a zip dump"),
332 'verify' => _("verify the current action"),
333 'viewsource' => _("view the source of this page"),
334 'xmlrpc' => _("access this wiki via XML-RPC"),
335 'soap' => _("access this wiki via SOAP"),
336 'zip' => _("download a zip dump from this wiki"),
337 'ziphtml' => _("download an html zip dump from this wiki")
340 if (in_array($action, array_keys($actionDescriptions)))
341 return $actionDescriptions[$action];
345 function getDisallowedActionDescription($action) {
346 static $disallowedActionDescriptions;
347 if (! $disallowedActionDescriptions) {
348 $disallowedActionDescriptions
349 = array('browse' => _("Browsing pages"),
350 'diff' => _("Diffing pages"),
351 'dumphtml' => _("Dumping html pages"),
352 'dumpserial' => _("Dumping serial pages"),
353 'edit' => _("Editing pages"),
354 'create' => _("Creating pages"),
355 'loadfile' => _("Loading files"),
356 'lock' => _("Locking pages"),
357 'remove' => _("Removing pages"),
358 'unlock' => _("Unlocking pages"),
359 'upload' => _("Uploading zip dumps"),
360 'verify' => _("Verify the current action"),
361 'viewsource' => _("Viewing the source of pages"),
362 'xmlrpc' => _("XML-RPC access"),
363 'soap' => _("SOAP access"),
364 'zip' => _("Downloading zip dumps"),
365 'ziphtml' => _("Downloading html zip dumps")
368 if (in_array($action, array_keys($disallowedActionDescriptions)))
369 return $disallowedActionDescriptions[$action];
374 function requiredAuthority ($action) {
375 $auth = $this->requiredAuthorityForAction($action);
376 if (!ALLOW_ANON_USER) return WIKIAUTH_USER;
379 * This is a hook for plugins to require authority
380 * for posting to them.
382 * IMPORTANT: this is not a secure check, so the plugin
383 * may not assume that any POSTs to it are authorized.
384 * All this does is cause PhpWiki to prompt for login
385 * if the user doesn't have the required authority.
387 if ($this->isPost()) {
388 $post_auth = $this->getArg('require_authority_for_post');
389 if ($post_auth !== false)
390 $auth = max($auth, $post_auth);
395 function requiredAuthorityForAction ($action) {
396 if (class_exists("PagePermission")) {
397 return requiredAuthorityForPage($action);
408 return WIKIAUTH_ANON;
412 if (defined('ZIPDUMP_AUTH') && ZIPDUMP_AUTH)
413 return WIKIAUTH_ADMIN;
414 return WIKIAUTH_ANON;
418 if (defined('REQUIRE_SIGNIN_BEFORE_EDIT') && REQUIRE_SIGNIN_BEFORE_EDIT)
419 return WIKIAUTH_BOGO;
420 return WIKIAUTH_ANON;
421 // return WIKIAUTH_BOGO;
424 $page = $this->getPage();
425 $current = $page->getCurrentRevision();
426 if ($current->hasDefaultContents())
427 return $this->requiredAuthorityForAction('edit');
428 return $this->requiredAuthorityForAction('browse');
438 return WIKIAUTH_ADMIN;
440 global $WikiNameRegexp;
441 if (preg_match("/$WikiNameRegexp\Z/A", $action))
442 return WIKIAUTH_ANON; // ActionPage.
444 return WIKIAUTH_ADMIN;
448 /* End of Permission system */
450 function possiblyDeflowerVirginWiki () {
451 if ($this->getArg('action') != 'browse')
453 if ($this->getArg('pagename') != HOME_PAGE)
456 $page = $this->getPage();
457 $current = $page->getCurrentRevision();
458 if ($current->getVersion() > 0)
459 return; // Homepage exists.
461 include('lib/loadsave.php');
463 $this->finish(); // NORETURN
466 function handleAction () {
467 $action = $this->getArg('action');
468 $method = "action_$action";
469 if (method_exists($this, $method)) {
472 elseif ($page = $this->findActionPage($action)) {
473 $this->actionpage($page);
476 $this->finish(fmt("%s: Bad action", $action));
480 function finish ($errormsg = false) {
484 exit(); // just in case CloseDataBase calls us
487 global $ErrorManager;
488 $ErrorManager->flushPostponedErrors();
490 if (!empty($errormsg)) {
493 HTML::h2(_("Fatal PhpWiki Error")),
496 echo "\n</body></html>";
498 if (is_object($this->_user)) {
499 $this->_user->page = $this->getArg('pagename');
500 $this->_user->action = $this->getArg('action');
501 unset($this->_user->_HomePagehandle);
502 unset($this->_user->_auth_dbi);
504 if (!empty($this->_dbi)) {
505 session_write_close();
506 $this->_dbi->close();
513 function _deducePagename () {
514 if ($this->getArg('pagename'))
515 return $this->getArg('pagename');
518 $pathinfo = $this->get('PATH_INFO');
519 $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
521 if ($tail != '' and $pathinfo == PATH_INFO_PREFIX . $tail) {
525 elseif ($this->isPost()) {
527 * In general, for security reasons, HTTP_GET_VARS should be ignored
528 * on POST requests, but we make an exception here (only for pagename).
530 * The justifcation for this hack is the following
531 * asymmetry: When POSTing with USE_PATH_INFO set, the
532 * pagename can (and should) be communicated through the
533 * request URL via PATH_INFO. When POSTing with
534 * USE_PATH_INFO off, this cannot be done --- the only way
535 * to communicate the pagename through the URL is via
536 * QUERY_ARGS (HTTP_GET_VARS).
538 global $HTTP_GET_VARS;
539 if (isset($HTTP_GET_VARS['pagename'])) {
540 return $HTTP_GET_VARS['pagename'];
545 * Support for PhpWiki 1.2 style requests.
547 $query_string = $this->get('QUERY_STRING');
548 if (preg_match('/^[^&=]+$/', $query_string)) {
549 return urldecode($query_string);
555 function _deduceAction () {
556 if (!($action = $this->getArg('action'))) {
557 // Detect XML-RPC requests
559 && $this->get('CONTENT_TYPE') == 'text/xml') {
560 global $HTTP_RAW_POST_DATA;
561 if (strstr($HTTP_RAW_POST_DATA, '<methodCall>')) {
566 return 'browse'; // Default if no action specified.
569 if (method_exists($this, "action_$action"))
572 // Allow for, e.g. action=LikePages
573 if ($this->isActionPage($action))
576 trigger_error("$action: Unknown action", E_USER_NOTICE);
580 function _deduceUsername() {
581 global $HTTP_SERVER_VARS, $HTTP_ENV_VARS;
582 if (!empty($this->args['auth']) and !empty($this->args['auth']['userid']))
583 return $this->args['auth']['userid'];
584 if (!empty($HTTP_SERVER_VARS['PHP_AUTH_USER']))
585 return $HTTP_SERVER_VARS['PHP_AUTH_USER'];
586 if (!empty($HTTP_ENV_VARS['REMOTE_USER']))
587 return $HTTP_ENV_VARS['REMOTE_USER'];
589 if ($user = $this->getSessionVar('wiki_user')) {
590 $this->_user = $user;
591 $this->_user->_authhow = 'session';
592 return ENABLE_USER_NEW ? $user->UserName() : $this->_user;
594 if ($userid = $this->getCookieVar('WIKI_ID')) {
595 if (!empty($userid) and substr($userid,0,2) != 's:') {
596 $this->_user->authhow = 'cookie';
603 function _isActionPage ($pagename) {
604 $dbi = $this->getDbh();
605 $page = $dbi->getPage($pagename);
606 $rev = $page->getCurrentRevision();
607 // FIXME: more restrictive check for sane plugin?
608 if (strstr($rev->getPackedContent(), '<?plugin'))
610 if (!$rev->hasDefaultContents())
611 trigger_error("$pagename: Does not appear to be an 'action page'", E_USER_NOTICE);
615 function findActionPage ($action) {
618 // check for translated version, as per users preferred language
619 // (or system default in case it is not en)
620 $translation = gettext($action);
622 if (isset($cache) and isset($cache[$translation]))
623 return $cache[$translation];
625 // check for cached translated version
626 if ($this->_isActionPage($translation))
627 return $cache[$action] = $translation;
629 // Allow for, e.g. action=LikePages
630 global $WikiNameRegexp;
631 if (!preg_match("/$WikiNameRegexp\\Z/A", $action))
632 return $cache[$action] = false;
634 // check for translated version (default language)
636 if ($LANG != DEFAULT_LANGUAGE and $LANG != "en") {
638 //trigger_error("DEBUG: findActionPage() ". DEFAULT_LANGUAGE." calling update_locale()...");
639 update_locale(DEFAULT_LANGUAGE);
640 $default = gettext($action);
641 //trigger_error("DEBUG: findActionPage() ". $save_lang." restoring save_lang, calling update_locale()...");
642 update_locale($save_lang);
643 if ($this->_isActionPage($default))
644 return $cache[$action] = $default;
647 $default = $translation;
650 // check for english version
651 if ($action != $translation and $action != $default) {
652 if ($this->_isActionPage($action))
653 return $cache[$action] = $action;
656 trigger_error("$action: Cannot find action page", E_USER_NOTICE);
657 return $cache[$action] = false;
660 function isActionPage ($pagename) {
661 return $this->findActionPage($pagename);
664 function action_browse () {
665 $this->buffer_output();
666 include_once("lib/display.php");
670 function action_verify () {
671 $this->action_browse();
674 function actionpage ($action) {
675 $this->buffer_output();
676 include_once("lib/display.php");
677 actionPage($this, $action);
680 function action_diff () {
681 $this->buffer_output();
682 include_once "lib/diff.php";
686 function action_search () {
687 // This is obsolete: reformulate URL and redirect.
688 // FIXME: this whole section should probably be deleted.
689 if ($this->getArg('searchtype') == 'full') {
690 $search_page = _("FullTextSearch");
693 $search_page = _("TitleSearch");
695 $this->redirect(WikiURL($search_page,
696 array('s' => $this->getArg('searchterm')),
700 function action_edit () {
701 $this->buffer_output();
702 include "lib/editpage.php";
703 $e = new PageEditor ($this);
707 function action_create () {
708 $this->action_edit();
711 function action_viewsource () {
712 $this->buffer_output();
713 include "lib/editpage.php";
714 $e = new PageEditor ($this);
718 function action_lock () {
719 $page = $this->getPage();
720 $page->set('locked', true);
721 $this->action_browse();
724 function action_unlock () {
725 // FIXME: This check is redundant.
726 //$user->requireAuth(WIKIAUTH_ADMIN);
727 $page = $this->getPage();
728 $page->set('locked', false);
729 $this->action_browse();
732 function action_remove () {
733 // FIXME: This check is redundant.
734 //$user->requireAuth(WIKIAUTH_ADMIN);
735 $pagename = $this->getArg('pagename');
736 if (strstr($pagename,_('PhpWikiAdministration'))) {
737 $this->action_browse();
739 include('lib/removepage.php');
744 function action_xmlrpc () {
745 include_once("lib/XmlRpcServer.php");
746 $xmlrpc = new XmlRpcServer($this);
750 function action_zip () {
751 include_once("lib/loadsave.php");
753 // I don't think it hurts to add cruft at the end of the zip file.
754 echo "\n========================================================\n";
755 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
758 function action_ziphtml () {
759 include_once("lib/loadsave.php");
760 MakeWikiZipHtml($this);
761 // I don't think it hurts to add cruft at the end of the zip file.
762 echo "\n========================================================\n";
763 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
766 function action_dumpserial () {
767 include_once("lib/loadsave.php");
771 function action_dumphtml () {
772 include_once("lib/loadsave.php");
773 DumpHtmlToDir($this);
776 function action_upload () {
777 include_once("lib/loadsave.php");
781 function action_upgrade () {
782 include_once("lib/loadsave.php");
783 include_once("lib/upgrade.php");
787 function action_loadfile () {
788 include_once("lib/loadsave.php");
789 LoadFileOrDir($this);
792 function action_pdf () {
793 $this->buffer_output('nocompress');
794 if ($GLOBALS['LANG'] == 'ja') {
795 include_once("lib/fpdf/japanese.php");
796 $pdf = new PDF_Japanese;
797 } elseif ($GLOBALS['LANG'] == 'zh') {
798 include_once("lib/fpdf/chinese.php");
799 $pdf = new PDF_Chinese;
801 include_once("lib/pdf.php");
804 include_once("lib/display.php");
806 $html = ob_get_contents();
809 $pdf->ConvertFromHTML($html);
810 $this->discardOutput();
812 $this->buffer_output('nocompress');
814 $GLOBALS['ErrorManager']->flushPostponedErrors();
815 if (!empty($errormsg)) {
816 $this->discardOutput();
819 HTML::h2(_("Fatal PhpWiki Error")),
821 echo "\n</body></html>";
829 function is_safe_action ($action) {
830 return WikiRequest::requiredAuthorityForAction($action) < WIKIAUTH_ADMIN;
833 function validateSessionPath() {
834 // Try to defer any session.save_path PHP errors before any html
835 // is output, which causes some versions of IE to display a blank
836 // page (due to its strict mode while parsing a page?).
837 if (! is_writeable(ini_get('session.save_path'))) {
840 (sprintf(_("%s is not writable."),
841 _("The session.save_path directory"))
843 . sprintf(_("Please ensure that %s is writable, or redefine %s in index.php."),
844 sprintf(_("the directory '%s'"),
845 ini_get('session.save_path')),
848 . sprintf(_("Attempting to use the directory '%s' instead."),
851 if (! is_writeable($tmpdir)) {
853 (sprintf(_("%s is not writable."), $tmpdir)
855 . _("Users will not be able to sign in.")
859 ini_set('session.save_path', $tmpdir);
865 validateSessionPath();
869 if (DEBUG and extension_loaded("apd"))
870 apd_set_session_trace(9);
871 $request = new WikiRequest();
874 * Allow for disabling of markup cache.
875 * (Mostly for debugging ... hopefully.)
877 * See also <?plugin WikiAdminUtils action=purge-cache ?>
879 if (!defined('WIKIDB_NOCACHE_MARKUP') and $request->getArg('nocache'))
880 define('WIKIDB_NOCACHE_MARKUP', $request->getArg('nocache'));
882 // Initialize with system defaults in case user not logged in.
883 // Should this go into constructor?
884 $request->initializeTheme();
886 $request->updateAuthAndPrefs();
887 $request->initializeLang();
889 // Enable the output of most of the warning messages.
890 // The warnings will screw up zip files though.
891 global $ErrorManager;
892 $action = $request->getArg('action');
893 if (substr($action, 0, 3) != 'zip') {
894 if ($action == 'pdf')
895 $ErrorManager->setPostponedErrorMask(0);
897 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
901 //if ($user->is_authenticated())
902 // $LogEntry->user = $user->getId();
904 $request->possiblyDeflowerVirginWiki();
906 if (defined('WIKI_XMLRPC') and WIKI_XMLRPC) return;
907 if (defined('WIKI_SOAP') and WIKI_SOAP) return;
909 $validators = array('wikiname' => WIKI_NAME,
910 'args' => hash($request->getArgs()),
911 'prefs' => hash($request->getPrefs()));
912 if (CACHE_CONTROL == 'STRICT') {
913 $dbi = $request->getDbh();
914 $timestamp = $dbi->getTimestamp();
915 $validators['mtime'] = $timestamp;
916 $validators['%mtime'] = (int)$timestamp;
918 // FIXME: we should try to generate strong validators when possible,
919 // but for now, our validator is weak, since equal validators do not
920 // indicate byte-level equality of content. (Due to DEBUG timing output, etc...)
922 // (If DEBUG if off, this may be a strong validator, but I'm going
923 // to go the paranoid route here pending further study and testing.)
925 $validators['%weak'] = true;
926 $request->setValidators($validators);
928 $request->handleAction();
930 if (defined('DEBUG') and DEBUG & 4) phpinfo(INFO_VARIABLES);
934 $x = error_reporting(); // why is it 1 here? should be E_ALL
935 error_reporting(E_ALL);
939 // $Log: not supported by cvs2svn $
940 // Revision 1.141 2004/05/03 13:16:47 rurban
941 // fixed UserPreferences update, esp for boolean and int
943 // Revision 1.140 2004/05/02 21:26:38 rurban
944 // limit user session data (HomePageHandle and auth_dbi have to invalidated anyway)
945 // because they will not survive db sessions, if too large.
946 // extended action=upgrade
947 // some WikiTranslation button work
948 // revert WIKIAUTH_UNOBTAINABLE (need it for main.php)
949 // some temp. session debug statements
951 // Revision 1.139 2004/05/02 15:10:07 rurban
952 // new finally reliable way to detect if /index.php is called directly
953 // and if to include lib/main.php
954 // new global AllActionPages
955 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
956 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
957 // PageGroupTestOne => subpages
958 // renamed PhpWikiRss to PhpWikiRecentChanges
959 // more docs, default configs, ...
961 // Revision 1.138 2004/05/01 15:59:29 rurban
962 // more php-4.0.6 compatibility: superglobals
964 // Revision 1.137 2004/04/29 19:39:44 rurban
965 // special support for formatted plugins (one-liners)
966 // like <small><plugin BlaBla ></small>
967 // iter->asArray() helper for PopularNearby
968 // db_session for older php's (no &func() allowed)
970 // Revision 1.136 2004/04/29 17:18:19 zorloc
971 // Fixes permission failure issues. With PagePermissions and Disabled Actions when user did not have permission WIKIAUTH_FORBIDDEN was returned. In WikiUser this was ok because WIKIAUTH_FORBIDDEN had a value of 11 -- thus no user could perform that action. But WikiUserNew has a WIKIAUTH_FORBIDDEN value of -1 -- thus a user without sufficent permission to do anything. The solution is a new high value permission level (WIKIAUTH_UNOBTAINABLE) to be the default level for access failure.
973 // Revision 1.135 2004/04/26 12:15:01 rurban
974 // check default config values
976 // Revision 1.134 2004/04/23 06:46:37 zorloc
977 // Leave DB connection open when USE_DB_SESSION is true so that session info can be written to the DB.
979 // Revision 1.133 2004/04/20 18:10:31 rurban
980 // config refactoring:
981 // FileFinder is needed for WikiFarm scripts calling index.php
982 // config run-time calls moved to lib/IniConfig.php:fix_configs()
983 // added PHPWIKI_DIR smart-detection code (Theme finder)
984 // moved FileFind to lib/FileFinder.php
985 // cleaned lib/config.php
987 // Revision 1.132 2004/04/19 21:51:41 rurban
988 // php5 compatibility: it works!
990 // Revision 1.131 2004/04/19 18:27:45 rurban
991 // Prevent from some PHP5 warnings (ref args, no :: object init)
992 // php5 runs now through, just one wrong XmlElement object init missing
993 // Removed unneccesary UpgradeUser lines
994 // Changed WikiLink to omit version if current (RecentChanges)
996 // Revision 1.130 2004/04/18 00:25:53 rurban
997 // allow "0" pagename
999 // Revision 1.129 2004/04/07 23:13:19 rurban
1000 // fixed pear/File_Passwd for Windows
1001 // fixed FilePassUser sessions (filehandle revive) and password update
1003 // Revision 1.128 2004/04/02 15:06:55 rurban
1004 // fixed a nasty ADODB_mysql session update bug
1005 // improved UserPreferences layout (tabled hints)
1006 // fixed UserPreferences auth handling
1007 // improved auth stability
1008 // improved old cookie handling: fixed deletion of old cookies with paths
1010 // Revision 1.127 2004/03/25 17:00:31 rurban
1011 // more code to convert old-style pref array to new hash
1013 // Revision 1.126 2004/03/24 19:39:03 rurban
1014 // php5 workaround code (plus some interim debugging code in XmlElement)
1015 // php5 doesn't work yet with the current XmlElement class constructors,
1016 // WikiUserNew does work better than php4.
1017 // rewrote WikiUserNew user upgrading to ease php5 update
1018 // fixed pref handling in WikiUserNew
1019 // added Email Notification
1020 // added simple Email verification
1021 // removed emailVerify userpref subclass: just a email property
1022 // changed pref binary storage layout: numarray => hash of non default values
1023 // print optimize message only if really done.
1024 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1025 // prefs should be stored in db or homepage, besides the current session.
1027 // Revision 1.125 2004/03/14 16:30:52 rurban
1028 // db-handle session revivification, dba fixes
1030 // Revision 1.124 2004/03/12 15:48:07 rurban
1031 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
1032 // simplified lib/stdlib.php:explodePageList
1034 // Revision 1.123 2004/03/10 15:41:27 rurban
1035 // use default pref mysql table
1037 // Revision 1.122 2004/03/08 18:17:09 rurban
1038 // added more WikiGroup::getMembersOf methods, esp. for special groups
1039 // fixed $LDAP_SET_OPTIONS
1040 // fixed _AuthInfo group methods
1042 // Revision 1.121 2004/03/01 13:48:45 rurban
1044 // p[] consistency fix
1046 // Revision 1.120 2004/03/01 10:22:41 rurban
1047 // initializeTheme optimize
1049 // Revision 1.119 2004/02/26 20:45:06 rurban
1050 // check for ALLOW_ANON_USER = false
1052 // Revision 1.118 2004/02/26 01:32:03 rurban
1053 // fixed session login with old WikiUser object. strangely, the errormask gets corruoted to 1, Pear???
1055 // Revision 1.117 2004/02/24 17:19:37 rurban
1056 // debugging helpers only
1058 // Revision 1.116 2004/02/24 15:17:14 rurban
1059 // 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
1061 // Revision 1.115 2004/02/15 21:34:37 rurban
1062 // PageList enhanced and improved.
1063 // fixed new WikiAdmin... plugins
1064 // editpage, Theme with exp. htmlarea framework
1065 // (htmlarea yet committed, this is really questionable)
1066 // WikiUser... code with better session handling for prefs
1067 // enhanced UserPreferences (again)
1068 // RecentChanges for show_deleted: how should pages be deleted then?
1070 // Revision 1.114 2004/02/15 17:30:13 rurban
1071 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
1072 // fixed getPreferences() (esp. from sessions)
1073 // fixed setPreferences() (update and set),
1074 // fixed AdoDb DB statements,
1075 // update prefs only at UserPreferences POST (for testing)
1076 // unified db prefs methods (but in external pref classes yet)
1078 // Revision 1.113 2004/02/12 13:05:49 rurban
1079 // Rename functional for PearDB backend
1080 // some other minor changes
1081 // SiteMap comes with a not yet functional feature request: includepages (tbd)
1083 // Revision 1.112 2004/02/09 03:58:12 rurban
1084 // for now default DB_SESSION to false
1086 // * not existing perms will now query the parent, and not
1087 // return the default perm
1088 // * added pagePermissions func which returns the object per page
1089 // * added getAccessDescription
1091 // * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
1092 // * force init of authdbh in the 2 db classes
1094 // * fixed session handling (not triple auth request anymore)
1095 // * don't store cookie prefs with sessions
1096 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
1098 // Revision 1.111 2004/02/07 10:41:25 rurban
1099 // fixed auth from session (still double code but works)
1101 // fixed DbPassUser upgrade and policy=old
1104 // Revision 1.110 2004/02/03 09:45:39 rurban
1105 // LDAP cleanup, start of new Pref classes
1107 // Revision 1.109 2004/01/30 19:57:58 rurban
1108 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
1110 // Revision 1.108 2004/01/28 14:34:14 rurban
1111 // session table takes the common prefix
1112 // + various minor stuff
1113 // reallow password changing
1115 // Revision 1.107 2004/01/27 23:23:39 rurban
1116 // renamed ->Username => _userid for consistency
1117 // renamed mayCheckPassword => mayCheckPass
1118 // fixed recursion problem in WikiUserNew
1119 // fixed bogo login (but not quite 100% ready yet, password storage)
1121 // Revision 1.106 2004/01/26 09:17:49 rurban
1122 // * changed stored pref representation as before.
1123 // the array of objects is 1) bigger and 2)
1124 // less portable. If we would import packed pref
1125 // objects and the object definition was changed, PHP would fail.
1126 // This doesn't happen with an simple array of non-default values.
1127 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1128 // understands the interim format of array of objects also.
1129 // * simplified $prefs->get() and fixed $prefs->set()
1130 // * added $user->_userid and class '_WikiUser' portability functions
1131 // * fixed $user object ->_level upgrading, mostly using sessions.
1132 // this fixes yesterdays problems with loosing authorization level.
1133 // * fixed WikiUserNew::checkPass to return the _level
1134 // * fixed WikiUserNew::isSignedIn
1135 // * added explodePageList to class PageList, support sortby arg
1136 // * fixed UserPreferences for WikiUserNew
1137 // * fixed WikiPlugin for empty defaults array
1138 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1139 // removed sort arg, support sortby arg
1141 // Revision 1.105 2004/01/25 03:57:15 rurban
1142 // WikiUserNew support (temp. ENABLE_USER_NEW constant)
1144 // Revision 1.104 2003/12/26 06:41:16 carstenklapp
1145 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
1146 // so they don't prevent IE from partially (or not at all) rendering the
1147 // page. This should help a little for the IE user who encounters trouble
1148 // when setting up a new PhpWiki for the first time.
1150 // Revision 1.103 2003/12/02 00:10:00 carstenklapp
1151 // Bugfix: Ongoing work to untangle UserPreferences/WikiUser/request code
1152 // mess: UserPreferences should take effect immediately now upon signing
1155 // Revision 1.102 2003/11/25 22:55:32 carstenklapp
1156 // Localization bugfix: For wikis where English is not the default system
1157 // language, make sure that the authority error message (i.e. "You must
1158 // sign in to edit pages in this wiki" etc.) is displayed in the wiki's
1159 // default language. Previously it would always display in English.
1160 // (Added call to update_locale() before displaying any messages prior to
1161 // the login prompt.)
1163 // Revision 1.101 2003/11/25 21:49:44 carstenklapp
1164 // Bugfix: For a non-english wiki or when the user's preference is not
1165 // english, the wiki would always use the english ActionPage first if it
1166 // was present rather than the appropriate localised variant. (PhpWikis
1167 // running only in english or Wikis running ONLY without any english
1168 // ActionPages would not notice this bug, only when both english and
1169 // localised ActionPages were in the DB.) Now we check for the localised
1172 // Revision 1.100 2003/11/18 16:54:18 carstenklapp
1173 // Reformatting only: Tabs to spaces, added rcs log.
1180 // c-basic-offset: 4
1181 // c-hanging-comment-ender-p: nil
1182 // indent-tabs-mode: nil