2 rcs_id('$Id: main.php,v 1.11 2001-04-06 18:21:37 wainstead 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 there is no HomePage, create a basic set of Wiki pages
100 if ( ! IsWikiPage($dbi, gettext("HomePage")) )
102 include_once("lib/loadsave.php");
107 // FIXME: I think this is redundant.
108 if (!IsSafeAction($action))
109 $user->must_be_admin($action);
110 if (isset($DisabledActions) && in_array($action, $DisabledActions))
111 ExitWiki(gettext("Action $action is disabled in this wiki."));
113 // Enable the output of most of the warning messages.
114 // The warnings will screw up zip files and setpref though.
115 if ($action != 'zip' && $action != 'setprefs')
116 PostponeErrorMessages(E_NOTICE);
120 include "lib/editpage.php";
124 if (isset($searchtype) && ($searchtype == 'full')) {
125 include "lib/fullsearch.php";
128 include "lib/search.php";
133 include "lib/savepage.php";
136 include "lib/pageinfo.php";
139 include "lib/diff.php";
143 include_once("lib/loadsave.php");
144 MakeWikiZip($dbi, isset($include) && $include == 'all');
145 // I don't think it hurts to add cruft at the end of the zip file.
146 echo "\n========================================================\n";
147 echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$RCS_IDS\n";
151 include_once("lib/loadsave.php");
152 LoadPostFile($dbi, 'file');
156 if (empty($directory))
157 ExitWiki(gettext("You must specify a directory to dump to"));
159 include_once("lib/loadsave.php");
160 DumpToDir($dbi, fix_magic_quotes_gpc($directory));
165 ExitWiki(gettext("You must specify a source to read from"));
167 include_once("lib/loadsave.php");
168 LoadFileOrDir($dbi, fix_magic_quotes_gpc($source));
172 include 'admin/removepage.php';
177 include "admin/lockpage.php";
178 include "lib/display.php";
182 $prefs = $user->getPreferences($GLOBALS);
183 if (!empty($edit_area_width))
184 $prefs['edit_area.width'] = $edit_area_width;
185 if (!empty($edit_area_height))
186 $prefs['edit_area.height'] = $edit_area_height;
187 $user->setPreferences($prefs);
189 PostponeErrorMessages(E_ALL & ~E_NOTICE);
191 include "lib/display.php";
197 include "lib/display.php";
201 echo QElement('p', sprintf("Bad action: '%s'", urlencode($action)));
210 // c-file-style: "ellemtel"