2 rcs_id('$Id: main.php,v 1.14 2001-09-18 19:16:23 dairiki Exp $');
4 include "lib/config.php";
5 include "lib/stdlib.php";
6 //include "lib/logger.php";
7 require_once('lib/Request.php');
8 require_once("lib/WikiUser.php");
9 require_once('lib/WikiDB.php');
12 function deduce_pagename ($request) {
13 if ($request->getArg('pagename'))
14 return $request->getArg('pagename');
17 $pathinfo = $request->get('PATH_INFO');
18 if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $pathinfo, $m))
22 $query_string = $request->get('QUERY_STRING');
23 if (preg_match('/^[^&=]+$/', $query_string))
24 return urldecode($query_string);
26 return gettext("HomePage");
29 function is_safe_action ($action) {
30 if (! ZIPDUMP_AUTH and ($action == 'zip' || $action == 'xmldump'))
32 return in_array ( $action, array('browse',
33 'info', 'diff', 'search',
39 function get_auth_mode ($action) {
46 if (is_safe_action($action))
49 return 'REQUIRE_AUTH';
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');
73 global $user; // FIXME: can we make this non-global?
74 $user = new WikiUser($request, get_auth_mode($action));
76 //if ($user->is_authenticated())
77 // $LogEntry->user = $user->id();
79 // All requests require the database
80 global $dbi; // FIXME: can we keep this non-global?
81 $dbi = WikiDB::open($GLOBALS['DBParams']);
83 if ( $action == 'browse' && $request->getArg('pagename') == gettext("HomePage") ) {
84 // if there is no HomePage, create a basic set of Wiki pages
85 if ( ! $dbi->isWikiPage(gettext("HomePage")) ) {
86 include_once("lib/loadsave.php");
92 // FIXME: I think this is redundant.
93 if (!is_safe_action($action))
94 $user->must_be_admin($action);
96 if (isset($DisabledActions) && in_array($action, $DisabledActions))
97 ExitWiki(sprintf(gettext("Action %s is disabled in this wiki."), $action));
99 // Enable the output of most of the warning messages.
100 // The warnings will screw up zip files and setpref though.
101 if ($action != 'zip' && $action != 'setprefs') {
102 global $ErrorManager;
103 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
109 $request->compress_output();
110 include "lib/editpage.php";
111 editPage($dbi, $request);
115 $request->compress_output();
116 if ($request->getArg('searchtype') == 'full') {
117 include "lib/fullsearch.php";
120 include "lib/search.php";
125 $request->compress_output();
126 include "lib/savepage.php";
127 savePage($dbi, $request);
130 $request->compress_output();
131 include "lib/pageinfo.php";
134 $request->compress_output();
135 include_once "lib/diff.php";
136 showDiff($dbi, $request);
140 include_once("lib/loadsave.php");
141 MakeWikiZip($dbi, $request);
142 // I don't think it hurts to add cruft at the end of the zip file.
143 echo "\n========================================================\n";
144 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
150 if ($request->getArg('include') == 'all')
152 require_once("lib/libxml.php");
153 $xmlwriter = new WikiXmlWriter;
155 $xmlwriter->writeComment("PhpWiki " . PHPWIKI_VERSION . " source:\n$RCS_IDS\n");
156 $xmlwriter->writeDatabase($dbi, $limit);
161 include_once("lib/loadsave.php");
162 LoadPostFile($dbi, $request);
166 include_once("lib/loadsave.php");
167 DumpToDir($dbi, $request);
171 include_once("lib/loadsave.php");
172 LoadFileOrDir($dbi, $request);
176 include 'admin/removepage.php';
181 $user->must_be_admin("lock or unlock pages");
182 $page = $dbi->getPage($request->getArg('pagename'));
183 $page->set('locked', $action == 'lock');
185 $request->compress_output();
186 include_once("lib/display.php");
187 displayPage($dbi, $request);
191 $prefs = $user->getPreferences();
192 $edit_area_width = $request->getArg('edit_area_width');
193 $edit_area_height = $request->getArg('edit_area_height');
194 if ($edit_area_width)
195 $prefs['edit_area.width'] = $edit_area_width;
196 if ($edit_area_height)
197 $prefs['edit_area.height'] = $edit_area_height;
198 $user->setPreferences($prefs);
199 $ErrorManager->setPostponedErrorMask(E_ALL & ~E_NOTICE);
201 $request->compress_output();
202 include_once("lib/display.php");
203 displayPage($dbi, $request);
209 $request->compress_output();
210 include_once("lib/display.php");
211 displayPage($dbi, $request);
215 echo QElement('p', sprintf("Bad action: '%s'", urlencode($action)));
221 $request = new Request;
229 // c-hanging-comment-ender-p: nil
230 // indent-tabs-mode: nil