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