]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/main.php
remove debugging prints
[SourceForge/phpwiki.git] / lib / main.php
1 <?php //-*-php-*-
2 rcs_id('$Id: main.php,v 1.183 2004-10-14 19:23:58 rurban Exp $');
3
4 define ('USE_PREFS_IN_PAGE', true);
5
6 //include "lib/config.php";
7 require_once(dirname(__FILE__)."/stdlib.php");
8 require_once('lib/Request.php');
9 require_once('lib/WikiDB.php');
10 if (ENABLE_USER_NEW)
11     require_once("lib/WikiUserNew.php");
12 else
13     require_once("lib/WikiUser.php");
14 require_once("lib/WikiGroup.php");
15 require_once("lib/PagePerm.php");
16
17 class WikiRequest extends Request {
18     // var $_dbi;
19
20     function WikiRequest () {
21         $this->_dbi = WikiDB::open($GLOBALS['DBParams']);
22         //if ((DEBUG & _DEBUG_TRACE) or (time() % 50 == 0))
23         //    $this->_dbi->_backend->optimize();
24         if (in_array('File', $this->_dbi->getAuthParam('USER_AUTH_ORDER'))) {
25             // force our local copy, until the pear version is fixed.
26             include_once(dirname(__FILE__)."/pear/File_Passwd.php");
27         }
28         if (USE_DB_SESSION) {
29             include_once('lib/DbSession.php');
30             $dbi =& $this->_dbi;
31             $this->_dbsession = & new DbSession($dbi, $dbi->getParam('prefix') . $dbi->getParam('db_session_table'));
32         }
33 // Fixme: Does pear reset the error mask to 1? We have to find the culprit
34 //$x = error_reporting();
35 $this->version = phpwiki_version();
36         $this->Request();
37
38         // Normalize args...
39         $this->setArg('pagename', $this->_deducePagename());
40         $this->setArg('action', $this->_deduceAction());
41
42         // Restore auth state. This doesn't check for proper authorization!
43         if (ENABLE_USER_NEW) {
44             $userid = $this->_deduceUsername(); 
45             if (isset($this->_user) and 
46                 !empty($this->_user->_authhow) and 
47                 $this->_user->_authhow == 'session')
48             {
49                 // users might switch in a session between the two objects.
50                 // restore old auth level here or in updateAuthAndPrefs?
51                 //$user = $this->getSessionVar('wiki_user');
52                 // revive db handle, because these don't survive sessions
53                 if (isset($this->_user) and 
54                      ( ! isa($this->_user, WikiUserClassname())
55                        or (strtolower(get_class($this->_user)) == '_passuser')))
56                 {
57                     $this->_user = WikiUser($userid, $this->_user->_prefs);
58                 }
59                 // revive other db handle
60                 if (isset($this->_user->_prefs->_method) and 
61                          ($this->_user->_prefs->_method == 'SQL' or 
62                          $this->_user->_prefs->_method == 'ADODB'))
63                     $this->_user->_HomePagehandle = $this->getPage($userid);
64                 // need to update the lockfile filehandle
65                 if (  isa($this->_user,'_FilePassUser') and 
66                       $this->_user->_file->lockfile and 
67                       !$this->_user->_file->fplock  )
68                 {
69                     //$level = $this->_user->_level;
70                     $this->_user = UpgradeUser($this->_user, 
71                                                new _FilePassUser($userid, $this->_user->_prefs, $this->_user->_file->filename));
72                     //$this->_user->_level = $level;
73                 }
74                 $this->_prefs = & $this->_user->_prefs;
75             } else {
76                 $user = WikiUser($userid);
77                 $this->_user = & $user;
78                 $this->_prefs = & $this->_user->_prefs;
79             }
80         } else {
81             $this->_user = new WikiUser($this, $this->_deduceUsername());
82             $this->_prefs = $this->_user->getPreferences();
83         }
84     }
85
86     function initializeLang () {
87         $user_lang = $this->getPref('lang');
88         $_lang = @$this->_prefs->_prefs['lang'];
89         //check changed LANG and THEME inside a session. 
90         // (e.g. by using another baseurl)
91         if (isset($this->_user->_authhow) and 
92             $this->_user->_authhow == 'session' and 
93             !isset($_lang->lang) and 
94             $user_lang != $GLOBALS['LANG'])
95         {
96             $user_lang = $GLOBALS['LANG'];
97         }
98         if (isset($user_lang)) {
99             //trigger_error("DEBUG: initializeLang() ". $user_lang ." calling update_locale()...");
100             update_locale($user_lang);
101             FindLocalizedButtonFile(".",'missing_ok','reinit');
102         }
103     }
104
105     function initializeTheme () {
106         global $WikiTheme;
107
108         // Load theme
109         $user_theme = $this->getPref('theme');
110         $_theme = @$this->_prefs->_prefs['theme'];
111         //check changed LANG and THEME inside a session. 
112         // (e.g. by using another baseurl)
113         if (isset($this->_user->_authhow) and 
114             $this->_user->_authhow == 'session' and 
115             !isset($_theme->theme) and
116             defined('THEME') and 
117             $user_theme != THEME)
118         {
119             include_once("themes/" . THEME . "/themeinfo.php");
120         }
121         if (empty($WikiTheme) and isset($user_theme)) {
122             if (strcspn($user_theme,"./\x00]") != strlen($user_theme)) {
123                 trigger_error(sprintf("invalid theme '%s': Invalid characters detected", $user_theme),
124                               E_USER_WARNING);
125                 $user_theme = "default";
126             }
127             include_once("themes/$user_theme/themeinfo.php");
128         }
129         if (empty($WikiTheme) and defined('THEME'))
130             include_once("themes/" . THEME . "/themeinfo.php");
131         if (empty($WikiTheme))
132             include_once("themes/default/themeinfo.php");
133         assert(!empty($WikiTheme));
134     }
135
136     // This really maybe should be part of the constructor, but since it
137     // may involve HTML/template output, the global $request really needs
138     // to be initialized before we do this stuff.
139     function updateAuthAndPrefs () {
140
141         if (isset($this->_user) and (!isa($this->_user,WikiUserClassname()))) {
142             $this->_user = false;       
143         }
144         // Handle authentication request, if any.
145         if ($auth_args = $this->getArg('auth')) {
146             $this->setArg('auth', false);
147             $this->_handleAuthRequest($auth_args); // possible NORETURN
148         }
149         elseif ( ! $this->_user or 
150                  (isa($this->_user,WikiUserClassname()) and ! $this->_user->isSignedIn())) {
151             // If not auth request, try to sign in as saved user.
152             if (($saved_user = $this->getPref('userid')) != false) {
153                 $this->_signIn($saved_user);
154             }
155         }
156
157         // Save preferences in session and cookie
158         if (isset($this->_user) and 
159             (!isset($this->_user->_authhow) or $this->_user->_authhow != 'session')) {
160             $id_only = true; 
161             $this->_user->setPreferences($this->_prefs, $id_only);
162         } else {
163             $this->setSessionVar('wiki_user', $this->_user);
164             //$this->setSessionVar('wiki_prefs', $this->_prefs);
165         }
166
167         // Ensure user has permissions for action
168         // HACK ALERT: We may not set the request arg to create, 
169         // since the pageeditor has an ugly logic for action == create.
170         $action = $this->getArg('action');
171         if ($action == 'edit' or $action == 'create') {
172             $page = $this->getPage();
173             if (! $page->exists() )
174                 $action = 'create';
175             else
176                 $action = 'edit';
177         }
178         $require_level = $this->requiredAuthority($action);
179         if (! $this->_user->hasAuthority($require_level))
180             $this->_notAuthorized($require_level); // NORETURN
181     }
182
183     function getUser () {
184         if (isset($this->_user))
185             return $this->_user;
186         else
187             return $GLOBALS['ForbiddenUser'];
188     }
189     
190     function & getGroup () {
191         if (isset($this->_user) and isset($this->_user->_group))
192             return $this->_user->_group;
193         else
194             return WikiGroup::getGroup();
195     }
196
197     function getPrefs () {
198         return $this->_prefs;
199     }
200
201     // Convenience function:
202     function getPref ($key) {
203         if (isset($this->_prefs)) {
204             return $this->_prefs->get($key);
205         }
206     }
207     function getDbh () {
208         return $this->_dbi;
209     }
210
211     /**
212      * Get requested page from the page database.
213      * By default it will grab the page requested via the URL
214      *
215      * This is a convenience function.
216      * @param string $pagename Name of page to get.
217      * @return WikiDB_Page Object with methods to pull data from
218      * database for the page requested.
219      */
220     function getPage ($pagename = false) {
221         if (!isset($this->_dbi))
222             $this->getDbh();
223         if (!$pagename) 
224             $pagename = $this->getArg('pagename');
225         return $this->_dbi->getPage($pagename);
226     }
227
228     /** Get URL for POST actions.
229      *
230      * Officially, we should just use SCRIPT_NAME (or some such),
231      * but that causes problems when we try to issue a redirect, e.g.
232      * after saving a page.
233      *
234      * Some browsers (at least NS4 and Mozilla 0.97 won't accept
235      * a redirect from a page to itself.)
236      *
237      * So, as a HACK, we include pagename and action as query args in
238      * the URL.  (These should be ignored when we receive the POST
239      * request.)
240      */
241     function getPostURL ($pagename=false) {
242         global $HTTP_GET_VARS;
243
244         if ($pagename === false)
245             $pagename = $this->getArg('pagename');
246         $action = $this->getArg('action');
247         if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
248             return WikiURL($pagename, array('action' => $action, 'start_debug' => 1));
249         else
250             return WikiURL($pagename, array('action' => $action));
251     }
252     
253     function _handleAuthRequest ($auth_args) {
254         if (!is_array($auth_args))
255             return;
256
257         // Ignore password unless POST'ed.
258         if (!$this->isPost())
259             unset($auth_args['passwd']);
260
261         $olduser = $this->_user;
262         $user = $this->_user->AuthCheck($auth_args);
263         if (isa($user, WikiUserClassname())) {
264             // Successful login (or logout.)
265             $this->_setUser($user);
266         }
267         elseif (is_string($user)) {
268             // Login attempt failed.
269             $fail_message = $user;
270             $auth_args['pass_required'] = true;
271             // If no password was submitted, it's not really
272             // a failure --- just need to prompt for password...
273             if (!ALLOW_USER_PASSWORDS 
274                 and ALLOW_BOGO_LOGIN 
275                 and !isset($auth_args['passwd'])) 
276             {
277                 $fail_message = false;
278             }
279             $olduser->PrintLoginForm($this, $auth_args, $fail_message, 'newpage');
280             $this->finish();    //NORETURN
281         }
282         else {
283             // Login request cancelled.
284         }
285     }
286
287     /**
288      * Attempt to sign in (bogo-login).
289      *
290      * Fails silently.
291      *
292      * @param $userid string Userid to attempt to sign in as.
293      * @access private
294      */
295     function _signIn ($userid) {
296         if (ENABLE_USER_NEW) {
297             if (! $this->_user )
298                 $this->_user = new _BogoUser($userid);
299             // FIXME: is this always false? shouldn't we try passuser first?
300             if (! $this->_user ) 
301                 $this->_user = new _PassUser($userid);
302         }
303         $user = $this->_user->AuthCheck(array('userid' => $userid));
304         if (isa($user,WikiUserClassname())) {
305             $this->_setUser($user); // success!
306         }
307     }
308
309     // login or logout or restore state
310     function _setUser ($user) {
311         $this->_user = $user;
312         if (defined('MAIN_setUser')) return;
313         define('MAIN_setUser',true);
314         $this->setCookieVar('WIKI_ID', $user->getAuthenticatedId(),
315                             COOKIE_EXPIRATION_DAYS, COOKIE_DOMAIN);
316         if ($user->isSignedIn())
317             $user->_authhow = 'signin';
318
319         // Save userid to prefs..
320         if ( empty($this->_user->_prefs)) {
321             $this->_user->_prefs = $this->_user->getPreferences();
322             $this->_prefs =& $this->_user->_prefs;
323         }
324         $this->_user->_group = $this->getGroup();
325         // avoid recursive objects and session resource handles
326         if (isset($user->_group)) {
327             unset($user->_group->_request);
328             unset($user->_group->_user);
329         }
330         unset($user->_HomePagehandle);
331         unset($user->_auth_dbi);
332         $this->setSessionVar('wiki_user', $user);
333         $this->_prefs->set('userid',
334                            $user->isSignedIn() ? $user->getId() : '');
335         $this->initializeTheme();
336     }
337
338     /* Permission system */
339     function getLevelDescription($level) {
340         static $levels = false;
341         if (!$levels) 
342             $levels = array('x-1' => _("FORBIDDEN"),
343                             'x0'  => _("ANON"),
344                             'x1'  => _("BOGO"),
345                             'x2'  => _("USER"),
346                             'x10' => _("ADMIN"),
347                             'x100'=> _("UNOBTAINABLE"));
348         return $levels["x".$level];
349     }
350     
351     function _notAuthorized ($require_level) {
352         // Display the authority message in the Wiki's default
353         // language, in case it is not english.
354         //
355         // Note that normally a user will not see such an error once
356         // logged in, unless the admin has altered the default
357         // disallowed wikiactions. In that case we should probably
358         // check the user's language prefs too at this point; this
359         // would be a situation which is not really handled with the
360         // current code.
361         if (empty($GLOBALS['LANG']))
362             update_locale(DEFAULT_LANGUAGE);
363
364         // User does not have required authority.  Prompt for login.
365         $what = $this->getActionDescription($this->getArg('action'));
366         $pass_required = ($require_level >= WIKIAUTH_USER);
367         if ($require_level == WIKIAUTH_UNOBTAINABLE) {
368             global $DisabledActions;
369             if ($DisabledActions and in_array($action, $DisabledActions)) {
370                 $msg = fmt("%s is disallowed on this wiki.",
371                            $this->getDisallowedActionDescription($this->getArg('action')));
372                 $this->finish();
373                 return;
374             }
375             if (class_exists('PagePermission')) {
376                 $user =& $this->_user;
377                 $status = $user->isAuthenticated() ? _("authenticated") : _("not authenticated");
378                 $msg = fmt("%s %s %s is disallowed on this wiki for %s user '%s' (level: %s).",
379                            _("Missing PagePermission:"),
380                            action2access($this->getArg('action')),
381                            $this->getArg('pagename'),
382                            $status, $user->getId(), $this->getLevelDescription($user->_level));
383                 // TODO: add link to action=setacl
384                 $user->PrintLoginForm($this, compact('pass_required'), $msg);
385                 $this->finish();
386                 return;
387             } else {
388                 $msg = fmt("%s is disallowed on this wiki.",
389                            $this->getDisallowedActionDescription($this->getArg('action')));
390                 $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
391                 $this->finish();
392                 return;
393             }
394         }
395         elseif ($require_level == WIKIAUTH_BOGO)
396             $msg = fmt("You must sign in to %s.", $what);
397         elseif ($require_level == WIKIAUTH_USER)
398             $msg = fmt("You must log in to %s.", $what);
399         elseif ($require_level == WIKIAUTH_ANON)
400             $msg = fmt("Access for you is forbidden to %s.", $what);
401         else
402             $msg = fmt("You must be an administrator to %s.", $what);
403
404         $this->_user->PrintLoginForm($this, compact('require_level','pass_required'), $msg);
405         $this->finish();    // NORETURN
406     }
407
408     // Fixme: for PagePermissions we'll need other strings, 
409     // relevant to the requested page, not just for the action on the whole wiki.
410     function getActionDescription($action) {
411         static $actionDescriptions;
412         if (! $actionDescriptions) {
413             $actionDescriptions
414             = array('browse'     => _("view this page"),
415                     'diff'       => _("diff this page"),
416                     'dumphtml'   => _("dump html pages"),
417                     'dumpserial' => _("dump serial pages"),
418                     'edit'       => _("edit this page"),
419                     'revert'     => _("revert to a previous version of this page"),
420                     'create'     => _("create this page"),
421                     'loadfile'   => _("load files into this wiki"),
422                     'lock'       => _("lock this page"),
423                     'remove'     => _("remove this page"),
424                     'unlock'     => _("unlock this page"),
425                     'upload'     => _("upload a zip dump"),
426                     'verify'     => _("verify the current action"),
427                     'viewsource' => _("view the source of this page"),
428                     'xmlrpc'     => _("access this wiki via XML-RPC"),
429                     'soap'       => _("access this wiki via SOAP"),
430                     'zip'        => _("download a zip dump from this wiki"),
431                     'ziphtml'    => _("download an html zip dump from this wiki")
432                     );
433         }
434         if (in_array($action, array_keys($actionDescriptions)))
435             return $actionDescriptions[$action];
436         else
437             return $action;
438     }
439     
440     /**
441 TODO: check against these cases:
442         if ($DisabledActions and in_array($action, $DisabledActions))
443             return WIKIAUTH_UNOBTAINABLE;
444
445         if (ENABLE_PAGEPERM and class_exists("PagePermission")) {
446            return requiredAuthorityForPage($action);
447            
448 => Browsing pages is disallowed on this wiki for authenticated user 'rurban' (level: BOGO).
449     */
450     function getDisallowedActionDescription($action) {
451         static $disallowedActionDescriptions;
452         
453         if (! $disallowedActionDescriptions) {
454             $disallowedActionDescriptions
455             = array('browse'     => _("Browsing pages"),
456                     'diff'       => _("Diffing pages"),
457                     'dumphtml'   => _("Dumping html pages"),
458                     'dumpserial' => _("Dumping serial pages"),
459                     'edit'       => _("Editing pages"),
460                     'revert'     => _("Reverting to a previous version of pages"),
461                     'create'     => _("Creating pages"),
462                     'loadfile'   => _("Loading files"),
463                     'lock'       => _("Locking pages"),
464                     'remove'     => _("Removing pages"),
465                     'unlock'     => _("Unlocking pages"),
466                     'upload'     => _("Uploading zip dumps"),
467                     'verify'     => _("Verify the current action"),
468                     'viewsource' => _("Viewing the source of pages"),
469                     'xmlrpc'     => _("XML-RPC access"),
470                     'soap'       => _("SOAP access"),
471                     'zip'        => _("Downloading zip dumps"),
472                     'ziphtml'    => _("Downloading html zip dumps")
473                     );
474         }
475         if (in_array($action, array_keys($disallowedActionDescriptions)))
476             return $disallowedActionDescriptions[$action];
477         else
478             return $action;
479     }
480
481     function requiredAuthority ($action) {
482         $auth = $this->requiredAuthorityForAction($action);
483         if (!ALLOW_ANON_USER) return WIKIAUTH_USER;
484         
485         /*
486          * This is a hook for plugins to require authority
487          * for posting to them.
488          *
489          * IMPORTANT: this is not a secure check, so the plugin
490          * may not assume that any POSTs to it are authorized.
491          * All this does is cause PhpWiki to prompt for login
492          * if the user doesn't have the required authority.
493          */
494         if ($this->isPost()) {
495             $post_auth = $this->getArg('require_authority_for_post');
496             if ($post_auth !== false)
497                 $auth = max($auth, $post_auth);
498         }
499         return $auth;
500     }
501         
502     function requiredAuthorityForAction ($action) {
503         global $DisabledActions;
504         
505         if ($DisabledActions and in_array($action, $DisabledActions))
506             return WIKIAUTH_UNOBTAINABLE;
507             
508         if (ENABLE_PAGEPERM and class_exists("PagePermission")) {
509            return requiredAuthorityForPage($action);
510         } else {
511           // FIXME: clean up. 
512           switch ($action) {
513             case 'browse':
514             case 'viewsource':
515             case 'diff':
516             case 'select':
517             case 'xmlrpc':
518             case 'search':
519             case 'pdf':
520                 return WIKIAUTH_ANON;
521
522             case 'zip':
523             case 'ziphtml':
524                 if (defined('ZIPDUMP_AUTH') && ZIPDUMP_AUTH)
525                     return WIKIAUTH_ADMIN;
526                 return WIKIAUTH_ANON;
527
528             case 'edit':
529             case 'revert':
530             case 'soap':
531                 if (defined('REQUIRE_SIGNIN_BEFORE_EDIT') && REQUIRE_SIGNIN_BEFORE_EDIT)
532                     return WIKIAUTH_BOGO;
533                 return WIKIAUTH_ANON;
534                 // return WIKIAUTH_BOGO;
535
536             case 'create':
537                 $page = $this->getPage();
538                 $current = $page->getCurrentRevision();
539                 if ($current->hasDefaultContents())
540                     return $this->requiredAuthorityForAction('edit');
541                 return $this->requiredAuthorityForAction('browse');
542
543             case 'upload':
544             case 'dumpserial':
545             case 'dumphtml':
546             case 'loadfile':
547             case 'remove':
548             case 'lock':
549             case 'unlock':
550             case 'upgrade':
551             case 'chown':
552             case 'setacl':
553             case 'rename':
554                 return WIKIAUTH_ADMIN;
555
556             /* authcheck occurs only in the plugin.
557                required actionpage RateIt */
558             /*
559             case 'rate':
560             case 'delete_rating':
561                 // Perhaps this should be WIKIAUTH_USER
562                 return WIKIAUTH_BOGO;
563             */
564
565             default:
566                 global $WikiNameRegexp;
567                 if (preg_match("/$WikiNameRegexp\Z/A", $action))
568                     return WIKIAUTH_ANON; // ActionPage.
569                 else
570                     return WIKIAUTH_ADMIN;
571           }
572         }
573     }
574     /* End of Permission system */
575
576     function possiblyDeflowerVirginWiki () {
577         if ($this->getArg('action') != 'browse')
578             return;
579         if ($this->getArg('pagename') != HOME_PAGE)
580             return;
581
582         $page = $this->getPage();
583         $current = $page->getCurrentRevision();
584         if ($current->getVersion() > 0)
585             return;             // Homepage exists.
586
587         include('lib/loadsave.php');
588         SetupWiki($this);
589         $this->finish();        // NORETURN
590     }
591
592     function handleAction () {
593         $action = $this->getArg('action');
594         $method = "action_$action";
595         if (method_exists($this, $method)) {
596             $this->{$method}();
597         }
598         elseif ($page = $this->findActionPage($action)) {
599             $this->actionpage($page);
600         }
601         else {
602             $this->finish(fmt("%s: Bad action", $action));
603         }
604     }
605     
606     function finish ($errormsg = false) {
607         static $in_exit = 0;
608
609         if ($in_exit)
610             exit();        // just in case CloseDataBase calls us
611         $in_exit = true;
612
613         global $ErrorManager;
614         $ErrorManager->flushPostponedErrors();
615
616         if (!empty($errormsg)) {
617             PrintXML(HTML::br(),
618                      HTML::hr(),
619                      HTML::h2(_("Fatal PhpWiki Error")),
620                      $errormsg);
621             // HACK:
622             echo "\n</body></html>";
623         }
624         if (is_object($this->_user)) {
625             $this->_user->page   = $this->getArg('pagename');
626             $this->_user->action = $this->getArg('action');
627             unset($this->_user->_HomePagehandle);
628             unset($this->_user->_auth_dbi);
629         }
630         if (!empty($this->_dbi)) {
631             session_write_close();
632             $this->_dbi->close();
633             unset($this->_dbi);
634         }
635         Request::finish();
636         exit;
637     }
638
639     /**
640      * Generally pagename is rawurlencoded for older browsers or mozilla.
641      * Typing a pagename into the IE bar will utf-8 encode it, so we have to 
642      * fix that with fixTitleEncoding().
643      * If USE_PATH_INFO = true, the pagename is stripped from the "/DATA_PATH/PageName&arg=value" line.
644      * If false, we support either "/index.php?pagename=PageName&arg=value",
645      * or the first arg (1.2.x style): "/index.php?PageName&arg=value"
646      */
647     function _deducePagename () {
648         if (trim(rawurldecode($this->getArg('pagename'))))
649             return fixTitleEncoding(rawurldecode($this->getArg('pagename')));
650
651         if (USE_PATH_INFO) {
652             $pathinfo = $this->get('PATH_INFO');
653             if (empty($pathinfo)) { // fix for CGI
654                 $path = $this->get('REQUEST_URI');
655                 $script = $this->get('SCRIPT_NAME');
656                 $pathinfo = substr($path,strlen($script));
657                 $pathinfo = preg_replace('/\?.+$/','',$pathinfo);
658             }
659             $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
660
661             if (trim($tail) != '' and $pathinfo == PATH_INFO_PREFIX . $tail) {
662                 return fixTitleEncoding($tail);
663             }
664         }
665         elseif ($this->isPost()) {
666             /*
667              * In general, for security reasons, HTTP_GET_VARS should be ignored
668              * on POST requests, but we make an exception here (only for pagename).
669              *
670              * The justification for this hack is the following
671              * asymmetry: When POSTing with USE_PATH_INFO set, the
672              * pagename can (and should) be communicated through the
673              * request URL via PATH_INFO.  When POSTing with
674              * USE_PATH_INFO off, this cannot be done --- the only way
675              * to communicate the pagename through the URL is via
676              * QUERY_ARGS (HTTP_GET_VARS).
677              */
678             global $HTTP_GET_VARS;
679             if (isset($HTTP_GET_VARS['pagename']) and trim($HTTP_GET_VARS['pagename'])) { 
680                 return fixTitleEncoding(rawurldecode($HTTP_GET_VARS['pagename']));
681             }
682         }
683
684         /*
685          * Support for PhpWiki 1.2 style requests.
686          * Strip off "&" args (?PageName&action=...&start_debug,...)
687          */
688         $query_string = $this->get('QUERY_STRING');
689         if (trim(rawurldecode($query_string)) and preg_match('/^([^&=]+)(&.+)?$/', $query_string, $m)) {
690             return fixTitleEncoding(rawurldecode($m[1]));
691         }
692
693         return fixTitleEncoding(HOME_PAGE);
694     }
695
696     function _deduceAction () {
697         if (!($action = $this->getArg('action'))) {
698             // Detect XML-RPC requests
699             if ($this->isPost()
700                 && $this->get('CONTENT_TYPE') == 'text/xml') {
701                 global $HTTP_RAW_POST_DATA;
702                 if (strstr($HTTP_RAW_POST_DATA, '<methodCall>')) {
703                     return 'xmlrpc';
704                 }
705             }
706             return 'browse';    // Default if no action specified.
707         }
708
709         if (method_exists($this, "action_$action"))
710             return $action;
711
712         // Allow for, e.g. action=LikePages
713         if ($this->isActionPage($action))
714             return $action;
715
716         // Handle untranslated actionpages in non-english
717         // (people playing with switching languages)
718         if (0 and $GLOBALS['LANG'] != 'en') {
719             require_once("lib/plugin/_WikiTranslation.php");
720             $trans = new WikiPlugin__WikiTranslation();
721             $en_action = $trans->translate($action,'en',$GLOBALS['LANG']);
722             if ($this->isActionPage($en_action))
723                 return $en_action;
724         }
725
726         trigger_error("$action: Unknown action", E_USER_NOTICE);
727         return 'browse';
728     }
729
730     function _deduceUsername() {
731         global $HTTP_SERVER_VARS, $HTTP_ENV_VARS;
732
733         if (!empty($this->args['auth']) and !empty($this->args['auth']['userid']))
734             return $this->args['auth']['userid'];
735
736         if (!empty($HTTP_SERVER_VARS['PHP_AUTH_USER']))
737             return $HTTP_SERVER_VARS['PHP_AUTH_USER'];
738         if (!empty($HTTP_ENV_VARS['REMOTE_USER']))
739             return $HTTP_ENV_VARS['REMOTE_USER'];
740             
741         if ($user = $this->getSessionVar('wiki_user')) {
742             $this->_user = $user;
743             $this->_user->_authhow = 'session';
744             return ENABLE_USER_NEW ? $user->UserName() : $this->_user;
745         }
746         if ($userid = $this->getCookieVar('WIKI_ID')) {
747             if (!empty($userid) and substr($userid,0,2) != 's:') {
748                 $this->_user->authhow = 'cookie';
749                 return $userid;
750             }
751         }
752         return false;
753     }
754     
755     function _isActionPage ($pagename) {
756         $dbi = $this->getDbh();
757         $page = $dbi->getPage($pagename);
758         if (!$page) return false;
759         $rev = $page->getCurrentRevision();
760         // FIXME: more restrictive check for sane plugin?
761         if (strstr($rev->getPackedContent(), '<?plugin'))
762             return true;
763         if (!$rev->hasDefaultContents())
764             trigger_error("$pagename: Does not appear to be an 'action page'", E_USER_NOTICE);
765         return false;
766     }
767
768     function findActionPage ($action) {
769         static $cache;
770
771         // check for translated version, as per users preferred language
772         // (or system default in case it is not en)
773         $translation = gettext($action);
774
775         if (isset($cache) and isset($cache[$translation]))
776             return $cache[$translation];
777
778         // check for cached translated version
779         if ($this->_isActionPage($translation))
780             return $cache[$action] = $translation;
781
782         // Allow for, e.g. action=LikePages
783         if (!isWikiWord($action))
784             return $cache[$action] = false;
785
786         // check for translated version (default language)
787         global $LANG;
788         if ($LANG != "en") {
789             require_once("lib/WikiPlugin.php");
790             require_once("lib/plugin/_WikiTranslation.php");
791             $trans = new WikiPlugin__WikiTranslation();
792             $trans->lang = $LANG;
793             $default = $trans->translate_to_en($action, $LANG);
794             if ($this->_isActionPage($default))
795                 return $cache[$action] = $default;
796         } else {
797             $default = $translation;
798         }
799         
800         // check for english version
801         if ($action != $translation and $action != $default) {
802             if ($this->_isActionPage($action))
803                 return $cache[$action] = $action;
804         }
805
806         trigger_error("$action: Cannot find action page", E_USER_NOTICE);
807         return $cache[$action] = false;
808     }
809     
810     function isActionPage ($pagename) {
811         return $this->findActionPage($pagename);
812     }
813
814     function action_browse () {
815         $this->buffer_output();
816         include_once("lib/display.php");
817         displayPage($this);
818     }
819
820     function action_verify () {
821         $this->action_browse();
822     }
823
824     function actionpage ($action) {
825         $this->buffer_output();
826         include_once("lib/display.php");
827         actionPage($this, $action);
828     }
829
830     function adminActionSubpage ($subpage) {
831         $page = _("PhpWikiAdministration")."/".$subpage;
832         $action = $this->findActionPage($page);
833         if ($action) {
834             $this->setArg('s',$this->getArg('pagename'));
835             $this->setArg('verify',1);
836             $this->setArg('action',$action);
837             $this->actionpage($action);
838         } else {
839             trigger_error($page.": Cannot find action page", E_USER_WARNING);
840         }
841     }
842
843     function action_chown () {
844         $this->adminActionSubpage(_("Chown"));
845     }
846
847     function action_setacl () {
848         $this->adminActionSubpage(_("SetAcl"));
849     }
850
851     function action_rename () {
852         $this->adminActionSubpage(_("Rename"));
853     }
854
855     function action_dump () {
856         $action = $this->findActionPage(_("PageDump"));
857         if ($action) {
858             $this->actionpage($action);
859         } else {
860             // redirect to action=upgrade if admin?
861             trigger_error(_("PageDump").": Cannot find action page", E_USER_WARNING);
862         }
863     }
864
865     function action_diff () {
866         $this->buffer_output();
867         include_once "lib/diff.php";
868         showDiff($this);
869     }
870
871     function action_search () {
872         // This is obsolete: reformulate URL and redirect.
873         // FIXME: this whole section should probably be deleted.
874         if ($this->getArg('searchtype') == 'full') {
875             $search_page = _("FullTextSearch");
876         }
877         else {
878             $search_page = _("TitleSearch");
879         }
880         $this->redirect(WikiURL($search_page,
881                                 array('s' => $this->getArg('searchterm')),
882                                 'absolute_url'));
883     }
884
885     function action_edit () {
886         $this->buffer_output();
887         include "lib/editpage.php";
888         $e = new PageEditor ($this);
889         $e->editPage();
890     }
891
892     function action_create () {
893         $this->action_edit();
894     }
895     
896     function action_viewsource () {
897         $this->buffer_output();
898         include "lib/editpage.php";
899         $e = new PageEditor ($this);
900         $e->viewSource();
901     }
902
903     function action_lock () {
904         $page = $this->getPage();
905         $page->set('locked', true);
906         $this->_dbi->touch();
907         $this->action_browse();
908     }
909
910     function action_unlock () {
911         // FIXME: This check is redundant.
912         //$user->requireAuth(WIKIAUTH_ADMIN);
913         $page = $this->getPage();
914         $page->set('locked', false);
915         $this->_dbi->touch();
916         $this->action_browse();
917     }
918
919     function action_remove () {
920         // FIXME: This check is redundant.
921         //$user->requireAuth(WIKIAUTH_ADMIN);
922         $pagename = $this->getArg('pagename');
923         if (strstr($pagename,_('PhpWikiAdministration'))) {
924             $this->action_browse();
925         } else {
926             include('lib/removepage.php');
927             RemovePage($this);
928         }
929     }
930
931     function action_xmlrpc () {
932         include_once("lib/XmlRpcServer.php");
933         $xmlrpc = new XmlRpcServer($this);
934         $xmlrpc->service();
935     }
936     
937     function action_revert () {
938         include_once "lib/loadsave.php";
939         RevertPage($this);
940     }
941
942     function action_zip () {
943         include_once("lib/loadsave.php");
944         MakeWikiZip($this);
945         // I don't think it hurts to add cruft at the end of the zip file.
946         //echo "\n========================================================\n";
947         //echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
948     }
949
950     function action_ziphtml () {
951         include_once("lib/loadsave.php");
952         MakeWikiZipHtml($this);
953         // I don't think it hurts to add cruft at the end of the zip file.
954         echo "\n========================================================\n";
955         echo "PhpWiki " . PHPWIKI_VERSION . " source:\n$GLOBALS[RCS_IDS]\n";
956     }
957
958     function action_dumpserial () {
959         include_once("lib/loadsave.php");
960         DumpToDir($this);
961     }
962
963     function action_dumphtml () {
964         include_once("lib/loadsave.php");
965         DumpHtmlToDir($this);
966     }
967
968     function action_upload () {
969         include_once("lib/loadsave.php");
970         LoadPostFile($this);
971     }
972
973     function action_upgrade () {
974         include_once("lib/loadsave.php");
975         include_once("lib/upgrade.php");
976         DoUpgrade($this);
977     }
978
979     function action_loadfile () {
980         include_once("lib/loadsave.php");
981         LoadFileOrDir($this);
982     }
983
984     function action_pdf () {
985         include_once("lib/pdf.php");
986         ConvertAndDisplayPdf($this);
987     }
988     
989 }
990
991 //FIXME: deprecated
992 function is_safe_action ($action) {
993     return WikiRequest::requiredAuthorityForAction($action) < WIKIAUTH_ADMIN;
994 }
995
996 function validateSessionPath() {
997     // Try to defer any session.save_path PHP errors before any html
998     // is output, which causes some versions of IE to display a blank
999     // page (due to its strict mode while parsing a page?).
1000     if (! is_writeable(ini_get('session.save_path'))) {
1001         $tmpdir = '/tmp';
1002         trigger_error
1003             (sprintf(_("%s is not writable."),
1004                      _("The session.save_path directory"))
1005              . "\n"
1006              . sprintf(_("Please ensure that %s is writable, or redefine %s in config/config.ini."),
1007                        sprintf(_("the directory '%s'"),
1008                                ini_get('session.save_path')),
1009                        'session.save_path')
1010              . "\n"
1011              . sprintf(_("Attempting to use the directory '%s' instead."),
1012                        $tmpdir)
1013              , E_USER_NOTICE);
1014         if (! is_writeable($tmpdir)) {
1015             trigger_error
1016                 (sprintf(_("%s is not writable."), $tmpdir)
1017                  . "\n"
1018                  . _("Users will not be able to sign in.")
1019                  , E_USER_NOTICE);
1020         }
1021         else
1022             ini_set('session.save_path', $tmpdir);
1023     }
1024 }
1025
1026 function main () {
1027     if (!USE_DB_SESSION)
1028         validateSessionPath();
1029
1030     global $request;
1031     if ((DEBUG & _DEBUG_APD) and extension_loaded("apd"))
1032         apd_set_session_trace(9);
1033
1034     // Postpone warnings
1035     global $ErrorManager;
1036     if (defined('E_STRICT')) // and (E_ALL & E_STRICT)) // strict php5?
1037         $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE|E_USER_WARNING|E_WARNING|E_STRICT);
1038     else
1039         $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE|E_USER_WARNING|E_WARNING);
1040     $request = new WikiRequest();
1041
1042     $action = $request->getArg('action');
1043     if (substr($action, 0, 3) != 'zip') {
1044         if ($action == 'pdf')
1045             $ErrorManager->setPostponedErrorMask(-1); // everything
1046         //else // reject postponing of warnings
1047         //    $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
1048     }
1049
1050     /*
1051      * Allow for disabling of markup cache.
1052      * (Mostly for debugging ... hopefully.)
1053      *
1054      * See also <?plugin WikiAdminUtils action=purge-cache ?>
1055      */
1056     if (!defined('WIKIDB_NOCACHE_MARKUP') and $request->getArg('nocache'))
1057         define('WIKIDB_NOCACHE_MARKUP', $request->getArg('nocache'));
1058     
1059     // Initialize with system defaults in case user not logged in.
1060     // Should this go into constructor?
1061     $request->initializeTheme();
1062
1063     $request->updateAuthAndPrefs();
1064     $request->initializeLang();
1065     
1066     //FIXME:
1067     //if ($user->is_authenticated())
1068     //  $LogEntry->user = $user->getId();
1069
1070     // Memory optimization:
1071     // http://www.procata.com/blog/archives/2004/05/27/rephlux-and-php-memory-usage/
1072     // kill the global PEAR _PEAR_destructor_object_list
1073     if (!empty($_PEAR_destructor_object_list))
1074         $_PEAR_destructor_object_list = array();
1075     $request->possiblyDeflowerVirginWiki();
1076     
1077 // hack! define proper actions for these.
1078 if (defined('WIKI_XMLRPC') and WIKI_XMLRPC) return;
1079 if (defined('WIKI_SOAP')   and WIKI_SOAP)   return;
1080
1081     $validators = array('wikiname' => WIKI_NAME,
1082                         'args'     => hash($request->getArgs()),
1083                         'prefs'    => hash($request->getPrefs()));
1084     if (CACHE_CONTROL == 'STRICT') {
1085         $dbi = $request->getDbh();
1086         $timestamp = $dbi->getTimestamp();
1087         $validators['mtime'] = $timestamp;
1088         $validators['%mtime'] = (int)$timestamp;
1089     }
1090     // FIXME: we should try to generate strong validators when possible,
1091     // but for now, our validator is weak, since equal validators do not
1092     // indicate byte-level equality of content.  (Due to DEBUG timing output, etc...)
1093     //
1094     // (If DEBUG if off, this may be a strong validator, but I'm going
1095     // to go the paranoid route here pending further study and testing.)
1096     //
1097     $validators['%weak'] = true;
1098     $request->setValidators($validators);
1099    
1100     $request->handleAction();
1101
1102     if (DEBUG and DEBUG & _DEBUG_INFO) phpinfo(INFO_VARIABLES);
1103     $request->finish();
1104 }
1105
1106 //$x = error_reporting();  // DEBUG: why is it 1 here? should be E_ALL
1107 if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
1108     error_reporting(E_ALL & ~E_STRICT);         // exclude E_STRICT
1109 else
1110     error_reporting(E_ALL); // php4
1111 // don't run the main loop for special requests (test, getimg, xmlrpc, soap, ...)
1112 if (!defined('PHPWIKI_NOMAIN') or !PHPWIKI_NOMAIN)
1113     main();
1114
1115
1116 // $Log: not supported by cvs2svn $
1117 // Revision 1.182  2004/10/12 13:13:19  rurban
1118 // php5 compatibility (5.0.1 ok)
1119 //
1120 // Revision 1.181  2004/10/07 16:08:58  rurban
1121 // fixed broken FileUser session handling.
1122 //   thanks to Arnaud Fontaine for detecting this.
1123 // enable file user Administrator membership.
1124 //
1125 // Revision 1.180  2004/10/04 23:39:34  rurban
1126 // just aesthetics
1127 //
1128 // Revision 1.179  2004/09/25 18:57:42  rurban
1129 // better ACL error message: view not browse, change not setacl, ...
1130 //
1131 // Revision 1.178  2004/09/25 16:27:36  rurban
1132 // better not allowed description: on global disallowed, and on missing pageperms
1133 //
1134 // Revision 1.177  2004/09/14 10:31:09  rurban
1135 // exclude E_STRICT for php5: untested. I believe this must be set earlier because the parsing step is already strict, and this is called at run-time
1136 //
1137 // Revision 1.176  2004/08/05 17:33:22  rurban
1138 // aesthetic typo
1139 //
1140 // Revision 1.175  2004/07/13 13:08:25  rurban
1141 // fix PEAR memory waste issues
1142 //
1143 // Revision 1.174  2004/07/08 13:50:32  rurban
1144 // various unit test fixes: print error backtrace on _DEBUG_TRACE; allusers fix; new PHPWIKI_NOMAIN constant for omitting the mainloop
1145 //
1146 // Revision 1.173  2004/07/05 12:57:54  rurban
1147 // add mysql timeout
1148 //
1149 // Revision 1.172  2004/07/03 08:04:19  rurban
1150 // fixed implicit PersonalPage login (e.g. on edit), fixed to check against create ACL on create, not edit
1151 //
1152 // Revision 1.171  2004/06/29 09:30:42  rurban
1153 // force string hash
1154 //
1155 // Revision 1.170  2004/06/25 14:29:20  rurban
1156 // WikiGroup refactoring:
1157 //   global group attached to user, code for not_current user.
1158 //   improved helpers for special groups (avoid double invocations)
1159 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
1160 // fixed a XHTML validation error on userprefs.tmpl
1161 //
1162 // Revision 1.169  2004/06/20 14:42:54  rurban
1163 // various php5 fixes (still broken at blockparser)
1164 //
1165 // Revision 1.168  2004/06/17 10:39:18  rurban
1166 // fix reverse translation of possible actionpage
1167 //
1168 // Revision 1.167  2004/06/16 13:21:16  rurban
1169 // stabilize on failing ldap queries or bind
1170 //
1171 // Revision 1.166  2004/06/15 09:15:52  rurban
1172 // IMPORTANT: fixed passwd handling for passwords stored in prefs:
1173 //   fix encrypted usage, actually store and retrieve them from db
1174 //   fix bogologin with passwd set.
1175 // fix php crashes with call-time pass-by-reference (references wrongly used
1176 //   in declaration AND call). This affected mainly Apache2 and IIS.
1177 //   (Thanks to John Cole to detect this!)
1178 //
1179 // Revision 1.165  2004/06/14 11:31:37  rurban
1180 // renamed global $Theme to $WikiTheme (gforge nameclash)
1181 // inherit PageList default options from PageList
1182 //   default sortby=pagename
1183 // use options in PageList_Selectable (limit, sortby, ...)
1184 // added action revert, with button at action=diff
1185 // added option regex to WikiAdminSearchReplace
1186 //
1187 // Revision 1.164  2004/06/13 13:54:25  rurban
1188 // Catch fatals on the four dump calls (as file and zip, as html and mimified)
1189 // FoafViewer: Check against external requirements, instead of fatal.
1190 // Change output for xhtmldumps: using file:// urls to the local fs.
1191 // Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
1192 // Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
1193 //
1194 // Revision 1.163  2004/06/13 11:35:32  rurban
1195 // check for create action on action=edit not to fool PagePerm checks
1196 //
1197 // Revision 1.162  2004/06/08 10:05:11  rurban
1198 // simplified admin action shortcuts
1199 //
1200 // Revision 1.161  2004/06/07 22:58:40  rurban
1201 // simplified chown, setacl, dump actions
1202 //
1203 // Revision 1.160  2004/06/07 22:44:14  rurban
1204 // added simplified chown, setacl actions
1205 //
1206 // Revision 1.159  2004/06/06 16:58:51  rurban
1207 // added more required ActionPages for foreign languages
1208 // install now english ActionPages if no localized are found. (again)
1209 // fixed default anon user level to be 0, instead of -1
1210 //   (wrong "required administrator to view this page"...)
1211 //
1212 // Revision 1.158  2004/06/04 20:32:53  rurban
1213 // Several locale related improvements suggested by Pierrick Meignen
1214 // LDAP fix by John Cole
1215 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
1216 //
1217 // Revision 1.157  2004/06/04 12:40:21  rurban
1218 // Restrict valid usernames to prevent from attacks against external auth or compromise
1219 // possible holes.
1220 // Fix various WikiUser old issues with default IMAP,LDAP,POP3 configs. Removed these.
1221 // Fxied more warnings
1222 //
1223 // Revision 1.156  2004/06/03 17:58:16  rurban
1224 // support immediate LANG and THEME switch inside a session
1225 //
1226 // Revision 1.155  2004/06/03 10:18:19  rurban
1227 // fix FileUser locking issues, new config ENABLE_PAGEPERM
1228 //
1229 // Revision 1.154  2004/06/02 18:01:46  rurban
1230 // init global FileFinder to add proper include paths at startup
1231 //   adds PHPWIKI_DIR if started from another dir, lib/pear also
1232 // fix slashify for Windows
1233 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
1234 //
1235 // Revision 1.153  2004/06/01 15:28:00  rurban
1236 // AdminUser only ADMIN_USER not member of Administrators
1237 // some RateIt improvements by dfrankow
1238 // edit_toolbar buttons
1239 //
1240 // Revision 1.152  2004/05/27 17:49:06  rurban
1241 // renamed DB_Session to DbSession (in CVS also)
1242 // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
1243 // remove leading slash in error message
1244 // added force_unlock parameter to File_Passwd (no return on stale locks)
1245 // fixed adodb session AffectedRows
1246 // added FileFinder helpers to unify local filenames and DATA_PATH names
1247 // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
1248 //
1249 // Revision 1.151  2004/05/25 12:40:48  rurban
1250 // trim the pagename
1251 //
1252 // Revision 1.150  2004/05/25 10:18:44  rurban
1253 // Check for UTF-8 URLs; Internet Explorer produces these if you
1254 // type non-ASCII chars in the URL bar or follow unescaped links.
1255 // Fixes sf.net bug #953949
1256 // src: languages/Language.php:checkTitleEncoding() from mediawiki
1257 //
1258 // Revision 1.149  2004/05/18 13:31:19  rurban
1259 // hold warnings until headers are sent. new Error-style with collapsed output of repeated messages
1260 //
1261 // Revision 1.148  2004/05/17 17:43:29  rurban
1262 // CGI: no PATH_INFO fix
1263 //
1264 // Revision 1.147  2004/05/15 19:48:33  rurban
1265 // fix some too loose PagePerms for signed, but not authenticated users
1266 //  (admin, owner, creator)
1267 // no double login page header, better login msg.
1268 // moved action_pdf to lib/pdf.php
1269 //
1270 // Revision 1.146  2004/05/15 18:31:01  rurban
1271 // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
1272 //
1273 // Revision 1.145  2004/05/12 10:49:55  rurban
1274 // require_once fix for those libs which are loaded before FileFinder and
1275 //   its automatic include_path fix, and where require_once doesn't grok
1276 //   dirname(__FILE__) != './lib'
1277 // upgrade fix with PearDB
1278 // navbar.tmpl: remove spaces for IE &nbsp; button alignment
1279 //
1280 // Revision 1.144  2004/05/06 19:26:16  rurban
1281 // improve stability, trying to find the InlineParser endless loop on sf.net
1282 //
1283 // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
1284 //
1285 // Revision 1.143  2004/05/06 17:30:38  rurban
1286 // CategoryGroup: oops, dos2unix eol
1287 // improved phpwiki_version:
1288 //   pre -= .0001 (1.3.10pre: 1030.099)
1289 //   -p1 += .001 (1.3.9-p1: 1030.091)
1290 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
1291 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
1292 //   backend->backendType(), backend->database(),
1293 //   backend->listOfFields(),
1294 //   backend->listOfTables(),
1295 //
1296 // Revision 1.142  2004/05/04 22:34:25  rurban
1297 // more pdf support
1298 //
1299 // Revision 1.141  2004/05/03 13:16:47  rurban
1300 // fixed UserPreferences update, esp for boolean and int
1301 //
1302 // Revision 1.140  2004/05/02 21:26:38  rurban
1303 // limit user session data (HomePageHandle and auth_dbi have to invalidated anyway)
1304 //   because they will not survive db sessions, if too large.
1305 // extended action=upgrade
1306 // some WikiTranslation button work
1307 // revert WIKIAUTH_UNOBTAINABLE (need it for main.php)
1308 // some temp. session debug statements
1309 //
1310 // Revision 1.139  2004/05/02 15:10:07  rurban
1311 // new finally reliable way to detect if /index.php is called directly
1312 //   and if to include lib/main.php
1313 // new global AllActionPages
1314 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
1315 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
1316 // PageGroupTestOne => subpages
1317 // renamed PhpWikiRss to PhpWikiRecentChanges
1318 // more docs, default configs, ...
1319 //
1320 // Revision 1.138  2004/05/01 15:59:29  rurban
1321 // more php-4.0.6 compatibility: superglobals
1322 //
1323 // Revision 1.137  2004/04/29 19:39:44  rurban
1324 // special support for formatted plugins (one-liners)
1325 //   like <small><plugin BlaBla ></small>
1326 // iter->asArray() helper for PopularNearby
1327 // db_session for older php's (no &func() allowed)
1328 //
1329 // Revision 1.136  2004/04/29 17:18:19  zorloc
1330 // Fixes permission failure issues.  With PagePermissions and Disabled Actions when user did not have permission WIKIAUTH_FORBIDDEN was returned.  In WikiUser this was ok because WIKIAUTH_FORBIDDEN had a value of 11 -- thus no user could perform that action.  But WikiUserNew has a WIKIAUTH_FORBIDDEN value of -1 -- thus a user without sufficent permission to do anything.  The solution is a new high value permission level (WIKIAUTH_UNOBTAINABLE) to be the default level for access failure.
1331 //
1332 // Revision 1.135  2004/04/26 12:15:01  rurban
1333 // check default config values
1334 //
1335 // Revision 1.134  2004/04/23 06:46:37  zorloc
1336 // Leave DB connection open when USE_DB_SESSION is true so that session info can be written to the DB.
1337 //
1338 // Revision 1.133  2004/04/20 18:10:31  rurban
1339 // config refactoring:
1340 //   FileFinder is needed for WikiFarm scripts calling index.php
1341 //   config run-time calls moved to lib/IniConfig.php:fix_configs()
1342 //   added PHPWIKI_DIR smart-detection code (Theme finder)
1343 //   moved FileFind to lib/FileFinder.php
1344 //   cleaned lib/config.php
1345 //
1346 // Revision 1.132  2004/04/19 21:51:41  rurban
1347 // php5 compatibility: it works!
1348 //
1349 // Revision 1.131  2004/04/19 18:27:45  rurban
1350 // Prevent from some PHP5 warnings (ref args, no :: object init)
1351 //   php5 runs now through, just one wrong XmlElement object init missing
1352 // Removed unneccesary UpgradeUser lines
1353 // Changed WikiLink to omit version if current (RecentChanges)
1354 //
1355 // Revision 1.130  2004/04/18 00:25:53  rurban
1356 // allow "0" pagename
1357 //
1358 // Revision 1.129  2004/04/07 23:13:19  rurban
1359 // fixed pear/File_Passwd for Windows
1360 // fixed FilePassUser sessions (filehandle revive) and password update
1361 //
1362 // Revision 1.128  2004/04/02 15:06:55  rurban
1363 // fixed a nasty ADODB_mysql session update bug
1364 // improved UserPreferences layout (tabled hints)
1365 // fixed UserPreferences auth handling
1366 // improved auth stability
1367 // improved old cookie handling: fixed deletion of old cookies with paths
1368 //
1369 // Revision 1.127  2004/03/25 17:00:31  rurban
1370 // more code to convert old-style pref array to new hash
1371 //
1372 // Revision 1.126  2004/03/24 19:39:03  rurban
1373 // php5 workaround code (plus some interim debugging code in XmlElement)
1374 //   php5 doesn't work yet with the current XmlElement class constructors,
1375 //   WikiUserNew does work better than php4.
1376 // rewrote WikiUserNew user upgrading to ease php5 update
1377 // fixed pref handling in WikiUserNew
1378 // added Email Notification
1379 // added simple Email verification
1380 // removed emailVerify userpref subclass: just a email property
1381 // changed pref binary storage layout: numarray => hash of non default values
1382 // print optimize message only if really done.
1383 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1384 //   prefs should be stored in db or homepage, besides the current session.
1385 //
1386 // Revision 1.125  2004/03/14 16:30:52  rurban
1387 // db-handle session revivification, dba fixes
1388 //
1389 // Revision 1.124  2004/03/12 15:48:07  rurban
1390 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
1391 // simplified lib/stdlib.php:explodePageList
1392 //
1393 // Revision 1.123  2004/03/10 15:41:27  rurban
1394 // use default pref mysql table
1395 //
1396 // Revision 1.122  2004/03/08 18:17:09  rurban
1397 // added more WikiGroup::getMembersOf methods, esp. for special groups
1398 // fixed $LDAP_SET_OPTIONS
1399 // fixed _AuthInfo group methods
1400 //
1401 // Revision 1.121  2004/03/01 13:48:45  rurban
1402 // rename fix
1403 // p[] consistency fix
1404 //
1405 // Revision 1.120  2004/03/01 10:22:41  rurban
1406 // initializeTheme optimize
1407 //
1408 // Revision 1.119  2004/02/26 20:45:06  rurban
1409 // check for ALLOW_ANON_USER = false
1410 //
1411 // Revision 1.118  2004/02/26 01:32:03  rurban
1412 // fixed session login with old WikiUser object. strangely, the errormask gets corruoted to 1, Pear???
1413 //
1414 // Revision 1.117  2004/02/24 17:19:37  rurban
1415 // debugging helpers only
1416 //
1417 // Revision 1.116  2004/02/24 15:17:14  rurban
1418 // improved auth errors with individual pages. the fact that you may not browse a certain admin page does not conclude that you may not browse the whole wiki. renamed browse => view
1419 //
1420 // Revision 1.115  2004/02/15 21:34:37  rurban
1421 // PageList enhanced and improved.
1422 // fixed new WikiAdmin... plugins
1423 // editpage, Theme with exp. htmlarea framework
1424 //   (htmlarea yet committed, this is really questionable)
1425 // WikiUser... code with better session handling for prefs
1426 // enhanced UserPreferences (again)
1427 // RecentChanges for show_deleted: how should pages be deleted then?
1428 //
1429 // Revision 1.114  2004/02/15 17:30:13  rurban
1430 // workaround for lost db connnection handle on session restauration (->_auth_dbi)
1431 // fixed getPreferences() (esp. from sessions)
1432 // fixed setPreferences() (update and set),
1433 // fixed AdoDb DB statements,
1434 // update prefs only at UserPreferences POST (for testing)
1435 // unified db prefs methods (but in external pref classes yet)
1436 //
1437 // Revision 1.113  2004/02/12 13:05:49  rurban
1438 // Rename functional for PearDB backend
1439 // some other minor changes
1440 // SiteMap comes with a not yet functional feature request: includepages (tbd)
1441 //
1442 // Revision 1.112  2004/02/09 03:58:12  rurban
1443 // for now default DB_SESSION to false
1444 // PagePerm:
1445 //   * not existing perms will now query the parent, and not
1446 //     return the default perm
1447 //   * added pagePermissions func which returns the object per page
1448 //   * added getAccessDescription
1449 // WikiUserNew:
1450 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
1451 //   * force init of authdbh in the 2 db classes
1452 // main:
1453 //   * fixed session handling (not triple auth request anymore)
1454 //   * don't store cookie prefs with sessions
1455 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
1456 //
1457 // Revision 1.111  2004/02/07 10:41:25  rurban
1458 // fixed auth from session (still double code but works)
1459 // fixed GroupDB
1460 // fixed DbPassUser upgrade and policy=old
1461 // added GroupLdap
1462 //
1463 // Revision 1.110  2004/02/03 09:45:39  rurban
1464 // LDAP cleanup, start of new Pref classes
1465 //
1466 // Revision 1.109  2004/01/30 19:57:58  rurban
1467 // fixed DBAuthParams['pref_select']: wrong _auth_dbi object used.
1468 //
1469 // Revision 1.108  2004/01/28 14:34:14  rurban
1470 // session table takes the common prefix
1471 // + various minor stuff
1472 // reallow password changing
1473 //
1474 // Revision 1.107  2004/01/27 23:23:39  rurban
1475 // renamed ->Username => _userid for consistency
1476 // renamed mayCheckPassword => mayCheckPass
1477 // fixed recursion problem in WikiUserNew
1478 // fixed bogo login (but not quite 100% ready yet, password storage)
1479 //
1480 // Revision 1.106  2004/01/26 09:17:49  rurban
1481 // * changed stored pref representation as before.
1482 //   the array of objects is 1) bigger and 2)
1483 //   less portable. If we would import packed pref
1484 //   objects and the object definition was changed, PHP would fail.
1485 //   This doesn't happen with an simple array of non-default values.
1486 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1487 //   understands the interim format of array of objects also.
1488 // * simplified $prefs->get() and fixed $prefs->set()
1489 // * added $user->_userid and class '_WikiUser' portability functions
1490 // * fixed $user object ->_level upgrading, mostly using sessions.
1491 //   this fixes yesterdays problems with loosing authorization level.
1492 // * fixed WikiUserNew::checkPass to return the _level
1493 // * fixed WikiUserNew::isSignedIn
1494 // * added explodePageList to class PageList, support sortby arg
1495 // * fixed UserPreferences for WikiUserNew
1496 // * fixed WikiPlugin for empty defaults array
1497 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1498 //   removed sort arg, support sortby arg
1499 //
1500 // Revision 1.105  2004/01/25 03:57:15  rurban
1501 // WikiUserNew support (temp. ENABLE_USER_NEW constant)
1502 //
1503 // Revision 1.104  2003/12/26 06:41:16  carstenklapp
1504 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
1505 // so they don't prevent IE from partially (or not at all) rendering the
1506 // page. This should help a little for the IE user who encounters trouble
1507 // when setting up a new PhpWiki for the first time.
1508 //
1509 // Revision 1.103  2003/12/02 00:10:00  carstenklapp
1510 // Bugfix: Ongoing work to untangle UserPreferences/WikiUser/request code
1511 // mess: UserPreferences should take effect immediately now upon signing
1512 // in.
1513 //
1514 // Revision 1.102  2003/11/25 22:55:32  carstenklapp
1515 // Localization bugfix: For wikis where English is not the default system
1516 // language, make sure that the authority error message (i.e. "You must
1517 // sign in to edit pages in this wiki" etc.) is displayed in the wiki's
1518 // default language. Previously it would always display in English.
1519 // (Added call to update_locale() before displaying any messages prior to
1520 // the login prompt.)
1521 //
1522 // Revision 1.101  2003/11/25 21:49:44  carstenklapp
1523 // Bugfix: For a non-english wiki or when the user's preference is not
1524 // english, the wiki would always use the english ActionPage first if it
1525 // was present rather than the appropriate localised variant. (PhpWikis
1526 // running only in english or Wikis running ONLY without any english
1527 // ActionPages would not notice this bug, only when both english and
1528 // localised ActionPages were in the DB.) Now we check for the localised
1529 // variant first.
1530 //
1531 // Revision 1.100  2003/11/18 16:54:18  carstenklapp
1532 // Reformatting only: Tabs to spaces, added rcs log.
1533 //
1534
1535
1536 // Local Variables:
1537 // mode: php
1538 // tab-width: 8
1539 // c-basic-offset: 4
1540 // c-hanging-comment-ender-p: nil
1541 // indent-tabs-mode: nil
1542 // End:
1543 ?>