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