2 rcs_id('$Id: main.php,v 1.25 2002-01-19 07:21:58 dairiki Exp $');
4 include "lib/config.php";
5 include "lib/stdlib.php";
6 require_once('lib/Request.php');
7 require_once("lib/WikiUser.php");
8 require_once('lib/WikiDB.php');
10 if (defined('THEME')) {
11 include("themes/" . THEME . "/themeinfo.php");
14 include("themes/default/themeinfo.php");
16 assert(!empty($Theme));
19 function deduce_pagename ($request) {
20 if ($request->getArg('pagename'))
21 return $request->getArg('pagename');
24 $pathinfo = $request->get('PATH_INFO');
25 if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $pathinfo, $m))
29 $query_string = $request->get('QUERY_STRING');
30 if (preg_match('/^[^&=]+$/', $query_string))
31 return urldecode($query_string);
36 function is_safe_action ($action) {
37 if (! ZIPDUMP_AUTH and ($action == 'zip' || $action == 'xmldump'))
39 return in_array ( $action, array('browse', 'info',
45 function authlevelForAction ($action) {
46 if (is_safe_action($action))
49 return WIKIAUTH_ADMIN;
52 function main ($request) {
55 if (USE_PATH_INFO && ! $request->get('PATH_INFO')
56 && ! preg_match(',/$,', $request->get('REDIRECT_URL'))) {
57 $request->redirect(SERVER_URL
58 . preg_replace('/(\?|$)/', '/\1',
59 $request->get('REQUEST_URI'),
64 $request->setArg('pagename', deduce_pagename($request));
65 global $pagename; // FIXME: can we make this non-global?
66 $pagename = $request->getArg('pagename');
68 $action = $request->getArg('action');
71 $request->setArg('action', $action);
74 global $user; // FIXME: can we make this non-global?
75 $user = new WikiUser($request);
76 $user->requireAuth( authlevelForAction($action) );
80 //if ($user->is_authenticated())
81 // $LogEntry->user = $user->getId();
83 // All requests require the database
84 global $dbi; // FIXME: can we keep this non-global?
85 $dbi = WikiDB::open($GLOBALS['DBParams']);
87 // FIXME: need something more robust here...
88 if ( $action == 'browse' && $request->getArg('pagename') == _("HomePage") ) {
89 // if there is no HomePage, create a basic set of Wiki pages
90 if ( ! $dbi->isWikiPage(_("HomePage")) ) {
91 include_once("lib/loadsave.php");
97 // FIXME: I think this is redundant.
98 //if (!is_safe_action($action))
99 // $user->must_be_admin($action);
101 // FIXME: this should be moved higher in the logic.
102 if (isset($DisabledActions) && in_array($action, $DisabledActions))
103 ExitWiki(sprintf(_("Action %s is disabled in this wiki."), $action));
105 // Enable the output of most of the warning messages.
106 // The warnings will screw up zip files and setpref though.
107 global $ErrorManager;
108 if ($action != 'zip' && $action != 'setprefs') {
109 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
115 $request->compress_output();
116 include "lib/editpage.php";
117 editPage($dbi, $request);
121 // This is obsolete: reformulate URL and redirect.
122 // FIXME: this whole section should probably be deleted.
123 if ($request->getArg('searchtype') == 'full') {
124 $search_page = _("FullTextSearch");
127 $search_page = _("TitleSearch");
129 $request->redirect(WikiURL($search_page,
130 array('s' => $request->getArg('searchterm')),
135 $request->compress_output();
136 include "lib/savepage.php";
137 savePage($dbi, $request);
140 $request->compress_output();
141 include_once "lib/diff.php";
142 showDiff($dbi, $request);
146 include_once("lib/loadsave.php");
147 MakeWikiZip($dbi, $request);
148 // I don't think it hurts to add cruft at the end of the zip file.
149 echo "\n========================================================\n";
150 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
153 /* Not yet implemented:
157 if ($request->getArg('include') == 'all')
159 require_once("lib/libxml.php");
160 $xmlwriter = new WikiXmlWriter;
162 $xmlwriter->writeComment("PhpWiki " . PHPWIKI_VERSION
163 . " source:\n$RCS_IDS\n");
164 $xmlwriter->writeDatabase($dbi, $limit);
170 include_once("lib/loadsave.php");
171 LoadPostFile($dbi, $request);
175 include_once("lib/loadsave.php");
176 DumpToDir($dbi, $request);
180 include_once("lib/loadsave.php");
181 LoadFileOrDir($dbi, $request);
185 include 'lib/removepage.php';
190 // FIXME: This check is redundant.
191 $user->requireAuth(WIKIAUTH_ADMIN);
192 $page = $dbi->getPage($request->getArg('pagename'));
193 $page->set('locked', $action == 'lock');
195 $request->compress_output();
196 include_once("lib/display.php");
197 displayPage($dbi, $request);
201 $prefs = $user->getPreferences();
202 $edit_area_width = $request->getArg('edit_area_width');
203 $edit_area_height = $request->getArg('edit_area_height');
204 if ($edit_area_width)
205 $prefs['edit_area.width'] = $edit_area_width;
206 if ($edit_area_height)
207 $prefs['edit_area.height'] = $edit_area_height;
208 $user->setPreferences($prefs);
209 $ErrorManager->setPostponedErrorMask(E_ALL & ~E_NOTICE);
211 $request->compress_output();
212 include_once("lib/display.php");
213 displayPage($dbi, $request);
220 $request->compress_output();
221 include_once("lib/display.php");
222 displayPage($dbi, $request);
226 echo QElement('p', sprintf(_("Bad action: '%s'"), urlencode($action)));
232 $request = new Request;
240 // c-hanging-comment-ender-p: nil
241 // indent-tabs-mode: nil