]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/main.php
log
[SourceForge/phpwiki.git] / lib / main.php
1 <?php
2 rcs_id('$Id: main.php,v 1.2 2001-02-13 05:54:38 dairiki Exp $');
3 include "lib/config.php";
4 include "lib/stdlib.php";
5 include "lib/userauth.php";
6
7
8 function DeducePagename () 
9 {
10    global $pagename, $PATH_INFO;
11    
12    if (isset($pagename))
13       return fix_magic_quotes_gpc($pagename);
14
15    if (USE_PATH_INFO)
16       if (ereg('^' . PATH_INFO_PREFIX . '(.*)$', $PATH_INFO, $m))
17          return $m[1];
18
19    return gettext("FrontPage");
20 }
21
22 $pagename = DeducePagename();
23
24 if (!empty($action))
25 {
26    $action = trim(fix_magic_quotes_gpc($action));
27 }
28 else if (isset($diff))
29 {
30    // Fix for compatibility with very old diff links in RecentChanges.
31    // (The [phpwiki:?diff=PageName] style links are fixed elsewhere.)
32    $action = 'diff';
33    $pagename = fix_magic_quotes_gpc($diff);
34    unset($diff);
35 }
36 else
37 {
38    $action = 'browse';
39 }
40
41
42 function IsSafeAction ($action)
43 {
44    if (! ZIPDUMP_AUTH and $action == 'zip')
45       return true;
46    return in_array ( $action, array('browse',
47                                     'info', 'diff', 'search',
48                                     'edit', 'save',
49                                     'login', 'logout',
50                                     'setprefs') );
51 }
52
53 function get_auth_mode ($action) 
54 {
55    switch ($action) {
56       case 'logout':
57          return  'LOGOUT';
58       case 'login':
59          return 'LOGIN';
60       default:
61          if (IsSafeAction($action))
62             return 'ANON_OK';
63          else
64             return 'REQUIRE_AUTH';
65    }
66 }
67
68 $user = new WikiUser(get_auth_mode($action));
69
70 // All requests require the database
71 $dbi = OpenDataBase($WikiPageStore);
72
73 // if there is no FrontPage, create a basic set of Wiki pages
74 if ( ! IsWikiPage($dbi, gettext("FrontPage")) )
75 {
76    include_once("lib/loadsave.php");
77    SetupWiki($dbi);
78    ExitWiki();
79 }
80
81 // FIXME: I think this is redundant.
82 if (!IsSafeAction($action))
83    $user->must_be_admin($action);
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 ?>