2 rcs_id('$Id: main.php,v 1.13 2001-04-09 19:31:49 dairiki Exp $');
3 include "lib/config.php";
4 include "lib/stdlib.php";
5 include "lib/userauth.php";
6 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)
17 && (!isset($REDIRECT_URL) || !preg_match(',/$,', $REDIRECT_URL)))
19 $LogEntry->status = 302; // "302 Found"
20 header("Location: " . SERVER_URL . preg_replace('/(\?|$)/', '/\1', $REQUEST_URI, 1));
24 function DeducePagename ()
26 global $pagename, $PATH_INFO, $QUERY_STRING;
29 return fix_magic_quotes_gpc($pagename);
31 if (USE_PATH_INFO && isset($PATH_INFO))
33 fix_magic_quotes_gpc($PATH_INFO);
34 if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $PATH_INFO, $m))
38 if (isset($QUERY_STRING) && preg_match('/^[^&=]+$/', $QUERY_STRING))
39 return urldecode(fix_magic_quotes_gpc($QUERY_STRING));
41 return gettext("HomePage");
44 $pagename = DeducePagename();
48 $action = trim(fix_magic_quotes_gpc($action));
50 else if (isset($diff))
52 // Fix for compatibility with very old diff links in RecentChanges.
53 // (The [phpwiki:?diff=PageName] style links are fixed elsewhere.)
55 $pagename = fix_magic_quotes_gpc($diff);
63 function IsSafeAction ($action)
65 if (! ZIPDUMP_AUTH and $action == 'zip')
67 return in_array ( $action, array('browse',
68 'info', 'diff', 'search',
74 function get_auth_mode ($action)
82 if (IsSafeAction($action))
85 return 'REQUIRE_AUTH';
90 $user = new WikiUser(get_auth_mode($action));
91 if ($user->is_authenticated())
92 $LogEntry->user = $user->id();
96 // All requests require the database
97 $dbi = OpenDataBase($WikiPageStore);
99 if ( $action == 'browse' && $pagename == gettext("HomePage") ) {
100 // if there is no HomePage, create a basic set of Wiki pages
101 if ( ! IsWikiPage($dbi, gettext("HomePage")) ) {
102 include_once("lib/loadsave.php");
108 // FIXME: I think this is redundant.
109 if (!IsSafeAction($action))
110 $user->must_be_admin($action);
111 if (isset($DisabledActions) && in_array($action, $DisabledActions))
112 ExitWiki(gettext("Action $action is disabled in this wiki."));
114 // Enable the output of most of the warning messages.
115 // The warnings will screw up zip files and setpref though.
116 if ($action != 'zip' && $action != 'setprefs')
117 PostponeErrorMessages(E_NOTICE);
121 include "lib/editpage.php";
125 if (isset($searchtype) && ($searchtype == 'full')) {
126 include "lib/fullsearch.php";
129 include "lib/search.php";
134 include "lib/savepage.php";
137 include "lib/pageinfo.php";
140 include "lib/diff.php";
144 include_once("lib/loadsave.php");
145 MakeWikiZip($dbi, isset($include) && $include == 'all');
146 // I don't think it hurts to add cruft at the end of the zip file.
147 echo "\n========================================================\n";
148 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$RCS_IDS\n";
152 include_once("lib/loadsave.php");
153 LoadPostFile($dbi, 'file');
157 if (empty($directory))
158 ExitWiki(gettext("You must specify a directory to dump to"));
160 include_once("lib/loadsave.php");
161 DumpToDir($dbi, fix_magic_quotes_gpc($directory));
166 ExitWiki(gettext("You must specify a source to read from"));
168 include_once("lib/loadsave.php");
169 LoadFileOrDir($dbi, fix_magic_quotes_gpc($source));
173 include 'admin/removepage.php';
178 include "admin/lockpage.php";
179 include "lib/display.php";
183 $prefs = $user->getPreferences($GLOBALS);
184 if (!empty($edit_area_width))
185 $prefs['edit_area.width'] = $edit_area_width;
186 if (!empty($edit_area_height))
187 $prefs['edit_area.height'] = $edit_area_height;
188 $user->setPreferences($prefs);
190 PostponeErrorMessages(E_ALL & ~E_NOTICE);
192 include "lib/display.php";
198 include "lib/display.php";
202 echo QElement('p', sprintf("Bad action: '%s'", urlencode($action)));
211 // c-file-style: "ellemtel"