]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/main.php
Did find-grep to replace all occurances of FrontPage to HomePage.
[SourceForge/phpwiki.git] / lib / main.php
1 <?php
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";
7
8 if (ACCESS_LOG)
9 {
10    $LogEntry = new AccessLogEntry;
11
12    function _write_log () { $GLOBALS['LogEntry']->write(ACCESS_LOG); }
13    register_shutdown_function('_write_log');
14 }
15
16 if (USE_PATH_INFO && !isset($PATH_INFO)
17     && (!isset($REDIRECT_URL) || !preg_match(',/$,', $REDIRECT_URL)))
18 {
19    $LogEntry->status = 302;     // "302 Found"
20    header("Location: " . SERVER_URL . preg_replace('/(\?|$)/', '/\1', $REQUEST_URI, 1));
21    exit;
22 }
23
24 function DeducePagename () 
25 {
26    global $pagename, $PATH_INFO, $QUERY_STRING;
27    
28    if (isset($pagename))
29       return fix_magic_quotes_gpc($pagename);
30
31    if (USE_PATH_INFO && isset($PATH_INFO))
32    {
33       fix_magic_quotes_gpc($PATH_INFO);
34       if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $PATH_INFO, $m))
35          return $m[1];
36    }
37
38    if (isset($QUERY_STRING) && preg_match('/^[^&=]+$/', $QUERY_STRING))
39       return urldecode(fix_magic_quotes_gpc($QUERY_STRING));
40    
41    return gettext("HomePage");
42 }
43
44 $pagename = DeducePagename();
45
46 if (!empty($action))
47 {
48    $action = trim(fix_magic_quotes_gpc($action));
49 }
50 else if (isset($diff))
51 {
52    // Fix for compatibility with very old diff links in RecentChanges.
53    // (The [phpwiki:?diff=PageName] style links are fixed elsewhere.)
54    $action = 'diff';
55    $pagename = fix_magic_quotes_gpc($diff);
56    unset($diff);
57 }
58 else
59 {
60    $action = 'browse';
61 }
62
63 function IsSafeAction ($action)
64 {
65    if (! ZIPDUMP_AUTH and $action == 'zip')
66       return true;
67    return in_array ( $action, array('browse',
68                                     'info', 'diff', 'search',
69                                     'edit', 'save',
70                                     'login', 'logout',
71                                     'setprefs') );
72 }
73
74 function get_auth_mode ($action) 
75 {
76    switch ($action) {
77       case 'logout':
78          return  'LOGOUT';
79       case 'login':
80          return 'LOGIN';
81       default:
82          if (IsSafeAction($action))
83             return 'ANON_OK';
84          else
85             return 'REQUIRE_AUTH';
86    }
87 }
88
89    
90 $user = new WikiUser(get_auth_mode($action));
91 if ($user->is_authenticated())
92    $LogEntry->user = $user->id();
93
94
95
96 // All requests require the database
97 $dbi = OpenDataBase($WikiPageStore);
98
99 // if there is no HomePage, create a basic set of Wiki pages
100 if ( ! IsWikiPage($dbi, gettext("HomePage")) )
101 {
102    include_once("lib/loadsave.php");
103    SetupWiki($dbi);
104    ExitWiki();
105 }
106
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."));
112    
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);
117
118 switch ($action) {
119    case 'edit':
120       include "lib/editpage.php";
121       break;
122
123    case 'search':
124       if (isset($searchtype) && ($searchtype == 'full')) {
125          include "lib/fullsearch.php";
126       }
127       else {
128          include "lib/search.php";
129       }
130       break;
131       
132    case 'save':
133       include "lib/savepage.php";
134       break;
135    case 'info':
136       include "lib/pageinfo.php";
137       break;
138    case 'diff':
139       include "lib/diff.php";
140       break;
141       
142    case 'zip':
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";
148       break;
149
150    case 'upload':
151       include_once("lib/loadsave.php");
152       LoadPostFile($dbi, 'file');
153       break;
154    
155    case 'dumpserial':
156       if (empty($directory))
157          ExitWiki(gettext("You must specify a directory to dump to"));
158
159       include_once("lib/loadsave.php");
160       DumpToDir($dbi, fix_magic_quotes_gpc($directory));
161       break;
162
163    case 'loadfile':
164       if (empty($source))
165          ExitWiki(gettext("You must specify a source to read from"));
166
167       include_once("lib/loadsave.php");
168       LoadFileOrDir($dbi, fix_magic_quotes_gpc($source));
169       break;
170
171    case 'remove':
172       include 'admin/removepage.php';
173       break;
174     
175    case 'lock':
176    case 'unlock':
177       include "admin/lockpage.php";
178       include "lib/display.php";
179       break;
180
181    case 'setprefs':
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);
188
189       PostponeErrorMessages(E_ALL & ~E_NOTICE);
190
191       include "lib/display.php";
192       break;
193    
194    case 'browse':
195    case 'login':
196    case 'logout':
197       include "lib/display.php";
198       break;
199
200    default:
201       echo QElement('p', sprintf("Bad action: '%s'", urlencode($action)));
202       break;
203 }
204
205 ExitWiki();
206
207 // For emacs users
208 // Local Variables:
209 // mode: php
210 // c-file-style: "ellemtel"
211 // End:   
212 ?>