2 rcs_id('$Id: main.php,v 1.27 2002-01-22 03:17:47 dairiki Exp $');
5 include "lib/config.php";
6 include "lib/stdlib.php";
7 require_once('lib/Request.php');
8 require_once("lib/WikiUser.php");
9 require_once('lib/WikiDB.php');
11 if (defined('THEME')) {
12 include("themes/" . THEME . "/themeinfo.php");
15 include("themes/default/themeinfo.php");
17 assert(!empty($Theme));
20 function deduce_pagename ($request) {
21 if ($request->getArg('pagename'))
22 return $request->getArg('pagename');
25 $pathinfo = $request->get('PATH_INFO');
26 if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $pathinfo, $m))
30 $query_string = $request->get('QUERY_STRING');
31 if (preg_match('/^[^&=]+$/', $query_string))
32 return urldecode($query_string);
37 function is_safe_action ($action) {
38 if (! ZIPDUMP_AUTH and ($action == 'zip' || $action == 'xmldump'))
40 return in_array ( $action, array('browse', 'info',
46 function authlevelForAction ($action) {
47 if (is_safe_action($action))
50 return WIKIAUTH_ADMIN;
53 function main ($request) {
56 if (USE_PATH_INFO && ! $request->get('PATH_INFO')
57 && ! preg_match(',/$,', $request->get('REDIRECT_URL'))) {
58 $request->redirect(SERVER_URL
59 . preg_replace('/(\?|$)/', '/\1',
60 $request->get('REQUEST_URI'),
65 $request->setArg('pagename', deduce_pagename($request));
66 global $pagename; // FIXME: can we make this non-global?
67 $pagename = $request->getArg('pagename');
69 $action = $request->getArg('action');
72 $request->setArg('action', $action);
75 global $user; // FIXME: can we make this non-global?
76 $user = new WikiUser($request);
77 $user->requireAuth( authlevelForAction($action) );
81 //if ($user->is_authenticated())
82 // $LogEntry->user = $user->getId();
84 // All requests require the database
85 global $dbi; // FIXME: can we keep this non-global?
86 $dbi = WikiDB::open($GLOBALS['DBParams']);
88 // FIXME: need something more robust here...
89 if ( $action == 'browse' && $request->getArg('pagename') == _("HomePage") ) {
90 // if there is no HomePage, create a basic set of Wiki pages
91 if ( ! $dbi->isWikiPage(_("HomePage")) ) {
92 include_once("lib/loadsave.php");
98 // FIXME: I think this is redundant.
99 //if (!is_safe_action($action))
100 // $user->must_be_admin($action);
102 // FIXME: this should be moved higher in the logic.
103 if (isset($DisabledActions) && in_array($action, $DisabledActions))
104 ExitWiki(sprintf(_("Action %s is disabled in this wiki."), $action));
106 // Enable the output of most of the warning messages.
107 // The warnings will screw up zip files and setpref though.
108 global $ErrorManager;
109 if ($action != 'zip' && $action != 'setprefs') {
110 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
116 $request->compress_output();
117 include "lib/editpage.php";
118 editPage($dbi, $request);
122 // This is obsolete: reformulate URL and redirect.
123 // FIXME: this whole section should probably be deleted.
124 if ($request->getArg('searchtype') == 'full') {
125 $search_page = _("FullTextSearch");
128 $search_page = _("TitleSearch");
130 $request->redirect(WikiURL($search_page,
131 array('s' => $request->getArg('searchterm')),
136 $request->compress_output();
137 include "lib/savepage.php";
138 savePage($dbi, $request);
141 $request->compress_output();
142 include_once "lib/diff.php";
143 showDiff($dbi, $request);
147 include_once("lib/loadsave.php");
148 MakeWikiZip($dbi, $request);
149 // I don't think it hurts to add cruft at the end of the zip file.
150 echo "\n========================================================\n";
151 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
154 /* Not yet implemented:
158 if ($request->getArg('include') == 'all')
160 require_once("lib/libxml.php");
161 $xmlwriter = new WikiXmlWriter;
163 $xmlwriter->writeComment("PhpWiki " . PHPWIKI_VERSION
164 . " source:\n$RCS_IDS\n");
165 $xmlwriter->writeDatabase($dbi, $limit);
171 include_once("lib/loadsave.php");
172 LoadPostFile($dbi, $request);
176 include_once("lib/loadsave.php");
177 DumpToDir($dbi, $request);
181 include_once("lib/loadsave.php");
182 LoadFileOrDir($dbi, $request);
186 include 'lib/removepage.php';
191 // FIXME: This check is redundant.
192 $user->requireAuth(WIKIAUTH_ADMIN);
193 $page = $dbi->getPage($request->getArg('pagename'));
194 $page->set('locked', $action == 'lock');
196 $request->compress_output();
197 include_once("lib/display.php");
198 displayPage($dbi, $request);
202 $prefs = $user->getPreferences();
203 $edit_area_width = $request->getArg('edit_area_width');
204 $edit_area_height = $request->getArg('edit_area_height');
205 if ($edit_area_width)
206 $prefs['edit_area.width'] = $edit_area_width;
207 if ($edit_area_height)
208 $prefs['edit_area.height'] = $edit_area_height;
209 $user->setPreferences($prefs);
210 $ErrorManager->setPostponedErrorMask(E_ALL & ~E_NOTICE);
212 $request->compress_output();
213 include_once("lib/display.php");
214 displayPage($dbi, $request);
221 $request->compress_output();
222 include_once("lib/display.php");
223 displayPage($dbi, $request);
227 ProntXML(HTML::p(fmt("Bad action: '%s'", $action)));
233 $request = new Request;
241 // c-hanging-comment-ender-p: nil
242 // indent-tabs-mode: nil