2 rcs_id('$Id: main.php,v 1.7 2001-02-17 21:52:08 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 . $REQUEST_URI . '/');
24 function DeducePagename ()
26 global $pagename, $PATH_INFO;
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 return gettext("FrontPage");
41 $pagename = DeducePagename();
45 $action = trim(fix_magic_quotes_gpc($action));
47 else if (isset($diff))
49 // Fix for compatibility with very old diff links in RecentChanges.
50 // (The [phpwiki:?diff=PageName] style links are fixed elsewhere.)
52 $pagename = fix_magic_quotes_gpc($diff);
60 function IsSafeAction ($action)
62 if (! ZIPDUMP_AUTH and $action == 'zip')
64 return in_array ( $action, array('browse',
65 'info', 'diff', 'search',
71 function get_auth_mode ($action)
79 if (IsSafeAction($action))
82 return 'REQUIRE_AUTH';
87 $user = new WikiUser(get_auth_mode($action));
88 if ($user->is_authenticated())
89 $LogEntry->user = $user->id;
93 // All requests require the database
94 $dbi = OpenDataBase($WikiPageStore);
96 // if there is no FrontPage, create a basic set of Wiki pages
97 if ( ! IsWikiPage($dbi, gettext("FrontPage")) )
99 include_once("lib/loadsave.php");
104 // FIXME: I think this is redundant.
105 if (!IsSafeAction($action))
106 $user->must_be_admin($action);
107 if (isset($DisabledActions) && in_array($action, $DisabledActions))
108 ExitWiki(gettext("Action $action is disabled in this wiki."));
110 // Enable the output of most of the warning messages.
111 // The warnings will screw up zip files and setpref though.
112 if ($action != 'zip' && $action != 'setprefs')
113 PostponeErrorMessages(E_NOTICE);
117 include "lib/editpage.php";
121 if (isset($searchtype) && ($searchtype == 'full')) {
122 include "lib/fullsearch.php";
125 include "lib/search.php";
130 include "lib/savepage.php";
133 include "lib/pageinfo.php";
136 include "lib/diff.php";
140 include_once("lib/loadsave.php");
141 MakeWikiZip($dbi, isset($include) && $include == 'all');
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$RCS_IDS\n";
148 include_once("lib/loadsave.php");
149 LoadPostFile($dbi, 'file');
153 if (empty($directory))
154 ExitWiki(gettext("You must specify a directory to dump to"));
156 include_once("lib/loadsave.php");
157 DumpToDir($dbi, fix_magic_quotes_gpc($directory));
162 ExitWiki(gettext("You must specify a source to read from"));
164 include_once("lib/loadsave.php");
165 LoadFileOrDir($dbi, fix_magic_quotes_gpc($source));
169 include 'admin/removepage.php';
174 include "admin/lockpage.php";
175 include "lib/display.php";
179 $prefs = $user->getPreferences($GLOBALS);
180 if (!empty($edit_area_width))
181 $prefs['edit_area.width'] = $edit_area_width;
182 if (!empty($edit_area_height))
183 $prefs['edit_area.height'] = $edit_area_height;
184 $user->setPreferences($prefs);
186 PostponeErrorMessages(E_ALL & ~E_NOTICE);
188 include "lib/display.php";
194 include "lib/display.php";
198 echo QElement('p', sprintf("Bad action: '%s'", urlencode($action)));
207 // c-file-style: "ellemtel"