2 rcs_id('$Id: main.php,v 1.164 2004-06-13 13:54:25 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 if (!$page) return false;
701 $rev = $page->getCurrentRevision();
702 // FIXME: more restrictive check for sane plugin?
703 if (strstr($rev->getPackedContent(), '<?plugin'))
705 if (!$rev->hasDefaultContents())
706 trigger_error("$pagename: Does not appear to be an 'action page'", E_USER_NOTICE);
710 function findActionPage ($action) {
713 // check for translated version, as per users preferred language
714 // (or system default in case it is not en)
715 $translation = gettext($action);
717 if (isset($cache) and isset($cache[$translation]))
718 return $cache[$translation];
720 // check for cached translated version
721 if ($this->_isActionPage($translation))
722 return $cache[$action] = $translation;
724 // Allow for, e.g. action=LikePages
725 global $WikiNameRegexp;
726 if (!preg_match("/$WikiNameRegexp\\Z/A", $action))
727 return $cache[$action] = false;
729 // check for translated version (default language)
731 if ($LANG != DEFAULT_LANGUAGE and $LANG != "en") {
733 //trigger_error("DEBUG: findActionPage() ". DEFAULT_LANGUAGE." calling update_locale()...");
734 update_locale(DEFAULT_LANGUAGE);
735 $default = gettext($action);
736 //trigger_error("DEBUG: findActionPage() ". $save_lang." restoring save_lang, calling update_locale()...");
737 update_locale($save_lang);
738 if ($this->_isActionPage($default))
739 return $cache[$action] = $default;
742 $default = $translation;
745 // check for english version
746 if ($action != $translation and $action != $default) {
747 if ($this->_isActionPage($action))
748 return $cache[$action] = $action;
751 trigger_error("$action: Cannot find action page", E_USER_NOTICE);
752 return $cache[$action] = false;
755 function isActionPage ($pagename) {
756 return $this->findActionPage($pagename);
759 function action_browse () {
760 $this->buffer_output();
761 include_once("lib/display.php");
765 function action_verify () {
766 $this->action_browse();
769 function actionpage ($action) {
770 $this->buffer_output();
771 include_once("lib/display.php");
772 actionPage($this, $action);
775 function adminActionSubpage ($subpage) {
776 $page = _("PhpWikiAdministration")."/".$subpage;
777 $action = $this->findActionPage($page);
779 $this->setArg('s',$this->getArg('pagename'));
780 $this->setArg('verify',1);
781 $this->setArg('action',$action);
782 $this->actionpage($action);
784 trigger_error($page.": Cannot find action page", E_USER_WARNING);
788 function action_chown () {
789 $this->adminActionSubpage(_("Chown"));
792 function action_setacl () {
793 $this->adminActionSubpage(_("SetAcl"));
796 function action_rename () {
797 $this->adminActionSubpage(_("Rename"));
800 function action_dump () {
801 $action = $this->findActionPage(_("PageDump"));
803 $this->actionpage($action);
805 // redirect to action=upgrade if admin?
806 trigger_error(_("PageDump").": Cannot find action page", E_USER_WARNING);
810 function action_diff () {
811 $this->buffer_output();
812 include_once "lib/diff.php";
816 function action_search () {
817 // This is obsolete: reformulate URL and redirect.
818 // FIXME: this whole section should probably be deleted.
819 if ($this->getArg('searchtype') == 'full') {
820 $search_page = _("FullTextSearch");
823 $search_page = _("TitleSearch");
825 $this->redirect(WikiURL($search_page,
826 array('s' => $this->getArg('searchterm')),
830 function action_edit () {
831 $this->buffer_output();
832 include "lib/editpage.php";
833 $e = new PageEditor ($this);
837 function action_create () {
838 $this->action_edit();
841 function action_viewsource () {
842 $this->buffer_output();
843 include "lib/editpage.php";
844 $e = new PageEditor ($this);
848 function action_lock () {
849 $page = $this->getPage();
850 $page->set('locked', true);
851 $this->_dbi->touch();
852 $this->action_browse();
855 function action_unlock () {
856 // FIXME: This check is redundant.
857 //$user->requireAuth(WIKIAUTH_ADMIN);
858 $page = $this->getPage();
859 $page->set('locked', false);
860 $this->_dbi->touch();
861 $this->action_browse();
864 function action_remove () {
865 // FIXME: This check is redundant.
866 //$user->requireAuth(WIKIAUTH_ADMIN);
867 $pagename = $this->getArg('pagename');
868 if (strstr($pagename,_('PhpWikiAdministration'))) {
869 $this->action_browse();
871 include('lib/removepage.php');
876 function action_xmlrpc () {
877 include_once("lib/XmlRpcServer.php");
878 $xmlrpc = new XmlRpcServer($this);
882 function action_zip () {
883 include_once("lib/loadsave.php");
885 // I don't think it hurts to add cruft at the end of the zip file.
886 //echo "\n========================================================\n";
887 //echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
890 function action_ziphtml () {
891 include_once("lib/loadsave.php");
892 MakeWikiZipHtml($this);
893 // I don't think it hurts to add cruft at the end of the zip file.
894 echo "\n========================================================\n";
895 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
898 function action_dumpserial () {
899 include_once("lib/loadsave.php");
903 function action_dumphtml () {
904 include_once("lib/loadsave.php");
905 DumpHtmlToDir($this);
908 function action_upload () {
909 include_once("lib/loadsave.php");
913 function action_upgrade () {
914 include_once("lib/loadsave.php");
915 include_once("lib/upgrade.php");
919 function action_loadfile () {
920 include_once("lib/loadsave.php");
921 LoadFileOrDir($this);
924 function action_pdf () {
925 include_once("lib/pdf.php");
926 ConvertAndDisplayPdf($this);
932 function is_safe_action ($action) {
933 return WikiRequest::requiredAuthorityForAction($action) < WIKIAUTH_ADMIN;
936 function validateSessionPath() {
937 // Try to defer any session.save_path PHP errors before any html
938 // is output, which causes some versions of IE to display a blank
939 // page (due to its strict mode while parsing a page?).
940 if (! is_writeable(ini_get('session.save_path'))) {
943 (sprintf(_("%s is not writable."),
944 _("The session.save_path directory"))
946 . sprintf(_("Please ensure that %s is writable, or redefine %s in config/config.ini."),
947 sprintf(_("the directory '%s'"),
948 ini_get('session.save_path')),
951 . sprintf(_("Attempting to use the directory '%s' instead."),
954 if (! is_writeable($tmpdir)) {
956 (sprintf(_("%s is not writable."), $tmpdir)
958 . _("Users will not be able to sign in.")
962 ini_set('session.save_path', $tmpdir);
968 validateSessionPath();
972 if ((DEBUG & 4) and extension_loaded("apd"))
973 apd_set_session_trace(9);
976 global $ErrorManager;
977 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE|E_USER_WARNING);
978 $request = new WikiRequest();
980 $action = $request->getArg('action');
981 if (substr($action, 0, 3) != 'zip') {
982 if ($action == 'pdf')
983 $ErrorManager->setPostponedErrorMask(-1);
984 else // reject postponing of warnings
985 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
989 * Allow for disabling of markup cache.
990 * (Mostly for debugging ... hopefully.)
992 * See also <?plugin WikiAdminUtils action=purge-cache ?>
994 if (!defined('WIKIDB_NOCACHE_MARKUP') and $request->getArg('nocache'))
995 define('WIKIDB_NOCACHE_MARKUP', $request->getArg('nocache'));
997 // Initialize with system defaults in case user not logged in.
998 // Should this go into constructor?
999 $request->initializeTheme();
1001 $request->updateAuthAndPrefs();
1002 $request->initializeLang();
1005 //if ($user->is_authenticated())
1006 // $LogEntry->user = $user->getId();
1008 $request->possiblyDeflowerVirginWiki();
1010 if (defined('WIKI_XMLRPC') and WIKI_XMLRPC) return;
1011 if (defined('WIKI_SOAP') and WIKI_SOAP) return;
1013 $validators = array('wikiname' => WIKI_NAME,
1014 'args' => hash($request->getArgs()),
1015 'prefs' => hash($request->getPrefs()));
1016 if (CACHE_CONTROL == 'STRICT') {
1017 $dbi = $request->getDbh();
1018 $timestamp = $dbi->getTimestamp();
1019 $validators['mtime'] = $timestamp;
1020 $validators['%mtime'] = (int)$timestamp;
1022 // FIXME: we should try to generate strong validators when possible,
1023 // but for now, our validator is weak, since equal validators do not
1024 // indicate byte-level equality of content. (Due to DEBUG timing output, etc...)
1026 // (If DEBUG if off, this may be a strong validator, but I'm going
1027 // to go the paranoid route here pending further study and testing.)
1029 $validators['%weak'] = true;
1030 $request->setValidators($validators);
1032 $request->handleAction();
1034 if (defined('DEBUG') and DEBUG & 4) phpinfo(INFO_VARIABLES);
1038 $x = error_reporting(); // why is it 1 here? should be E_ALL
1039 error_reporting(E_ALL);
1043 // $Log: not supported by cvs2svn $
1044 // Revision 1.163 2004/06/13 11:35:32 rurban
1045 // check for create action on action=edit not to fool PagePerm checks
1047 // Revision 1.162 2004/06/08 10:05:11 rurban
1048 // simplified admin action shortcuts
1050 // Revision 1.161 2004/06/07 22:58:40 rurban
1051 // simplified chown, setacl, dump actions
1053 // Revision 1.160 2004/06/07 22:44:14 rurban
1054 // added simplified chown, setacl actions
1056 // Revision 1.159 2004/06/06 16:58:51 rurban
1057 // added more required ActionPages for foreign languages
1058 // install now english ActionPages if no localized are found. (again)
1059 // fixed default anon user level to be 0, instead of -1
1060 // (wrong "required administrator to view this page"...)
1062 // Revision 1.158 2004/06/04 20:32:53 rurban
1063 // Several locale related improvements suggested by Pierrick Meignen
1064 // LDAP fix by John Cole
1065 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
1067 // Revision 1.157 2004/06/04 12:40:21 rurban
1068 // Restrict valid usernames to prevent from attacks against external auth or compromise
1070 // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
1071 // Fxied more warnings
1073 // Revision 1.156 2004/06/03 17:58:16 rurban
1074 // support immediate LANG and THEME switch inside a session
1076 // Revision 1.155 2004/06/03 10:18:19 rurban
1077 // fix FileUser locking issues, new config ENABLE_PAGEPERM
1079 // Revision 1.154 2004/06/02 18:01:46 rurban
1080 // init global FileFinder to add proper include paths at startup
1081 // adds PHPWIKI_DIR if started from another dir, lib/pear also
1082 // fix slashify for Windows
1083 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
1085 // Revision 1.153 2004/06/01 15:28:00 rurban
1086 // AdminUser only ADMIN_USER not member of Administrators
1087 // some RateIt improvements by dfrankow
1088 // edit_toolbar buttons
1090 // Revision 1.152 2004/05/27 17:49:06 rurban
1091 // renamed DB_Session to DbSession (in CVS also)
1092 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
1093 // remove leading slash in error message
1094 // added force_unlock parameter to File_Passwd (no return on stale locks)
1095 // fixed adodb session AffectedRows
1096 // added FileFinder helpers to unify local filenames and DATA_PATH names
1097 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
1099 // Revision 1.151 2004/05/25 12:40:48 rurban
1100 // trim the pagename
1102 // Revision 1.150 2004/05/25 10:18:44 rurban
1103 // Check for UTF-8 URLs; Internet Explorer produces these if you
1104 // type non-ASCII chars in the URL bar or follow unescaped links.
1105 // Fixes sf.net bug #953949
1106 // src: languages/Language.php:checkTitleEncoding() from mediawiki
1108 // Revision 1.149 2004/05/18 13:31:19 rurban
1109 // hold warnings until headers are sent. new Error-style with collapsed output of repeated messages
1111 // Revision 1.148 2004/05/17 17:43:29 rurban
1112 // CGI: no PATH_INFO fix
1114 // Revision 1.147 2004/05/15 19:48:33 rurban
1115 // fix some too loose PagePerms for signed, but not authenticated users
1116 // (admin, owner, creator)
1117 // no double login page header, better login msg.
1118 // moved action_pdf to lib/pdf.php
1120 // Revision 1.146 2004/05/15 18:31:01 rurban
1121 // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
1123 // Revision 1.145 2004/05/12 10:49:55 rurban
1124 // require_once fix for those libs which are loaded before FileFinder and
1125 // its automatic include_path fix, and where require_once doesn't grok
1126 // dirname(__FILE__) != './lib'
1127 // upgrade fix with PearDB
1128 // navbar.tmpl: remove spaces for IE button alignment
1130 // Revision 1.144 2004/05/06 19:26:16 rurban
1131 // improve stability, trying to find the InlineParser endless loop on sf.net
1133 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
1135 // Revision 1.143 2004/05/06 17:30:38 rurban
1136 // CategoryGroup: oops, dos2unix eol
1137 // improved phpwiki_version:
1138 // pre -= .0001 (1.3.10pre: 1030.099)
1139 // -p1 += .001 (1.3.9-p1: 1030.091)
1140 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
1141 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
1142 // backend->backendType(), backend->database(),
1143 // backend->listOfFields(),
1144 // backend->listOfTables(),
1146 // Revision 1.142 2004/05/04 22:34:25 rurban
1149 // Revision 1.141 2004/05/03 13:16:47 rurban
1150 // fixed UserPreferences update, esp for boolean and int
1152 // Revision 1.140 2004/05/02 21:26:38 rurban
1153 // limit user session data (HomePageHandle and auth_dbi have to invalidated anyway)
1154 // because they will not survive db sessions, if too large.
1155 // extended action=upgrade
1156 // some WikiTranslation button work
1157 // revert WIKIAUTH_UNOBTAINABLE (need it for main.php)
1158 // some temp. session debug statements
1160 // Revision 1.139 2004/05/02 15:10:07 rurban
1161 // new finally reliable way to detect if /index.php is called directly
1162 // and if to include lib/main.php
1163 // new global AllActionPages
1164 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
1165 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
1166 // PageGroupTestOne => subpages
1167 // renamed PhpWikiRss to PhpWikiRecentChanges
1168 // more docs, default configs, ...
1170 // Revision 1.138 2004/05/01 15:59:29 rurban
1171 // more php-4.0.6 compatibility: superglobals
1173 // Revision 1.137 2004/04/29 19:39:44 rurban
1174 // special support for formatted plugins (one-liners)
1175 // like <small><plugin BlaBla ></small>
1176 // iter->asArray() helper for PopularNearby
1177 // db_session for older php's (no &func() allowed)
1179 // Revision 1.136 2004/04/29 17:18:19 zorloc
1180 // 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.
1182 // Revision 1.135 2004/04/26 12:15:01 rurban
1183 // check default config values
1185 // Revision 1.134 2004/04/23 06:46:37 zorloc
1186 // Leave DB connection open when USE_DB_SESSION is true so that session info can be written to the DB.
1188 // Revision 1.133 2004/04/20 18:10:31 rurban
1189 // config refactoring:
1190 // FileFinder is needed for WikiFarm scripts calling index.php
1191 // config run-time calls moved to lib/IniConfig.php:fix_configs()
1192 // added PHPWIKI_DIR smart-detection code (Theme finder)
1193 // moved FileFind to lib/FileFinder.php
1194 // cleaned lib/config.php
1196 // Revision 1.132 2004/04/19 21:51:41 rurban
1197 // php5 compatibility: it works!
1199 // Revision 1.131 2004/04/19 18:27:45 rurban
1200 // Prevent from some PHP5 warnings (ref args, no :: object init)
1201 // php5 runs now through, just one wrong XmlElement object init missing
1202 // Removed unneccesary UpgradeUser lines
1203 // Changed WikiLink to omit version if current (RecentChanges)
1205 // Revision 1.130 2004/04/18 00:25:53 rurban
1206 // allow "0" pagename
1208 // Revision 1.129 2004/04/07 23:13:19 rurban
1209 // fixed pear/File_Passwd for Windows
1210 // fixed FilePassUser sessions (filehandle revive) and password update
1212 // Revision 1.128 2004/04/02 15:06:55 rurban
1213 // fixed a nasty ADODB_mysql session update bug
1214 // improved UserPreferences layout (tabled hints)
1215 // fixed UserPreferences auth handling
1216 // improved auth stability
1217 // improved old cookie handling: fixed deletion of old cookies with paths
1219 // Revision 1.127 2004/03/25 17:00:31 rurban
1220 // more code to convert old-style pref array to new hash
1222 // Revision 1.126 2004/03/24 19:39:03 rurban
1223 // php5 workaround code (plus some interim debugging code in XmlElement)
1224 // php5 doesn't work yet with the current XmlElement class constructors,
1225 // WikiUserNew does work better than php4.
1226 // rewrote WikiUserNew user upgrading to ease php5 update
1227 // fixed pref handling in WikiUserNew
1228 // added Email Notification
1229 // added simple Email verification
1230 // removed emailVerify userpref subclass: just a email property
1231 // changed pref binary storage layout: numarray => hash of non default values
1232 // print optimize message only if really done.
1233 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1234 // prefs should be stored in db or homepage, besides the current session.
1236 // Revision 1.125 2004/03/14 16:30:52 rurban
1237 // db-handle session revivification, dba fixes
1239 // Revision 1.124 2004/03/12 15:48:07 rurban
1240 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
1241 // simplified lib/stdlib.php:explodePageList
1243 // Revision 1.123 2004/03/10 15:41:27 rurban
1244 // use default pref mysql table
1246 // Revision 1.122 2004/03/08 18:17:09 rurban
1247 // added more WikiGroup::getMembersOf methods, esp. for special groups
1248 // fixed $LDAP_SET_OPTIONS
1249 // fixed _AuthInfo group methods
1251 // Revision 1.121 2004/03/01 13:48:45 rurban
1253 // p[] consistency fix
1255 // Revision 1.120 2004/03/01 10:22:41 rurban
1256 // initializeTheme optimize
1258 // Revision 1.119 2004/02/26 20:45:06 rurban
1259 // check for ALLOW_ANON_USER = false
1261 // Revision 1.118 2004/02/26 01:32:03 rurban
1262 // fixed session login with old WikiUser object. strangely, the errormask gets corruoted to 1, Pear???
1264 // Revision 1.117 2004/02/24 17:19:37 rurban
1265 // debugging helpers only
1267 // Revision 1.116 2004/02/24 15:17:14 rurban
1268 // 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
1270 // Revision 1.115 2004/02/15 21:34:37 rurban
1271 // PageList enhanced and improved.
1272 // fixed new WikiAdmin... plugins
1273 // editpage, Theme with exp. htmlarea framework
1274 // (htmlarea yet committed, this is really questionable)
1275 // WikiUser... code with better session handling for prefs
1276 // enhanced UserPreferences (again)
1277 // RecentChanges for show_deleted: how should pages be deleted then?
1279 // Revision 1.114 2004/02/15 17:30:13 rurban
1280 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
1281 // fixed getPreferences() (esp. from sessions)
1282 // fixed setPreferences() (update and set),
1283 // fixed AdoDb DB statements,
1284 // update prefs only at UserPreferences POST (for testing)
1285 // unified db prefs methods (but in external pref classes yet)
1287 // Revision 1.113 2004/02/12 13:05:49 rurban
1288 // Rename functional for PearDB backend
1289 // some other minor changes
1290 // SiteMap comes with a not yet functional feature request: includepages (tbd)
1292 // Revision 1.112 2004/02/09 03:58:12 rurban
1293 // for now default DB_SESSION to false
1295 // * not existing perms will now query the parent, and not
1296 // return the default perm
1297 // * added pagePermissions func which returns the object per page
1298 // * added getAccessDescription
1300 // * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
1301 // * force init of authdbh in the 2 db classes
1303 // * fixed session handling (not triple auth request anymore)
1304 // * don't store cookie prefs with sessions
1305 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
1307 // Revision 1.111 2004/02/07 10:41:25 rurban
1308 // fixed auth from session (still double code but works)
1310 // fixed DbPassUser upgrade and policy=old
1313 // Revision 1.110 2004/02/03 09:45:39 rurban
1314 // LDAP cleanup, start of new Pref classes
1316 // Revision 1.109 2004/01/30 19:57:58 rurban
1317 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
1319 // Revision 1.108 2004/01/28 14:34:14 rurban
1320 // session table takes the common prefix
1321 // + various minor stuff
1322 // reallow password changing
1324 // Revision 1.107 2004/01/27 23:23:39 rurban
1325 // renamed ->Username => _userid for consistency
1326 // renamed mayCheckPassword => mayCheckPass
1327 // fixed recursion problem in WikiUserNew
1328 // fixed bogo login (but not quite 100% ready yet, password storage)
1330 // Revision 1.106 2004/01/26 09:17:49 rurban
1331 // * changed stored pref representation as before.
1332 // the array of objects is 1) bigger and 2)
1333 // less portable. If we would import packed pref
1334 // objects and the object definition was changed, PHP would fail.
1335 // This doesn't happen with an simple array of non-default values.
1336 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1337 // understands the interim format of array of objects also.
1338 // * simplified $prefs->get() and fixed $prefs->set()
1339 // * added $user->_userid and class '_WikiUser' portability functions
1340 // * fixed $user object ->_level upgrading, mostly using sessions.
1341 // this fixes yesterdays problems with loosing authorization level.
1342 // * fixed WikiUserNew::checkPass to return the _level
1343 // * fixed WikiUserNew::isSignedIn
1344 // * added explodePageList to class PageList, support sortby arg
1345 // * fixed UserPreferences for WikiUserNew
1346 // * fixed WikiPlugin for empty defaults array
1347 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1348 // removed sort arg, support sortby arg
1350 // Revision 1.105 2004/01/25 03:57:15 rurban
1351 // WikiUserNew support (temp. ENABLE_USER_NEW constant)
1353 // Revision 1.104 2003/12/26 06:41:16 carstenklapp
1354 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
1355 // so they don't prevent IE from partially (or not at all) rendering the
1356 // page. This should help a little for the IE user who encounters trouble
1357 // when setting up a new PhpWiki for the first time.
1359 // Revision 1.103 2003/12/02 00:10:00 carstenklapp
1360 // Bugfix: Ongoing work to untangle UserPreferences/WikiUser/request code
1361 // mess: UserPreferences should take effect immediately now upon signing
1364 // Revision 1.102 2003/11/25 22:55:32 carstenklapp
1365 // Localization bugfix: For wikis where English is not the default system
1366 // language, make sure that the authority error message (i.e. "You must
1367 // sign in to edit pages in this wiki" etc.) is displayed in the wiki's
1368 // default language. Previously it would always display in English.
1369 // (Added call to update_locale() before displaying any messages prior to
1370 // the login prompt.)
1372 // Revision 1.101 2003/11/25 21:49:44 carstenklapp
1373 // Bugfix: For a non-english wiki or when the user's preference is not
1374 // english, the wiki would always use the english ActionPage first if it
1375 // was present rather than the appropriate localised variant. (PhpWikis
1376 // running only in english or Wikis running ONLY without any english
1377 // ActionPages would not notice this bug, only when both english and
1378 // localised ActionPages were in the DB.) Now we check for the localised
1381 // Revision 1.100 2003/11/18 16:54:18 carstenklapp
1382 // Reformatting only: Tabs to spaces, added rcs log.
1389 // c-basic-offset: 4
1390 // c-hanging-comment-ender-p: nil
1391 // indent-tabs-mode: nil