2 rcs_id('$Id: main.php,v 1.163 2004-06-13 11:35:32 rurban Exp $');
4 define ('USE_PREFS_IN_PAGE', true);
6 //include "lib/config.php";
7 require_once(dirname(__FILE__)."/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']);
22 if (in_array('File', $this->_dbi->getAuthParam('USER_AUTH_ORDER'))) {
23 // force our local copy, until the pear version is fixed.
24 include_once(dirname(__FILE__)."/pear/File_Passwd.php");
27 include_once('lib/DbSession.php');
29 $this->_dbsession = & new DbSession($dbi, $dbi->getParam('prefix') . $dbi->getParam('db_session_table'));
31 // Fixme: Does pear reset the error mask to 1? We have to find the culprit
32 $x = error_reporting();
33 $this->version = phpwiki_version();
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 $user_lang = $this->getPref('lang');
85 $_lang = @$this->_prefs->_prefs['lang'];
86 //check changed LANG and THEME inside a session.
87 // (e.g. by using another baseurl)
88 if (isset($this->_user->_authhow) and
89 $this->_user->_authhow == 'session' and
90 !isset($_lang->lang) and
91 $user_lang != $GLOBALS['LANG'])
93 $user_lang = $GLOBALS['LANG'];
95 if (isset($user_lang)) {
96 //trigger_error("DEBUG: initializeLang() ". $user_lang ." calling update_locale()...");
97 update_locale($user_lang);
98 FindLocalizedButtonFile(".",'missing_ok','reinit');
102 function initializeTheme () {
106 $user_theme = $this->getPref('theme');
107 $_theme = @$this->_prefs->_prefs['theme'];
108 //check changed LANG and THEME inside a session.
109 // (e.g. by using another baseurl)
110 if (isset($this->_user->_authhow) and
111 $this->_user->_authhow == 'session' and
112 !isset($_theme->theme) and
114 $user_theme != THEME)
116 include_once("themes/" . THEME . "/themeinfo.php");
118 if (empty($Theme) and isset($user_theme))
119 include_once("themes/$user_theme/themeinfo.php");
120 if (empty($Theme) and defined('THEME'))
121 include_once("themes/" . THEME . "/themeinfo.php");
123 include_once("themes/default/themeinfo.php");
124 assert(!empty($Theme));
127 // This really maybe should be part of the constructor, but since it
128 // may involve HTML/template output, the global $request really needs
129 // to be initialized before we do this stuff.
130 function updateAuthAndPrefs () {
132 if (isset($this->_user) and (!isa($this->_user,WikiUserClassname()))) {
133 $this->_user = false;
135 // Handle authentication request, if any.
136 if ($auth_args = $this->getArg('auth')) {
137 $this->setArg('auth', false);
138 $this->_handleAuthRequest($auth_args); // possible NORETURN
140 elseif ( ! $this->_user or
141 (isa($this->_user,WikiUserClassname()) and ! $this->_user->isSignedIn())) {
142 // If not auth request, try to sign in as saved user.
143 if (($saved_user = $this->getPref('userid')) != false) {
144 $this->_signIn($saved_user);
148 // Save preferences in session and cookie
149 if (isset($this->_user) and
150 (!isset($this->_user->_authhow) or $this->_user->_authhow != 'session')) {
152 $this->_user->setPreferences($this->_prefs, $id_only);
154 $this->setSessionVar('wiki_user', $this->_user);
155 //$this->setSessionVar('wiki_prefs', $this->_prefs);
158 // Ensure user has permissions for action
159 // HACK ALERT: We may not set the request arg to create,
160 // since the pageeditor has an ugly logic for action == create.
161 $action = $this->getArg('action');
162 if ($action == 'edit' or $action == 'create') {
163 $page = $this->getPage();
164 if (! $page->exists() )
169 $require_level = $this->requiredAuthority($action);
170 if (! $this->_user->hasAuthority($require_level))
171 $this->_notAuthorized($require_level); // NORETURN
174 function getUser () {
175 if (isset($this->_user))
178 return $GLOBALS['ForbiddenUser'];
181 function getPrefs () {
182 return $this->_prefs;
185 // Convenience function:
186 function getPref ($key) {
187 if (isset($this->_prefs))
188 return $this->_prefs->get($key);
196 * Get requested page from the page database.
197 * By default it will grab the page requested via the URL
199 * This is a convenience function.
200 * @param string $pagename Name of page to get.
201 * @return WikiDB_Page Object with methods to pull data from
202 * database for the page requested.
204 function getPage ($pagename = false) {
205 if (!isset($this->_dbi))
208 $pagename = $this->getArg('pagename');
209 return $this->_dbi->getPage($pagename);
212 /** Get URL for POST actions.
214 * Officially, we should just use SCRIPT_NAME (or some such),
215 * but that causes problems when we try to issue a redirect, e.g.
216 * after saving a page.
218 * Some browsers (at least NS4 and Mozilla 0.97 won't accept
219 * a redirect from a page to itself.)
221 * So, as a HACK, we include pagename and action as query args in
222 * the URL. (These should be ignored when we receive the POST
225 function getPostURL ($pagename=false) {
226 global $HTTP_GET_VARS;
228 if ($pagename === false)
229 $pagename = $this->getArg('pagename');
230 $action = $this->getArg('action');
231 if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
232 return WikiURL($pagename, array('action' => $action, 'start_debug' => 1));
234 return WikiURL($pagename, array('action' => $action));
237 function _handleAuthRequest ($auth_args) {
238 if (!is_array($auth_args))
241 // Ignore password unless POST'ed.
242 if (!$this->isPost())
243 unset($auth_args['passwd']);
245 $olduser = $this->_user;
246 $user = $this->_user->AuthCheck($auth_args);
247 if (isa($user, WikiUserClassname())) {
248 // Successful login (or logout.)
249 $this->_setUser($user);
251 elseif (is_string($user)) {
252 // Login attempt failed.
253 $fail_message = $user;
254 $auth_args['pass_required'] = true;
255 // If no password was submitted, it's not really
256 // a failure --- just need to prompt for password...
257 if (!ALLOW_USER_PASSWORDS
259 and !isset($auth_args['passwd']))
261 $fail_message = false;
263 $olduser->PrintLoginForm($this, $auth_args, $fail_message, 'newpage');
264 $this->finish(); //NORETURN
267 // Login request cancelled.
272 * Attempt to sign in (bogo-login).
276 * @param $userid string Userid to attempt to sign in as.
279 function _signIn ($userid) {
280 if (ENABLE_USER_NEW) {
282 $this->_user = new _BogoUser($userid);
284 $this->_user = new _PassUser($userid);
286 $user = $this->_user->AuthCheck(array('userid' => $userid));
287 if (isa($user,WikiUserClassname())) {
288 $this->_setUser($user); // success!
292 // login or logout or restore state
293 function _setUser ($user) {
294 $this->_user = $user;
295 define('MAIN_setUser',true);
296 $this->setCookieVar('WIKI_ID', $user->getAuthenticatedId(),
297 COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
298 $this->setSessionVar('wiki_user', $user);
299 if ($user->isSignedIn())
300 $user->_authhow = 'signin';
302 // Save userid to prefs..
303 if ( empty($this->_user->_prefs)) {
304 $this->_user->_prefs = $this->_user->getPreferences();
305 $this->_prefs =& $this->_user->_prefs;
307 $this->_prefs->set('userid',
308 $user->isSignedIn() ? $user->getId() : '');
309 $this->initializeTheme();
312 /* Permission system */
313 function getLevelDescription($level) {
314 static $levels = false;
316 $levels = array('-1' => _("FORBIDDEN"),
321 '100'=> _("UNOBTAINABLE"));
322 return $levels[$level];
325 function _notAuthorized ($require_level) {
326 // Display the authority message in the Wiki's default
327 // language, in case it is not english.
329 // Note that normally a user will not see such an error once
330 // logged in, unless the admin has altered the default
331 // disallowed wikiactions. In that case we should probably
332 // check the user's language prefs too at this point; this
333 // would be a situation which is not really handled with the
335 if (empty($GLOBALS['LANG']))
336 update_locale(DEFAULT_LANGUAGE);
338 // User does not have required authority. Prompt for login.
339 $what = $this->getActionDescription($this->getArg('action'));
340 $pass_required = ($require_level >= WIKIAUTH_USER);
341 if ($require_level == WIKIAUTH_UNOBTAINABLE) {
342 if (class_exists('PagePermission')) {
343 $user =& $this->_user;
344 $status = $user->isAuthenticated() ? _("authenticated") : _("not authenticated");
345 $msg = fmt("%s is disallowed on this wiki for %s user '%s' (level: %s).",
346 $this->getDisallowedActionDescription($this->getArg('action')),
347 $status, $user->getId(),$this->getLevelDescription($user->_level));
348 $user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
351 $msg = fmt("%s is disallowed on this wiki.",
352 $this->getDisallowedActionDescription($this->getArg('action')));
353 $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
357 elseif ($require_level == WIKIAUTH_BOGO)
358 $msg = fmt("You must sign in to %s.", $what);
359 elseif ($require_level == WIKIAUTH_USER)
360 $msg = fmt("You must log in to %s.", $what);
361 elseif ($require_level == WIKIAUTH_ANON)
362 $msg = fmt("Access for you is forbidden to %s.", $what);
364 $msg = fmt("You must be an administrator to %s.", $what);
366 $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
367 $this->finish(); // NORETURN
370 // Fixme: for PagePermissions we'll need other strings,
371 // relevant to the requested page, not just for the action on the whole wiki.
372 function getActionDescription($action) {
373 static $actionDescriptions;
374 if (! $actionDescriptions) {
376 = array('browse' => _("view this page"),
377 'diff' => _("diff this page"),
378 'dumphtml' => _("dump html pages"),
379 'dumpserial' => _("dump serial pages"),
380 'edit' => _("edit this page"),
381 'create' => _("create this page"),
382 'loadfile' => _("load files into this wiki"),
383 'lock' => _("lock this page"),
384 'remove' => _("remove this page"),
385 'unlock' => _("unlock this page"),
386 'upload' => _("upload a zip dump"),
387 'verify' => _("verify the current action"),
388 'viewsource' => _("view the source of this page"),
389 'xmlrpc' => _("access this wiki via XML-RPC"),
390 'soap' => _("access this wiki via SOAP"),
391 'zip' => _("download a zip dump from this wiki"),
392 'ziphtml' => _("download an html zip dump from this wiki")
395 if (in_array($action, array_keys($actionDescriptions)))
396 return $actionDescriptions[$action];
400 function getDisallowedActionDescription($action) {
401 static $disallowedActionDescriptions;
402 if (! $disallowedActionDescriptions) {
403 $disallowedActionDescriptions
404 = array('browse' => _("Browsing pages"),
405 'diff' => _("Diffing pages"),
406 'dumphtml' => _("Dumping html pages"),
407 'dumpserial' => _("Dumping serial pages"),
408 'edit' => _("Editing pages"),
409 'create' => _("Creating pages"),
410 'loadfile' => _("Loading files"),
411 'lock' => _("Locking pages"),
412 'remove' => _("Removing pages"),
413 'unlock' => _("Unlocking pages"),
414 'upload' => _("Uploading zip dumps"),
415 'verify' => _("Verify the current action"),
416 'viewsource' => _("Viewing the source of pages"),
417 'xmlrpc' => _("XML-RPC access"),
418 'soap' => _("SOAP access"),
419 'zip' => _("Downloading zip dumps"),
420 'ziphtml' => _("Downloading html zip dumps")
423 if (in_array($action, array_keys($disallowedActionDescriptions)))
424 return $disallowedActionDescriptions[$action];
429 function requiredAuthority ($action) {
430 $auth = $this->requiredAuthorityForAction($action);
431 if (!ALLOW_ANON_USER) return WIKIAUTH_USER;
434 * This is a hook for plugins to require authority
435 * for posting to them.
437 * IMPORTANT: this is not a secure check, so the plugin
438 * may not assume that any POSTs to it are authorized.
439 * All this does is cause PhpWiki to prompt for login
440 * if the user doesn't have the required authority.
442 if ($this->isPost()) {
443 $post_auth = $this->getArg('require_authority_for_post');
444 if ($post_auth !== false)
445 $auth = max($auth, $post_auth);
450 function requiredAuthorityForAction ($action) {
451 if (ENABLE_PAGEPERM and class_exists("PagePermission")) {
452 return requiredAuthorityForPage($action);
463 return WIKIAUTH_ANON;
467 if (defined('ZIPDUMP_AUTH') && ZIPDUMP_AUTH)
468 return WIKIAUTH_ADMIN;
469 return WIKIAUTH_ANON;
473 if (defined('REQUIRE_SIGNIN_BEFORE_EDIT') && REQUIRE_SIGNIN_BEFORE_EDIT)
474 return WIKIAUTH_BOGO;
475 return WIKIAUTH_ANON;
476 // return WIKIAUTH_BOGO;
479 $page = $this->getPage();
480 $current = $page->getCurrentRevision();
481 if ($current->hasDefaultContents())
482 return $this->requiredAuthorityForAction('edit');
483 return $this->requiredAuthorityForAction('browse');
496 return WIKIAUTH_ADMIN;
498 /* authcheck occurs only in the plugin.
499 required actionpage RateIt */
502 case 'delete_rating':
503 // Perhaps this should be WIKIAUTH_USER
504 return WIKIAUTH_BOGO;
508 global $WikiNameRegexp;
509 if (preg_match("/$WikiNameRegexp\Z/A", $action))
510 return WIKIAUTH_ANON; // ActionPage.
512 return WIKIAUTH_ADMIN;
516 /* End of Permission system */
518 function possiblyDeflowerVirginWiki () {
519 if ($this->getArg('action') != 'browse')
521 if ($this->getArg('pagename') != HOME_PAGE)
524 $page = $this->getPage();
525 $current = $page->getCurrentRevision();
526 if ($current->getVersion() > 0)
527 return; // Homepage exists.
529 include('lib/loadsave.php');
531 $this->finish(); // NORETURN
534 function handleAction () {
535 $action = $this->getArg('action');
536 $method = "action_$action";
537 if (method_exists($this, $method)) {
540 elseif ($page = $this->findActionPage($action)) {
541 $this->actionpage($page);
544 $this->finish(fmt("%s: Bad action", $action));
548 function finish ($errormsg = false) {
552 exit(); // just in case CloseDataBase calls us
555 global $ErrorManager;
556 $ErrorManager->flushPostponedErrors();
558 if (!empty($errormsg)) {
561 HTML::h2(_("Fatal PhpWiki Error")),
564 echo "\n</body></html>";
566 if (is_object($this->_user)) {
567 $this->_user->page = $this->getArg('pagename');
568 $this->_user->action = $this->getArg('action');
569 unset($this->_user->_HomePagehandle);
570 unset($this->_user->_auth_dbi);
572 if (!empty($this->_dbi)) {
573 session_write_close();
574 $this->_dbi->close();
582 * Generally pagename is rawurlencoded for older browsers or mozilla.
583 * Typing a pagename into the IE bar will utf-8 encode it, so we have to
584 * fix that with fixTitleEncoding().
585 * If USE_PATH_INFO = true, the pagename is stripped from the "/DATA_PATH/PageName&arg=value" line.
586 * If false, we support either "/index.php?pagename=PageName&arg=value",
587 * or the first arg (1.2.x style): "/index.php?PageName&arg=value"
589 function _deducePagename () {
590 if (trim(rawurldecode($this->getArg('pagename'))))
591 return fixTitleEncoding(rawurldecode($this->getArg('pagename')));
594 $pathinfo = $this->get('PATH_INFO');
595 if (empty($pathinfo)) { // fix for CGI
596 $path = $this->get('REQUEST_URI');
597 $script = $this->get('SCRIPT_NAME');
598 $pathinfo = substr($path,strlen($script));
599 $pathinfo = preg_replace('/\?.+$/','',$pathinfo);
601 $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
603 if (trim($tail) != '' and $pathinfo == PATH_INFO_PREFIX . $tail) {
604 return fixTitleEncoding($tail);
607 elseif ($this->isPost()) {
609 * In general, for security reasons, HTTP_GET_VARS should be ignored
610 * on POST requests, but we make an exception here (only for pagename).
612 * The justification for this hack is the following
613 * asymmetry: When POSTing with USE_PATH_INFO set, the
614 * pagename can (and should) be communicated through the
615 * request URL via PATH_INFO. When POSTing with
616 * USE_PATH_INFO off, this cannot be done --- the only way
617 * to communicate the pagename through the URL is via
618 * QUERY_ARGS (HTTP_GET_VARS).
620 global $HTTP_GET_VARS;
621 if (isset($HTTP_GET_VARS['pagename']) and trim($HTTP_GET_VARS['pagename'])) {
622 return fixTitleEncoding(rawurldecode($HTTP_GET_VARS['pagename']));
627 * Support for PhpWiki 1.2 style requests.
628 * Strip off "&" args (?PageName&action=...&start_debug,...)
630 $query_string = $this->get('QUERY_STRING');
631 if (trim(rawurldecode($query_string)) and preg_match('/^([^&=]+)(&.+)?$/', $query_string, $m)) {
632 return fixTitleEncoding(rawurldecode($m[1]));
635 return fixTitleEncoding(HOME_PAGE);
638 function _deduceAction () {
639 if (!($action = $this->getArg('action'))) {
640 // Detect XML-RPC requests
642 && $this->get('CONTENT_TYPE') == 'text/xml') {
643 global $HTTP_RAW_POST_DATA;
644 if (strstr($HTTP_RAW_POST_DATA, '<methodCall>')) {
648 return 'browse'; // Default if no action specified.
651 if (method_exists($this, "action_$action"))
654 // Allow for, e.g. action=LikePages
655 if ($this->isActionPage($action))
658 // Handle untranslated actionpages in non-english
659 // (people playing with switching languages)
660 if (0 and $GLOBALS['LANG'] != 'en') {
661 require_once("lib/plugin/_WikiTranslation.php");
662 $trans = new WikiPlugin__WikiTranslation();
663 $en_action = $trans->translate($action,'en',$GLOBALS['LANG']);
664 if ($this->isActionPage($en_action))
668 trigger_error("$action: Unknown action", E_USER_NOTICE);
672 function _deduceUsername() {
673 global $HTTP_SERVER_VARS, $HTTP_ENV_VARS;
675 if (!empty($this->args['auth']) and !empty($this->args['auth']['userid']))
676 return $this->args['auth']['userid'];
678 if (!empty($HTTP_SERVER_VARS['PHP_AUTH_USER']))
679 return $HTTP_SERVER_VARS['PHP_AUTH_USER'];
680 if (!empty($HTTP_ENV_VARS['REMOTE_USER']))
681 return $HTTP_ENV_VARS['REMOTE_USER'];
683 if ($user = $this->getSessionVar('wiki_user')) {
684 $this->_user = $user;
685 $this->_user->_authhow = 'session';
686 return ENABLE_USER_NEW ? $user->UserName() : $this->_user;
688 if ($userid = $this->getCookieVar('WIKI_ID')) {
689 if (!empty($userid) and substr($userid,0,2) != 's:') {
690 $this->_user->authhow = 'cookie';
697 function _isActionPage ($pagename) {
698 $dbi = $this->getDbh();
699 $page = $dbi->getPage($pagename);
700 $rev = $page->getCurrentRevision();
701 // FIXME: more restrictive check for sane plugin?
702 if (strstr($rev->getPackedContent(), '<?plugin'))
704 if (!$rev->hasDefaultContents())
705 trigger_error("$pagename: Does not appear to be an 'action page'", E_USER_NOTICE);
709 function findActionPage ($action) {
712 // check for translated version, as per users preferred language
713 // (or system default in case it is not en)
714 $translation = gettext($action);
716 if (isset($cache) and isset($cache[$translation]))
717 return $cache[$translation];
719 // check for cached translated version
720 if ($this->_isActionPage($translation))
721 return $cache[$action] = $translation;
723 // Allow for, e.g. action=LikePages
724 global $WikiNameRegexp;
725 if (!preg_match("/$WikiNameRegexp\\Z/A", $action))
726 return $cache[$action] = false;
728 // check for translated version (default language)
730 if ($LANG != DEFAULT_LANGUAGE and $LANG != "en") {
732 //trigger_error("DEBUG: findActionPage() ". DEFAULT_LANGUAGE." calling update_locale()...");
733 update_locale(DEFAULT_LANGUAGE);
734 $default = gettext($action);
735 //trigger_error("DEBUG: findActionPage() ". $save_lang." restoring save_lang, calling update_locale()...");
736 update_locale($save_lang);
737 if ($this->_isActionPage($default))
738 return $cache[$action] = $default;
741 $default = $translation;
744 // check for english version
745 if ($action != $translation and $action != $default) {
746 if ($this->_isActionPage($action))
747 return $cache[$action] = $action;
750 trigger_error("$action: Cannot find action page", E_USER_NOTICE);
751 return $cache[$action] = false;
754 function isActionPage ($pagename) {
755 return $this->findActionPage($pagename);
758 function action_browse () {
759 $this->buffer_output();
760 include_once("lib/display.php");
764 function action_verify () {
765 $this->action_browse();
768 function actionpage ($action) {
769 $this->buffer_output();
770 include_once("lib/display.php");
771 actionPage($this, $action);
774 function adminActionSubpage ($subpage) {
775 $page = _("PhpWikiAdministration")."/".$subpage;
776 $action = $this->findActionPage($page);
778 $this->setArg('s',$this->getArg('pagename'));
779 $this->setArg('verify',1);
780 $this->setArg('action',$action);
781 $this->actionpage($action);
783 trigger_error($page.": Cannot find action page", E_USER_WARNING);
787 function action_chown () {
788 $this->adminActionSubpage(_("Chown"));
791 function action_setacl () {
792 $this->adminActionSubpage(_("SetAcl"));
795 function action_rename () {
796 $this->adminActionSubpage(_("Rename"));
799 function action_dump () {
800 $action = $this->findActionPage(_("PageDump"));
802 $this->actionpage($action);
804 // redirect to action=upgrade if admin?
805 trigger_error(_("PageDump").": Cannot find action page", E_USER_WARNING);
809 function action_diff () {
810 $this->buffer_output();
811 include_once "lib/diff.php";
815 function action_search () {
816 // This is obsolete: reformulate URL and redirect.
817 // FIXME: this whole section should probably be deleted.
818 if ($this->getArg('searchtype') == 'full') {
819 $search_page = _("FullTextSearch");
822 $search_page = _("TitleSearch");
824 $this->redirect(WikiURL($search_page,
825 array('s' => $this->getArg('searchterm')),
829 function action_edit () {
830 $this->buffer_output();
831 include "lib/editpage.php";
832 $e = new PageEditor ($this);
836 function action_create () {
837 $this->action_edit();
840 function action_viewsource () {
841 $this->buffer_output();
842 include "lib/editpage.php";
843 $e = new PageEditor ($this);
847 function action_lock () {
848 $page = $this->getPage();
849 $page->set('locked', true);
850 $this->_dbi->touch();
851 $this->action_browse();
854 function action_unlock () {
855 // FIXME: This check is redundant.
856 //$user->requireAuth(WIKIAUTH_ADMIN);
857 $page = $this->getPage();
858 $page->set('locked', false);
859 $this->_dbi->touch();
860 $this->action_browse();
863 function action_remove () {
864 // FIXME: This check is redundant.
865 //$user->requireAuth(WIKIAUTH_ADMIN);
866 $pagename = $this->getArg('pagename');
867 if (strstr($pagename,_('PhpWikiAdministration'))) {
868 $this->action_browse();
870 include('lib/removepage.php');
875 function action_xmlrpc () {
876 include_once("lib/XmlRpcServer.php");
877 $xmlrpc = new XmlRpcServer($this);
881 function action_zip () {
882 include_once("lib/loadsave.php");
884 // I don't think it hurts to add cruft at the end of the zip file.
885 //echo "\n========================================================\n";
886 //echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
889 function action_ziphtml () {
890 include_once("lib/loadsave.php");
891 MakeWikiZipHtml($this);
892 // I don't think it hurts to add cruft at the end of the zip file.
893 echo "\n========================================================\n";
894 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
897 function action_dumpserial () {
898 include_once("lib/loadsave.php");
902 function action_dumphtml () {
903 include_once("lib/loadsave.php");
904 DumpHtmlToDir($this);
907 function action_upload () {
908 include_once("lib/loadsave.php");
912 function action_upgrade () {
913 include_once("lib/loadsave.php");
914 include_once("lib/upgrade.php");
918 function action_loadfile () {
919 include_once("lib/loadsave.php");
920 LoadFileOrDir($this);
923 function action_pdf () {
924 include_once("lib/pdf.php");
925 ConvertAndDisplayPdf($this);
931 function is_safe_action ($action) {
932 return WikiRequest::requiredAuthorityForAction($action) < WIKIAUTH_ADMIN;
935 function validateSessionPath() {
936 // Try to defer any session.save_path PHP errors before any html
937 // is output, which causes some versions of IE to display a blank
938 // page (due to its strict mode while parsing a page?).
939 if (! is_writeable(ini_get('session.save_path'))) {
942 (sprintf(_("%s is not writable."),
943 _("The session.save_path directory"))
945 . sprintf(_("Please ensure that %s is writable, or redefine %s in config/config.ini."),
946 sprintf(_("the directory '%s'"),
947 ini_get('session.save_path')),
950 . sprintf(_("Attempting to use the directory '%s' instead."),
953 if (! is_writeable($tmpdir)) {
955 (sprintf(_("%s is not writable."), $tmpdir)
957 . _("Users will not be able to sign in.")
961 ini_set('session.save_path', $tmpdir);
967 validateSessionPath();
971 if ((DEBUG & 4) and extension_loaded("apd"))
972 apd_set_session_trace(9);
975 global $ErrorManager;
976 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE|E_USER_WARNING);
977 $request = new WikiRequest();
979 $action = $request->getArg('action');
980 if (substr($action, 0, 3) != 'zip') {
981 if ($action == 'pdf')
982 $ErrorManager->setPostponedErrorMask(-1);
983 else // reject postponing of warnings
984 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
988 * Allow for disabling of markup cache.
989 * (Mostly for debugging ... hopefully.)
991 * See also <?plugin WikiAdminUtils action=purge-cache ?>
993 if (!defined('WIKIDB_NOCACHE_MARKUP') and $request->getArg('nocache'))
994 define('WIKIDB_NOCACHE_MARKUP', $request->getArg('nocache'));
996 // Initialize with system defaults in case user not logged in.
997 // Should this go into constructor?
998 $request->initializeTheme();
1000 $request->updateAuthAndPrefs();
1001 $request->initializeLang();
1004 //if ($user->is_authenticated())
1005 // $LogEntry->user = $user->getId();
1007 $request->possiblyDeflowerVirginWiki();
1009 if (defined('WIKI_XMLRPC') and WIKI_XMLRPC) return;
1010 if (defined('WIKI_SOAP') and WIKI_SOAP) return;
1012 $validators = array('wikiname' => WIKI_NAME,
1013 'args' => hash($request->getArgs()),
1014 'prefs' => hash($request->getPrefs()));
1015 if (CACHE_CONTROL == 'STRICT') {
1016 $dbi = $request->getDbh();
1017 $timestamp = $dbi->getTimestamp();
1018 $validators['mtime'] = $timestamp;
1019 $validators['%mtime'] = (int)$timestamp;
1021 // FIXME: we should try to generate strong validators when possible,
1022 // but for now, our validator is weak, since equal validators do not
1023 // indicate byte-level equality of content. (Due to DEBUG timing output, etc...)
1025 // (If DEBUG if off, this may be a strong validator, but I'm going
1026 // to go the paranoid route here pending further study and testing.)
1028 $validators['%weak'] = true;
1029 $request->setValidators($validators);
1031 $request->handleAction();
1033 if (defined('DEBUG') and DEBUG & 4) phpinfo(INFO_VARIABLES);
1037 $x = error_reporting(); // why is it 1 here? should be E_ALL
1038 error_reporting(E_ALL);
1042 // $Log: not supported by cvs2svn $
1043 // Revision 1.162 2004/06/08 10:05:11 rurban
1044 // simplified admin action shortcuts
1046 // Revision 1.161 2004/06/07 22:58:40 rurban
1047 // simplified chown, setacl, dump actions
1049 // Revision 1.160 2004/06/07 22:44:14 rurban
1050 // added simplified chown, setacl actions
1052 // Revision 1.159 2004/06/06 16:58:51 rurban
1053 // added more required ActionPages for foreign languages
1054 // install now english ActionPages if no localized are found. (again)
1055 // fixed default anon user level to be 0, instead of -1
1056 // (wrong "required administrator to view this page"...)
1058 // Revision 1.158 2004/06/04 20:32:53 rurban
1059 // Several locale related improvements suggested by Pierrick Meignen
1060 // LDAP fix by John Cole
1061 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
1063 // Revision 1.157 2004/06/04 12:40:21 rurban
1064 // Restrict valid usernames to prevent from attacks against external auth or compromise
1066 // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
1067 // Fxied more warnings
1069 // Revision 1.156 2004/06/03 17:58:16 rurban
1070 // support immediate LANG and THEME switch inside a session
1072 // Revision 1.155 2004/06/03 10:18:19 rurban
1073 // fix FileUser locking issues, new config ENABLE_PAGEPERM
1075 // Revision 1.154 2004/06/02 18:01:46 rurban
1076 // init global FileFinder to add proper include paths at startup
1077 // adds PHPWIKI_DIR if started from another dir, lib/pear also
1078 // fix slashify for Windows
1079 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
1081 // Revision 1.153 2004/06/01 15:28:00 rurban
1082 // AdminUser only ADMIN_USER not member of Administrators
1083 // some RateIt improvements by dfrankow
1084 // edit_toolbar buttons
1086 // Revision 1.152 2004/05/27 17:49:06 rurban
1087 // renamed DB_Session to DbSession (in CVS also)
1088 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
1089 // remove leading slash in error message
1090 // added force_unlock parameter to File_Passwd (no return on stale locks)
1091 // fixed adodb session AffectedRows
1092 // added FileFinder helpers to unify local filenames and DATA_PATH names
1093 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
1095 // Revision 1.151 2004/05/25 12:40:48 rurban
1096 // trim the pagename
1098 // Revision 1.150 2004/05/25 10:18:44 rurban
1099 // Check for UTF-8 URLs; Internet Explorer produces these if you
1100 // type non-ASCII chars in the URL bar or follow unescaped links.
1101 // Fixes sf.net bug #953949
1102 // src: languages/Language.php:checkTitleEncoding() from mediawiki
1104 // Revision 1.149 2004/05/18 13:31:19 rurban
1105 // hold warnings until headers are sent. new Error-style with collapsed output of repeated messages
1107 // Revision 1.148 2004/05/17 17:43:29 rurban
1108 // CGI: no PATH_INFO fix
1110 // Revision 1.147 2004/05/15 19:48:33 rurban
1111 // fix some too loose PagePerms for signed, but not authenticated users
1112 // (admin, owner, creator)
1113 // no double login page header, better login msg.
1114 // moved action_pdf to lib/pdf.php
1116 // Revision 1.146 2004/05/15 18:31:01 rurban
1117 // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
1119 // Revision 1.145 2004/05/12 10:49:55 rurban
1120 // require_once fix for those libs which are loaded before FileFinder and
1121 // its automatic include_path fix, and where require_once doesn't grok
1122 // dirname(__FILE__) != './lib'
1123 // upgrade fix with PearDB
1124 // navbar.tmpl: remove spaces for IE button alignment
1126 // Revision 1.144 2004/05/06 19:26:16 rurban
1127 // improve stability, trying to find the InlineParser endless loop on sf.net
1129 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
1131 // Revision 1.143 2004/05/06 17:30:38 rurban
1132 // CategoryGroup: oops, dos2unix eol
1133 // improved phpwiki_version:
1134 // pre -= .0001 (1.3.10pre: 1030.099)
1135 // -p1 += .001 (1.3.9-p1: 1030.091)
1136 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
1137 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
1138 // backend->backendType(), backend->database(),
1139 // backend->listOfFields(),
1140 // backend->listOfTables(),
1142 // Revision 1.142 2004/05/04 22:34:25 rurban
1145 // Revision 1.141 2004/05/03 13:16:47 rurban
1146 // fixed UserPreferences update, esp for boolean and int
1148 // Revision 1.140 2004/05/02 21:26:38 rurban
1149 // limit user session data (HomePageHandle and auth_dbi have to invalidated anyway)
1150 // because they will not survive db sessions, if too large.
1151 // extended action=upgrade
1152 // some WikiTranslation button work
1153 // revert WIKIAUTH_UNOBTAINABLE (need it for main.php)
1154 // some temp. session debug statements
1156 // Revision 1.139 2004/05/02 15:10:07 rurban
1157 // new finally reliable way to detect if /index.php is called directly
1158 // and if to include lib/main.php
1159 // new global AllActionPages
1160 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
1161 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
1162 // PageGroupTestOne => subpages
1163 // renamed PhpWikiRss to PhpWikiRecentChanges
1164 // more docs, default configs, ...
1166 // Revision 1.138 2004/05/01 15:59:29 rurban
1167 // more php-4.0.6 compatibility: superglobals
1169 // Revision 1.137 2004/04/29 19:39:44 rurban
1170 // special support for formatted plugins (one-liners)
1171 // like <small><plugin BlaBla ></small>
1172 // iter->asArray() helper for PopularNearby
1173 // db_session for older php's (no &func() allowed)
1175 // Revision 1.136 2004/04/29 17:18:19 zorloc
1176 // 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.
1178 // Revision 1.135 2004/04/26 12:15:01 rurban
1179 // check default config values
1181 // Revision 1.134 2004/04/23 06:46:37 zorloc
1182 // Leave DB connection open when USE_DB_SESSION is true so that session info can be written to the DB.
1184 // Revision 1.133 2004/04/20 18:10:31 rurban
1185 // config refactoring:
1186 // FileFinder is needed for WikiFarm scripts calling index.php
1187 // config run-time calls moved to lib/IniConfig.php:fix_configs()
1188 // added PHPWIKI_DIR smart-detection code (Theme finder)
1189 // moved FileFind to lib/FileFinder.php
1190 // cleaned lib/config.php
1192 // Revision 1.132 2004/04/19 21:51:41 rurban
1193 // php5 compatibility: it works!
1195 // Revision 1.131 2004/04/19 18:27:45 rurban
1196 // Prevent from some PHP5 warnings (ref args, no :: object init)
1197 // php5 runs now through, just one wrong XmlElement object init missing
1198 // Removed unneccesary UpgradeUser lines
1199 // Changed WikiLink to omit version if current (RecentChanges)
1201 // Revision 1.130 2004/04/18 00:25:53 rurban
1202 // allow "0" pagename
1204 // Revision 1.129 2004/04/07 23:13:19 rurban
1205 // fixed pear/File_Passwd for Windows
1206 // fixed FilePassUser sessions (filehandle revive) and password update
1208 // Revision 1.128 2004/04/02 15:06:55 rurban
1209 // fixed a nasty ADODB_mysql session update bug
1210 // improved UserPreferences layout (tabled hints)
1211 // fixed UserPreferences auth handling
1212 // improved auth stability
1213 // improved old cookie handling: fixed deletion of old cookies with paths
1215 // Revision 1.127 2004/03/25 17:00:31 rurban
1216 // more code to convert old-style pref array to new hash
1218 // Revision 1.126 2004/03/24 19:39:03 rurban
1219 // php5 workaround code (plus some interim debugging code in XmlElement)
1220 // php5 doesn't work yet with the current XmlElement class constructors,
1221 // WikiUserNew does work better than php4.
1222 // rewrote WikiUserNew user upgrading to ease php5 update
1223 // fixed pref handling in WikiUserNew
1224 // added Email Notification
1225 // added simple Email verification
1226 // removed emailVerify userpref subclass: just a email property
1227 // changed pref binary storage layout: numarray => hash of non default values
1228 // print optimize message only if really done.
1229 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1230 // prefs should be stored in db or homepage, besides the current session.
1232 // Revision 1.125 2004/03/14 16:30:52 rurban
1233 // db-handle session revivification, dba fixes
1235 // Revision 1.124 2004/03/12 15:48:07 rurban
1236 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
1237 // simplified lib/stdlib.php:explodePageList
1239 // Revision 1.123 2004/03/10 15:41:27 rurban
1240 // use default pref mysql table
1242 // Revision 1.122 2004/03/08 18:17:09 rurban
1243 // added more WikiGroup::getMembersOf methods, esp. for special groups
1244 // fixed $LDAP_SET_OPTIONS
1245 // fixed _AuthInfo group methods
1247 // Revision 1.121 2004/03/01 13:48:45 rurban
1249 // p[] consistency fix
1251 // Revision 1.120 2004/03/01 10:22:41 rurban
1252 // initializeTheme optimize
1254 // Revision 1.119 2004/02/26 20:45:06 rurban
1255 // check for ALLOW_ANON_USER = false
1257 // Revision 1.118 2004/02/26 01:32:03 rurban
1258 // fixed session login with old WikiUser object. strangely, the errormask gets corruoted to 1, Pear???
1260 // Revision 1.117 2004/02/24 17:19:37 rurban
1261 // debugging helpers only
1263 // Revision 1.116 2004/02/24 15:17:14 rurban
1264 // 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
1266 // Revision 1.115 2004/02/15 21:34:37 rurban
1267 // PageList enhanced and improved.
1268 // fixed new WikiAdmin... plugins
1269 // editpage, Theme with exp. htmlarea framework
1270 // (htmlarea yet committed, this is really questionable)
1271 // WikiUser... code with better session handling for prefs
1272 // enhanced UserPreferences (again)
1273 // RecentChanges for show_deleted: how should pages be deleted then?
1275 // Revision 1.114 2004/02/15 17:30:13 rurban
1276 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
1277 // fixed getPreferences() (esp. from sessions)
1278 // fixed setPreferences() (update and set),
1279 // fixed AdoDb DB statements,
1280 // update prefs only at UserPreferences POST (for testing)
1281 // unified db prefs methods (but in external pref classes yet)
1283 // Revision 1.113 2004/02/12 13:05:49 rurban
1284 // Rename functional for PearDB backend
1285 // some other minor changes
1286 // SiteMap comes with a not yet functional feature request: includepages (tbd)
1288 // Revision 1.112 2004/02/09 03:58:12 rurban
1289 // for now default DB_SESSION to false
1291 // * not existing perms will now query the parent, and not
1292 // return the default perm
1293 // * added pagePermissions func which returns the object per page
1294 // * added getAccessDescription
1296 // * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
1297 // * force init of authdbh in the 2 db classes
1299 // * fixed session handling (not triple auth request anymore)
1300 // * don't store cookie prefs with sessions
1301 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
1303 // Revision 1.111 2004/02/07 10:41:25 rurban
1304 // fixed auth from session (still double code but works)
1306 // fixed DbPassUser upgrade and policy=old
1309 // Revision 1.110 2004/02/03 09:45:39 rurban
1310 // LDAP cleanup, start of new Pref classes
1312 // Revision 1.109 2004/01/30 19:57:58 rurban
1313 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
1315 // Revision 1.108 2004/01/28 14:34:14 rurban
1316 // session table takes the common prefix
1317 // + various minor stuff
1318 // reallow password changing
1320 // Revision 1.107 2004/01/27 23:23:39 rurban
1321 // renamed ->Username => _userid for consistency
1322 // renamed mayCheckPassword => mayCheckPass
1323 // fixed recursion problem in WikiUserNew
1324 // fixed bogo login (but not quite 100% ready yet, password storage)
1326 // Revision 1.106 2004/01/26 09:17:49 rurban
1327 // * changed stored pref representation as before.
1328 // the array of objects is 1) bigger and 2)
1329 // less portable. If we would import packed pref
1330 // objects and the object definition was changed, PHP would fail.
1331 // This doesn't happen with an simple array of non-default values.
1332 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1333 // understands the interim format of array of objects also.
1334 // * simplified $prefs->get() and fixed $prefs->set()
1335 // * added $user->_userid and class '_WikiUser' portability functions
1336 // * fixed $user object ->_level upgrading, mostly using sessions.
1337 // this fixes yesterdays problems with loosing authorization level.
1338 // * fixed WikiUserNew::checkPass to return the _level
1339 // * fixed WikiUserNew::isSignedIn
1340 // * added explodePageList to class PageList, support sortby arg
1341 // * fixed UserPreferences for WikiUserNew
1342 // * fixed WikiPlugin for empty defaults array
1343 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1344 // removed sort arg, support sortby arg
1346 // Revision 1.105 2004/01/25 03:57:15 rurban
1347 // WikiUserNew support (temp. ENABLE_USER_NEW constant)
1349 // Revision 1.104 2003/12/26 06:41:16 carstenklapp
1350 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
1351 // so they don't prevent IE from partially (or not at all) rendering the
1352 // page. This should help a little for the IE user who encounters trouble
1353 // when setting up a new PhpWiki for the first time.
1355 // Revision 1.103 2003/12/02 00:10:00 carstenklapp
1356 // Bugfix: Ongoing work to untangle UserPreferences/WikiUser/request code
1357 // mess: UserPreferences should take effect immediately now upon signing
1360 // Revision 1.102 2003/11/25 22:55:32 carstenklapp
1361 // Localization bugfix: For wikis where English is not the default system
1362 // language, make sure that the authority error message (i.e. "You must
1363 // sign in to edit pages in this wiki" etc.) is displayed in the wiki's
1364 // default language. Previously it would always display in English.
1365 // (Added call to update_locale() before displaying any messages prior to
1366 // the login prompt.)
1368 // Revision 1.101 2003/11/25 21:49:44 carstenklapp
1369 // Bugfix: For a non-english wiki or when the user's preference is not
1370 // english, the wiki would always use the english ActionPage first if it
1371 // was present rather than the appropriate localised variant. (PhpWikis
1372 // running only in english or Wikis running ONLY without any english
1373 // ActionPages would not notice this bug, only when both english and
1374 // localised ActionPages were in the DB.) Now we check for the localised
1377 // Revision 1.100 2003/11/18 16:54:18 carstenklapp
1378 // Reformatting only: Tabs to spaces, added rcs log.
1385 // c-basic-offset: 4
1386 // c-hanging-comment-ender-p: nil
1387 // indent-tabs-mode: nil