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