2 rcs_id('$Id: main.php,v 1.5 2001-02-16 04:43:08 dairiki Exp $');
3 include "lib/config.php";
4 include "lib/stdlib.php";
5 include "lib/userauth.php";
9 include "lib/logger.php";
10 $LogEntry = new AccessLogEntry;
12 function _write_log () { $GLOBALS['LogEntry']->write(ACCESS_LOG); }
13 register_shutdown_function('_write_log');
16 if (USE_PATH_INFO && !isset($PATH_INFO))
18 $LogEntry->status = 302; // "302 Found"
19 header("Location: " . SERVER_URL . $REQUEST_URI);
23 function DeducePagename ()
25 global $pagename, $PATH_INFO;
28 return fix_magic_quotes_gpc($pagename);
30 if (USE_PATH_INFO && isset($PATH_INFO))
32 fix_magic_quotes_gpc($PATH_INFO);
33 if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $PATH_INFO, $m))
37 return gettext("FrontPage");
40 $pagename = DeducePagename();
44 $action = trim(fix_magic_quotes_gpc($action));
46 else if (isset($diff))
48 // Fix for compatibility with very old diff links in RecentChanges.
49 // (The [phpwiki:?diff=PageName] style links are fixed elsewhere.)
51 $pagename = fix_magic_quotes_gpc($diff);
59 function IsSafeAction ($action)
61 if (! ZIPDUMP_AUTH and $action == 'zip')
63 return in_array ( $action, array('browse',
64 'info', 'diff', 'search',
70 function get_auth_mode ($action)
78 if (IsSafeAction($action))
81 return 'REQUIRE_AUTH';
86 $user = new WikiUser(get_auth_mode($action));
87 if (ACCESS_LOG and $user->is_authenticated())
88 $LogEntry->user = $user->id;
92 // All requests require the database
93 $dbi = OpenDataBase($WikiPageStore);
95 // if there is no FrontPage, create a basic set of Wiki pages
96 if ( ! IsWikiPage($dbi, gettext("FrontPage")) )
98 include_once("lib/loadsave.php");
103 // FIXME: I think this is redundant.
104 if (!IsSafeAction($action))
105 $user->must_be_admin($action);
106 if (isset($DisabledActions) && in_array($action, $DisabledActions))
107 ExitWiki(gettext("Action $action is disabled in this wiki."));
109 // Enable the output of most of the warning messages.
110 // The warnings will screw up zip files and setpref though.
111 if ($action != 'zip' && $action != 'setprefs')
112 PostponeErrorMessages(E_NOTICE);
116 include "lib/editpage.php";
120 if (isset($searchtype) && ($searchtype == 'full')) {
121 include "lib/fullsearch.php";
124 include "lib/search.php";
129 include "lib/savepage.php";
132 include "lib/pageinfo.php";
135 include "lib/diff.php";
139 include_once("lib/loadsave.php");
140 MakeWikiZip($dbi, isset($include) && $include == 'all');
141 // I don't think it hurts to add cruft at the end of the zip file.
142 echo "\n========================================================\n";
143 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$RCS_IDS\n";
147 include_once("lib/loadsave.php");
148 LoadPostFile($dbi, 'file');
152 if (empty($directory))
153 ExitWiki(gettext("You must specify a directory to dump to"));
155 include_once("lib/loadsave.php");
156 DumpToDir($dbi, fix_magic_quotes_gpc($directory));
161 ExitWiki(gettext("You must specify a source to read from"));
163 include_once("lib/loadsave.php");
164 LoadFileOrDir($dbi, fix_magic_quotes_gpc($source));
168 include 'admin/removepage.php';
173 include "admin/lockpage.php";
174 include "lib/display.php";
178 $prefs = $user->getPreferences($GLOBALS);
179 if (!empty($edit_area_width))
180 $prefs['edit_area.width'] = $edit_area_width;
181 if (!empty($edit_area_height))
182 $prefs['edit_area.height'] = $edit_area_height;
183 $user->setPreferences($prefs);
185 PostponeErrorMessages(E_ALL & ~E_NOTICE);
187 include "lib/display.php";
193 include "lib/display.php";
197 echo QElement('p', sprintf("Bad action: '%s'", urlencode($action)));
206 // c-file-style: "ellemtel"