]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/main.php
If we're expecting PATH_INFO, and don't get it, redirect to REQUEST_URI
[SourceForge/phpwiki.git] / lib / main.php
1 <?php
2 rcs_id('$Id: main.php,v 1.4 2001-02-15 19:32:34 dairiki Exp $');
3 include "lib/config.php";
4 include "lib/stdlib.php";
5 include "lib/userauth.php";
6
7 if (USE_PATH_INFO && !isset($PATH_INFO))
8 {
9    header("Location: " . SERVER_URL . $REQUEST_URI);
10    exit;
11 }
12
13 function DeducePagename () 
14 {
15    global $pagename, $PATH_INFO;
16    
17    if (isset($pagename))
18       return fix_magic_quotes_gpc($pagename);
19
20    if (USE_PATH_INFO && isset($PATH_INFO))
21    {
22       fix_magic_quotes_gpc($PATH_INFO);
23       if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $PATH_INFO, $m))
24          return $m[1];
25    }
26
27    return gettext("FrontPage");
28 }
29
30 $pagename = DeducePagename();
31
32 if (!empty($action))
33 {
34    $action = trim(fix_magic_quotes_gpc($action));
35 }
36 else if (isset($diff))
37 {
38    // Fix for compatibility with very old diff links in RecentChanges.
39    // (The [phpwiki:?diff=PageName] style links are fixed elsewhere.)
40    $action = 'diff';
41    $pagename = fix_magic_quotes_gpc($diff);
42    unset($diff);
43 }
44 else
45 {
46    $action = 'browse';
47 }
48
49 function IsSafeAction ($action)
50 {
51    if (! ZIPDUMP_AUTH and $action == 'zip')
52       return true;
53    return in_array ( $action, array('browse',
54                                     'info', 'diff', 'search',
55                                     'edit', 'save',
56                                     'login', 'logout',
57                                     'setprefs') );
58 }
59
60 function get_auth_mode ($action) 
61 {
62    switch ($action) {
63       case 'logout':
64          return  'LOGOUT';
65       case 'login':
66          return 'LOGIN';
67       default:
68          if (IsSafeAction($action))
69             return 'ANON_OK';
70          else
71             return 'REQUIRE_AUTH';
72    }
73 }
74
75 $user = new WikiUser(get_auth_mode($action));
76
77 // All requests require the database
78 $dbi = OpenDataBase($WikiPageStore);
79
80 // if there is no FrontPage, create a basic set of Wiki pages
81 if ( ! IsWikiPage($dbi, gettext("FrontPage")) )
82 {
83    include_once("lib/loadsave.php");
84    SetupWiki($dbi);
85    ExitWiki();
86 }
87
88 // FIXME: I think this is redundant.
89 if (!IsSafeAction($action))
90    $user->must_be_admin($action);
91 if (isset($DisabledActions) && in_array($action, $DisabledActions))
92    ExitWiki(gettext("Action $action is disabled in this wiki."));
93    
94 // Enable the output of most of the warning messages.
95 // The warnings will screw up zip files and setpref though.
96 if ($action != 'zip' && $action != 'setprefs')
97    PostponeErrorMessages(E_NOTICE);
98
99 switch ($action) {
100    case 'edit':
101       include "lib/editpage.php";
102       break;
103
104    case 'search':
105       if (isset($searchtype) && ($searchtype == 'full')) {
106          include "lib/fullsearch.php";
107       }
108       else {
109          include "lib/search.php";
110       }
111       break;
112       
113    case 'save':
114       include "lib/savepage.php";
115       break;
116    case 'info':
117       include "lib/pageinfo.php";
118       break;
119    case 'diff':
120       include "lib/diff.php";
121       break;
122       
123    case 'zip':
124       include_once("lib/loadsave.php");
125       MakeWikiZip($dbi, isset($include) && $include == 'all');
126       // I don't think it hurts to add cruft at the end of the zip file.
127       echo "\n========================================================\n";
128       echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$RCS_IDS\n";
129       break;
130
131    case 'upload':
132       include_once("lib/loadsave.php");
133       LoadPostFile($dbi, 'file');
134       break;
135    
136    case 'dumpserial':
137       if (empty($directory))
138          ExitWiki(gettext("You must specify a directory to dump to"));
139
140       include_once("lib/loadsave.php");
141       DumpToDir($dbi, fix_magic_quotes_gpc($directory));
142       break;
143
144    case 'loadfile':
145       if (empty($source))
146          ExitWiki(gettext("You must specify a source to read from"));
147
148       include_once("lib/loadsave.php");
149       LoadFileOrDir($dbi, fix_magic_quotes_gpc($source));
150       break;
151
152    case 'remove':
153       include 'admin/removepage.php';
154       break;
155     
156    case 'lock':
157    case 'unlock':
158       include "admin/lockpage.php";
159       include "lib/display.php";
160       break;
161
162    case 'setprefs':
163       $prefs = $user->getPreferences($GLOBALS);
164       if (!empty($edit_area_width))
165          $prefs['edit_area.width'] = $edit_area_width;
166       if (!empty($edit_area_height))
167          $prefs['edit_area.height'] = $edit_area_height;
168       $user->setPreferences($prefs);
169
170       PostponeErrorMessages(E_ALL & ~E_NOTICE);
171
172       include "lib/display.php";
173       break;
174    
175    case 'browse':
176    case 'login':
177    case 'logout':
178       include "lib/display.php";
179       break;
180
181    default:
182       echo QElement('p', sprintf("Bad action: '%s'", urlencode($action)));
183       break;
184 }
185
186 ExitWiki();
187
188 // For emacs users
189 // Local Variables:
190 // mode: php
191 // c-file-style: "ellemtel"
192 // End:   
193 ?>