]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/Request.php
enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for...
[SourceForge/phpwiki.git] / lib / Request.php
1 <?php // -*-php-*-
2 rcs_id('$Id: Request.php,v 1.82 2004-12-06 19:49:55 rurban Exp $');
3 /*
4  Copyright (C) 2002,2004 $ThePhpWikiProgrammingTeam
5  
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 // backward compatibility for PHP < 4.2.0
24 if (!function_exists('ob_clean')) {
25     function ob_clean() {
26         ob_end_clean();
27         ob_start();
28     }
29 }
30
31 class Request {
32         
33     function Request() {
34         $this->_fix_magic_quotes_gpc();
35         $this->_fix_multipart_form_data();
36         
37         switch($this->get('REQUEST_METHOD')) {
38         case 'GET':
39         case 'HEAD':
40             $this->args = &$GLOBALS['HTTP_GET_VARS'];
41             break;
42         case 'POST':
43             $this->args = &$GLOBALS['HTTP_POST_VARS'];
44             break;
45         default:
46             $this->args = array();
47             break;
48         }
49         
50         $this->session = new Request_SessionVars; 
51         $this->cookies = new Request_CookieVars;
52         
53         if (ACCESS_LOG or ACCESS_LOG_SQL) {
54             $this->_accesslog =& new Request_AccessLog(ACCESS_LOG, ACCESS_LOG_SQL);
55         }
56         
57         $GLOBALS['request'] = $this;
58     }
59
60     function get($key) {
61         if (!empty($GLOBALS['HTTP_SERVER_VARS']))
62             $vars = &$GLOBALS['HTTP_SERVER_VARS'];
63         else // cgi or other servers than Apache
64             $vars = &$GLOBALS['HTTP_ENV_VARS'];
65
66         if (isset($vars[$key]))
67             return $vars[$key];
68
69         switch ($key) {
70         case 'REMOTE_HOST':
71             $addr = $vars['REMOTE_ADDR'];
72             if (defined('ENABLE_REVERSE_DNS') && ENABLE_REVERSE_DNS)
73                 return $vars[$key] = gethostbyaddr($addr);
74             else
75                 return $addr;
76         default:
77             return false;
78         }
79     }
80
81     function getArg($key) {
82         if (isset($this->args[$key]))
83             return $this->args[$key];
84         return false;
85     }
86
87     function getArgs () {
88         return $this->args;
89     }
90     
91     function setArg($key, $val) {
92         if ($val === false)
93             unset($this->args[$key]);
94         else
95             $this->args[$key] = $val;
96     }
97     
98     // Well oh well. Do we really want to pass POST params back as GET?
99     function getURLtoSelf($args = false, $exclude = array()) {
100         $get_args = $this->args;
101         if ($args)
102             $get_args = array_merge($get_args, $args);
103
104         // Err... good point...
105         // sortby buttons
106         if ($this->isPost()) {
107             $exclude = array_merge($exclude, array('action','auth'));
108             //$get_args = $args; // or only the provided
109             /*
110             trigger_error("Request::getURLtoSelf() should probably not be from POST",
111                           E_USER_NOTICE);
112             */
113         }
114
115         foreach ($exclude as $ex) {
116             if (!empty($get_args[$ex])) unset($get_args[$ex]);
117         }
118
119         $pagename = $get_args['pagename'];
120         unset ($get_args['pagename']);
121         if (!empty($get_args['action']) and $get_args['action'] == 'browse')
122             unset($get_args['action']);
123
124         return WikiURL($pagename, $get_args);
125     }
126
127     function isPost () {
128         return $this->get("REQUEST_METHOD") == "POST";
129     }
130
131     function isGetOrHead () {
132         return in_array($this->get('REQUEST_METHOD'),
133                         array('GET', 'HEAD'));
134     }
135
136     function httpVersion() {
137         if (!preg_match('@HTTP\s*/\s*(\d+.\d+)@', $this->get('SERVER_PROTOCOL'), $m))
138             return false;
139         return (float) $m[1];
140     }
141     
142     function redirect($url, $noreturn=true) {
143         $bogus = defined('DISABLE_HTTP_REDIRECT') and DISABLE_HTTP_REDIRECT;
144         
145         if (!$bogus) {
146             header("Location: $url");
147             /*
148              * "302 Found" is not really meant to be sent in response
149              * to a POST.  Worse still, according to (both HTTP 1.0
150              * and 1.1) spec, the user, if it is sent, the user agent
151              * is supposed to use the same method to fetch the
152              * redirected URI as the original.
153              *
154              * That means if we redirect from a POST, the user-agent
155              * supposed to generate another POST.  Not what we want.
156              * (We do this after a page save after all.)
157              *
158              * Fortunately, most/all browsers don't do that.
159              *
160              * "303 See Other" is what we really want.  But it only
161              * exists in HTTP/1.1
162              *
163              * FIXME: this is still not spec compliant for HTTP
164              * version < 1.1.
165              */
166             $status = $this->httpVersion() >= 1.1 ? 303 : 302;
167             $this->setStatus($status);
168         }
169
170         if ($noreturn) {
171             include_once('lib/Template.php');
172             $this->discardOutput();
173             $tmpl = new Template('redirect', $this, array('REDIRECT_URL' => $url));
174             $tmpl->printXML();
175             $this->finish();
176         }
177         else if ($bogus) {
178             return JavaScript("
179               function redirect(url) {
180                 if (typeof location.replace == 'function')
181                   location.replace(url);
182                 else if (typeof location.assign == 'function')
183                   location.assign(url);
184                 else
185                   window.location = url;
186               }
187               redirect('" . addslashes($url) . "')");
188         }
189     }
190
191     /** Set validators for this response.
192      *
193      * This sets a (possibly incomplete) set of validators
194      * for this response.
195      *
196      * The validator set can be extended using appendValidators().
197      *
198      * When you're all done setting and appending validators, you
199      * must call checkValidators() to check them and set the
200      * appropriate headers in the HTTP response.
201      *
202      * Example Usage:
203      *  ...
204      *  $request->setValidators(array('pagename' => $pagename,
205      *                                '%mtime' => $rev->get('mtime')));
206      *  ...
207      *  // Wups... response content depends on $otherpage, too...
208      *  $request->appendValidators(array('otherpage' => $otherpagerev->getPageName(),
209      *                                   '%mtime' => $otherpagerev->get('mtime')));
210      *  ...
211      *  // After all validators have been set:
212      *  $request->checkValidators();
213      */
214     function setValidators($validator_set) {
215         if (is_array($validator_set))
216             $validator_set = new HTTP_ValidatorSet($validator_set);
217         $this->_validators = $validator_set;
218     }
219     
220     /** Append more validators for this response. 
221      *  i.e dependencies on other pages mtimes
222      *  now it may be called in init also to simplify client code.
223      */ 
224     function appendValidators($validator_set) {
225         if (!isset($this->_validators)) {
226             $this->setValidators($validator_set);
227             return;
228         }
229         $this->_validators->append($validator_set);
230     }
231     
232     /** Check validators and set headers in HTTP response
233      *
234      * This sets the appropriate "Last-Modified" and "ETag"
235      * headers in the HTTP response.
236      *
237      * Additionally, if the validators match any(all) conditional
238      * headers in the HTTP request, this method will not return, but
239      * instead will send "304 Not Modified" or "412 Precondition
240      * Failed" (as appropriate) back to the client.
241      */
242     function checkValidators() {
243         $validators = &$this->_validators;
244         
245         // Set validator headers
246         if ($this->_is_buffering_output or !headers_sent()) {
247             if (($etag = $validators->getETag()) !== false)
248                 header("ETag: " . $etag->asString());
249             if (($mtime = $validators->getModificationTime()) !== false)
250                 header("Last-Modified: " . Rfc1123DateTime($mtime));
251
252             // Set cache control headers
253             $this->cacheControl();
254         }
255
256         if (CACHE_CONTROL == 'NO_CACHE')
257             return;             // don't check conditionals...
258         
259         // Check conditional headers in request
260         $status = $validators->checkConditionalRequest($this);
261         if ($status) {
262             // Return short response due to failed conditionals
263             $this->setStatus($status);
264             print "\n\n";
265             $this->discardOutput();
266             $this->finish();
267             exit();
268         }
269     }
270
271     /** Set the cache control headers in the HTTP response.
272      */
273     function cacheControl($strategy=CACHE_CONTROL, $max_age=CACHE_CONTROL_MAX_AGE) {
274         if ($strategy == 'NO_CACHE') {
275             $cache_control = "no-cache"; // better set private. See Pear HTTP_Header
276             $max_age = -20;
277         }
278         elseif ($strategy == 'ALLOW_STALE' && $max_age > 0) {
279             $cache_control = sprintf("max-age=%d", $max_age);
280         }
281         else {
282             $cache_control = "must-revalidate";
283             $max_age = -20;
284         }
285         header("Cache-Control: $cache_control");
286         header("Expires: " . Rfc1123DateTime(time() + $max_age));
287         header("Vary: Cookie"); // FIXME: add more here?
288     }
289     
290     function setStatus($status) {
291         if (preg_match('|^HTTP/.*?\s(\d+)|i', $status, $m)) {
292             header($status);
293             $status = $m[1];
294         }
295         else {
296             $status = (integer) $status;
297             $reason = array('200' => 'OK',
298                             '302' => 'Found',
299                             '303' => 'See Other',
300                             '304' => 'Not Modified',
301                             '400' => 'Bad Request',
302                             '401' => 'Unauthorized',
303                             '403' => 'Forbidden',
304                             '404' => 'Not Found',
305                             '412' => 'Precondition Failed');
306             // FIXME: is it always okay to send HTTP/1.1 here, even for older clients?
307             header(sprintf("HTTP/1.1 %d %s", $status, $reason[$status]));
308         }
309
310         if (isset($this->_log_entry))
311             $this->_log_entry->setStatus($status);
312     }
313
314     function buffer_output($compress = true) {
315         // FIXME: disables sessions (some byte before all headers_sent())
316         /*if (defined('USECACHE') and !USECACHE) {
317             $this->_is_buffering_output = false;
318             return;
319         }*/
320         if (defined('COMPRESS_OUTPUT')) {
321             if (!COMPRESS_OUTPUT)
322                 $compress = false;
323         }
324         elseif (!check_php_version(4,2,3))
325             $compress = false;
326         elseif (isCGI()) // necessary?
327             $compress = false;
328             
329         if ($this->getArg('start_debug'))
330             $compress = false;
331         // Should we compress even when apache_note is not available?
332         // sf.net bug #933183 and http://bugs.php.net/17557
333         // This effectively eliminates CGI, but all other servers also. hmm.
334         if ($compress 
335             and (!function_exists('ob_gzhandler') 
336                  or !function_exists('apache_note'))) 
337             $compress = false;
338         // http://www.php.net/ob_gzhandler "output handler 'ob_gzhandler' cannot be used twice"
339         if ($compress and ini_get("zlib.output_compression"))
340             $compress = false;
341
342         // New: we check for the client Accept-Encoding: "gzip" presence also
343         // This should eliminate a lot or reported problems.
344         if ($compress
345             and (!$this->get("HTTP_ACCEPT_ENCODING")
346                  or !strstr($this->get("HTTP_ACCEPT_ENCODING"), "gzip")))
347             $compress = false;
348
349         // Most RSS clients are NOT(!) application/xml gzip compatible yet. 
350         // Even if they are sending the accept-encoding gzip header!
351         // wget is, Mozilla, and MSIE no.
352         // Of the RSS readers only MagpieRSS 0.5.2 is. http://www.rssgov.com/rssparsers.html
353         // See also http://phpwiki.sourceforge.net/phpwiki/KnownBugs
354         if ($compress 
355             and $this->getArg('format') 
356             and strstr($this->getArg('format'), 'rss'))
357             $compress = false;
358
359         if ($compress) {
360             ob_start('ob_gzhandler');
361             /*
362              * Attempt to prevent Apache from doing the dreaded double-gzip.
363              *
364              * It would be better if we could detect when apache was going
365              * to zip for us, and then let it ... but I have yet to figure
366              * out how to do that.
367              */
368             if (function_exists('apache_note'))
369                 @apache_note('no-gzip', 1);
370         }
371         else {
372             // Now we alway buffer output.
373             // This is so we can set HTTP headers (e.g. for redirect)
374             // at any point.
375             // FIXME: change the name of this method.
376             ob_start();
377         }
378         $this->_is_buffering_output = true;
379         $this->_ob_get_length = 0;
380     }
381
382     function discardOutput() {
383         if (!empty($this->_is_buffering_output)) {
384             ob_clean();
385             $this->_is_buffering_output = false;
386         } else {
387             trigger_error("Not buffering output", E_USER_NOTICE);
388         }
389     }
390
391     /** 
392      * Longer texts need too much memory on tiny or memory-limit=8MB systems.
393      * We might want to flush our buffer and restart again.
394      * (This would be fine if php would release its memory)
395      * Note that this must not be called inside Template expansion or other 
396      * sections with ob_buffering.
397      */
398     function chunkOutput() {
399         if (!empty($this->_is_buffering_output) or 
400             (function_exists('ob_get_level') and @ob_get_level())) {
401             $this->_do_chunked_output = true;
402             $this->_ob_get_length += ob_get_length();
403             while (@ob_end_flush());
404             ob_end_clean();
405             ob_start();
406         }
407     }
408
409     function finish() {
410         if (!empty($this->_accesslog)) {
411             $this->_accesslog->push($this);
412             if (empty($this->_do_chunked_output))
413                 $this->_ob_get_length = ob_get_length();
414             $this->_accesslog->setSize($this->_ob_get_length);
415             global $RUNTIMER;
416             if ($RUNTIMER) $this->_accesslog->setDuration($RUNTIMER->getTime());
417             // sql logging must be done before the db is closed.
418             $this->_accesslog->write_sql();
419         }
420         
421         session_write_close();
422         if (!empty($this->_dbi)) {
423             $this->_dbi->close();
424             unset($this->_dbi);
425         }
426
427         if (!empty($this->_is_buffering_output)) {
428             /* This cannot work because it might destroy xml markup */
429             /*
430             if (0 and $GLOBALS['SearchHighLightQuery'] and check_php_version(4,2)) {
431                 $html = str_replace($GLOBALS['SearchHighLightQuery'],
432                                     '<span class="search-term">'.$GLOBALS['SearchHighLightQuery'].'</span>',
433                                     ob_get_contents());
434                 ob_clean();
435                 header(sprintf("Content-Length: %d", strlen($html)));
436                 echo $html;
437             } else {
438             */
439             if (empty($this->_do_chunked_output)) {
440                 $this->_ob_get_length = ob_get_length();
441             }
442             header(sprintf("Content-Length: %d", $this->_ob_get_length));
443             //}
444             while (@ob_end_flush());
445             $this->_is_buffering_output = false;
446         }
447         exit;
448     }
449
450     function getSessionVar($key) {
451         return $this->session->get($key);
452     }
453     function setSessionVar($key, $val) {
454         if ($key == 'wiki_user') {
455             if (empty($val->page))
456                 $val->page = $this->getArg('pagename');
457             if (empty($val->action))
458                 $val->action = $this->getArg('action');
459             // avoid recursive objects and session resource handles
460             // avoid overlarge session data (max 4000 byte!)
461             if (isset($val->_group)) {
462                 unset($val->_group->_request);
463                 unset($val->_group->_user);
464             }
465             if (ENABLE_USER_NEW) {
466                 unset($val->_HomePagehandle);
467                 unset($val->_auth_dbi);
468             } else {
469                 unset($val->_dbi);
470                 unset($val->_authdbi);
471                 unset($val->_homepage);
472                 unset($val->_request);
473             }
474         }
475         return $this->session->set($key, $val);
476     }
477     function deleteSessionVar($key) {
478         return $this->session->delete($key);
479     }
480
481     function getCookieVar($key) {
482         return $this->cookies->get($key);
483     }
484     function setCookieVar($key, $val, $lifetime_in_days = false, $path = false) {
485         return $this->cookies->set($key, $val, $lifetime_in_days, $path);
486     }
487     function deleteCookieVar($key) {
488         return $this->cookies->delete($key);
489     }
490     
491     function getUploadedFile($key) {
492         return Request_UploadedFile::getUploadedFile($key);
493     }
494     
495
496     function _fix_magic_quotes_gpc() {
497         $needs_fix = array('HTTP_POST_VARS',
498                            'HTTP_GET_VARS',
499                            'HTTP_COOKIE_VARS',
500                            'HTTP_SERVER_VARS',
501                            'HTTP_POST_FILES');
502         
503         // Fix magic quotes.
504         if (get_magic_quotes_gpc()) {
505             foreach ($needs_fix as $vars)
506                 $this->_stripslashes($GLOBALS[$vars]);
507         }
508     }
509
510     function _stripslashes(&$var) {
511         if (is_array($var)) {
512             foreach ($var as $key => $val)
513                 $this->_stripslashes($var[$key]);
514         }
515         elseif (is_string($var))
516             $var = stripslashes($var);
517     }
518     
519     function _fix_multipart_form_data () {
520         if (preg_match('|^multipart/form-data|', $this->get('CONTENT_TYPE')))
521             $this->_strip_leading_nl($GLOBALS['HTTP_POST_VARS']);
522     }
523     
524     function _strip_leading_nl(&$var) {
525         if (is_array($var)) {
526             foreach ($var as $key => $val)
527                 $this->_strip_leading_nl($var[$key]);
528         }
529         elseif (is_string($var))
530             $var = preg_replace('|^\r?\n?|', '', $var);
531     }
532 }
533
534 class Request_SessionVars {
535     function Request_SessionVars() {
536         // Prevent cacheing problems with IE 5
537         session_cache_limiter('none');
538                                         
539         // Avoid to get a notice if session is already started,
540         // for example if session.auto_start is activated
541         if (!session_id())
542             session_start();
543     }
544     
545     function get($key) {
546         $vars = &$GLOBALS['HTTP_SESSION_VARS'];
547         if (isset($vars[$key]))
548             return $vars[$key];
549         return false;
550     }
551     
552     function set($key, $val) {
553         $vars = &$GLOBALS['HTTP_SESSION_VARS'];
554         if (!function_usable('get_cfg_var') or get_cfg_var('register_globals')) {
555             // This is funky but necessary, at least in some PHP's
556             $GLOBALS[$key] = $val;
557         }
558         $vars[$key] = $val;
559         if (isset($_SESSION))
560             $_SESSION[$key] = $val;
561         session_register($key);
562     }
563     
564     function delete($key) {
565         $vars = &$GLOBALS['HTTP_SESSION_VARS'];
566         if (!function_usable('ini_get') or ini_get('register_globals'))
567             unset($GLOBALS[$key]);
568         if (DEBUG) trigger_error("delete session $key",E_USER_WARNING);
569         unset($vars[$key]);
570         session_unregister($key);
571     }
572 }
573
574 class Request_CookieVars {
575     
576     function get($key) {
577         $vars = &$GLOBALS['HTTP_COOKIE_VARS'];
578         if (isset($vars[$key])) {
579             @$val = unserialize(base64_decode($vars[$key]));
580             if (!empty($val))
581                 return $val;
582             @$val = urldecode($vars[$key]);
583             if (!empty($val))
584                 return $val;
585         }
586         return false;
587     }
588
589     function get_old($key) {
590         $vars = &$GLOBALS['HTTP_COOKIE_VARS'];
591         if (isset($vars[$key])) {
592             @$val = unserialize(base64_decode($vars[$key]));
593             if (!empty($val))
594                 return $val;
595             @$val = unserialize($vars[$key]);
596             if (!empty($val))
597                 return $val;
598             @$val = $vars[$key];
599             if (!empty($val))
600                 return $val;
601         }
602         return false;
603     }
604
605     function set($key, $val, $persist_days = false, $path = false) {
606         // if already defined, ignore
607         if (defined('MAIN_setUser') and $key = 'WIKI_ID') return;
608         $vars = &$GLOBALS['HTTP_COOKIE_VARS'];
609         if (is_numeric($persist_days)) {
610             $expires = time() + (24 * 3600) * $persist_days;
611         }
612         else {
613             $expires = 0;
614         }
615         if (is_array($val) or is_object($val))
616             $packedval = base64_encode(serialize($val));
617         else
618             $packedval = urlencode($val);
619         $vars[$key] = $packedval;
620         if ($path)
621             @setcookie($key, $packedval, $expires, $path);
622         else
623             @setcookie($key, $packedval, $expires);
624     }
625     
626     function delete($key) {
627         static $deleted = array();
628         if (isset($deleted[$key])) return;
629         $vars = &$GLOBALS['HTTP_COOKIE_VARS'];
630         if (!defined('COOKIE_DOMAIN'))
631             @setcookie($key,'',0);
632         @setcookie($key,'',0,defined('COOKIE_DOMAIN') ? COOKIE_DOMAIN : '/');
633         unset($vars[$key]);
634         unset($GLOBALS['HTTP_COOKIE_VARS'][$key]);
635         $deleted[$key] = 1;
636     }
637 }
638
639 /* Win32 Note:
640    [\winnt\php.ini]
641    You must set "upload_tmp_dir" = "/tmp/" or "C:/tmp/"
642    Best on the same drive as apache, with forward slashes 
643    and with ending slash!
644    Otherwise "\\" => "" and the uploaded file will not be found.
645 */
646 class Request_UploadedFile {
647     function getUploadedFile($postname) {
648         global $HTTP_POST_FILES;
649         
650         if (!isset($HTTP_POST_FILES[$postname]))
651             return false;
652         
653         $fileinfo = &$HTTP_POST_FILES[$postname];
654         if ($fileinfo['error']) {
655             // errmsgs by Shilad Sen
656             switch ($HTTP_POST_FILES['userfile']['error']) {
657             case 1:
658                 trigger_error(_("Upload error: file too big"), E_USER_ERROR);
659                 break;
660             case 2:
661                 trigger_error(_("Upload error: file too big"), E_USER_ERROR);
662                 break;
663             case 3:
664                 trigger_error(_("Upload error: file only partially recieved"), E_USER_ERROR);
665                 break;
666             case 4:
667                 trigger_error(_("Upload error: no file selected"), E_USER_ERROR);
668                 break;
669             default:
670                 trigger_error(_("Upload error: unknown error #") . $fileinfo['error'], E_USER_ERROR);
671                 break;
672             }
673             return false;
674         }
675
676         // With windows/php 4.2.1 is_uploaded_file() always returns false.
677         // Be sure that upload_tmp_dir ends with a slash!
678         if (!is_uploaded_file($fileinfo['tmp_name'])) {
679             if (isWindows()) {
680                 if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
681                     $tmp_file = dirname(tempnam('', ''));
682                 }
683                 $tmp_file .= '/' . basename($fileinfo['tmp_name']);
684                 /* but ending slash in php.ini upload_tmp_dir is required. */
685                 if (ereg_replace('/+', '/', $tmp_file) != $fileinfo['tmp_name']) {
686                     trigger_error(sprintf("Uploaded tmpfile illegal: %s != %s.",$tmp_file, $fileinfo['tmp_name']).
687                                   "\n".
688                                   "Probably illegal TEMP environment or upload_tmp_dir setting.",
689                                   E_USER_ERROR);
690                     return false;
691                 } else {
692                     /*
693                     trigger_error(sprintf("Workaround for PHP/Windows is_uploaded_file() problem for %s.",
694                                           $fileinfo['tmp_name'])."\n".
695                                   "Probably illegal TEMP environment or upload_tmp_dir setting.", 
696                                   E_USER_NOTICE);
697                     */
698                     ;
699                 }
700             } else {
701               trigger_error(sprintf("Uploaded tmpfile %s not found.",$fileinfo['tmp_name'])."\n".
702                            " Probably illegal TEMP environment or upload_tmp_dir setting.",
703                           E_USER_WARNING);
704             }
705         }
706         return new Request_UploadedFile($fileinfo);
707     }
708     
709     function Request_UploadedFile($fileinfo) {
710         $this->_info = $fileinfo;
711     }
712
713     function getSize() {
714         return $this->_info['size'];
715     }
716
717     function getName() {
718         return $this->_info['name'];
719     }
720
721     function getType() {
722         return $this->_info['type'];
723     }
724
725     function getTmpName() {
726         return $this->_info['tmp_name'];
727     }
728
729     function open() {
730         if ( ($fd = fopen($this->_info['tmp_name'], "rb")) ) {
731             if ($this->getSize() < filesize($this->_info['tmp_name'])) {
732                 // FIXME: Some PHP's (or is it some browsers?) put
733                 //    HTTP/MIME headers in the file body, some don't.
734                 //
735                 // At least, I think that's the case.  I know I used
736                 // to need this code, now I don't.
737                 //
738                 // This code is more-or-less untested currently.
739                 //
740                 // Dump HTTP headers.
741                 while ( ($header = fgets($fd, 4096)) ) {
742                     if (trim($header) == '') {
743                         break;
744                     }
745                     else if (!preg_match('/^content-(length|type):/i', $header)) {
746                         rewind($fd);
747                         break;
748                     }
749                 }
750             }
751         }
752         return $fd;
753     }
754
755     function getContents() {
756         $fd = $this->open();
757         $data = fread($fd, $this->getSize());
758         fclose($fd);
759         return $data;
760     }
761 }
762
763 /**
764  * Create NCSA "combined" log entry for current request.
765  * Also needed for advanced spam prevention.
766  * global object holding global state (sql or file, entries, to dump)
767  */
768 class Request_AccessLog {
769     /**
770      * @param $logfile string  Log file name.
771      */
772     function Request_AccessLog ($logfile, $do_sql = false) {
773         //global $request; // request not yet initialized!
774
775         $this->logfile = $logfile;
776         if ($logfile and !is_writeable($logfile)) {
777             trigger_error
778                 (sprintf(_("%s is not writable."), _("The PhpWiki access log file"))
779                  . "\n"
780                  . sprintf(_("Please ensure that %s is writable, or redefine %s in config/config.ini."),
781                            sprintf(_("the file '%s'"), ACCESS_LOG),
782                            'ACCESS_LOG')
783                  , E_USER_NOTICE);
784         }
785         //$request->_accesslog =& $this;
786         //if (empty($request->_accesslog->entries))
787         register_shutdown_function("Request_AccessLogEntry_shutdown_function");
788         
789         if ($do_sql) {
790             global $DBParams;
791             if (!in_array($DBParams['dbtype'], array('SQL','ADODB'))) {
792                 trigger_error("Unsupported database backend for ACCESS_LOG_SQL.\nNeed DATABASE_TYPE=SQL or ADODB");
793             } else {
794                 //$this->_dbi =& $request->_dbi;
795                 $this->logtable = (!empty($DBParams['prefix']) ? $DBParams['prefix'] : '')."accesslog";
796             }
797         }
798         $this->entries = array();
799         $this->entries[] = & new Request_AccessLogEntry($this);
800     }
801
802     function _do($cmd, &$arg) {
803         if ($this->entries)
804             for ($i=0; $i < count($this->entries);$i++)
805                 $this->entries[$i]->$cmd($arg);
806     }
807     function push(&$request)   { $this->_do('push',$request); }
808     function setSize($arg)     { $this->_do('setSize',$arg); }
809     function setStatus($arg)   { $this->_do('setStatus',$arg); }
810     function setDuration($arg) { $this->_do('setDuration',$arg); }
811
812     /**
813      * Read sequentially all previous entries from the beginning.
814      * while ($logentry = Request_AccessLogEntry::read()) ;
815      * For internal log analyzers: RecentReferrers, WikiAccessRestrictions
816      */
817     function read() {
818         return $this->logtable ? $this->read_sql() : $this->read_file();
819     }
820
821     /**
822      * Return iterator of referer items reverse sorted (latest first).
823      */
824     function get_referer($limit=15, $external_only=false) {
825         if ($external_only) { // see stdlin.php:isExternalReferrer()
826             $base = SERVER_URL;
827             $blen = strlen($base);
828         }
829         if (!empty($this->_dbi)) {
830             // check same hosts in referer and request and remove them
831             $ext_where = " AND LEFT(referer,$blen) <> ".$this->_dbi->quote($base)
832                 ." AND LEFT(referer,$blen) <> LEFT(CONCAT(".$this->_dbi->quote(SERVER_URL).",request_uri),$blen)";
833             return $this->_read_sql_query("(referer <>'' AND NOT(ISNULL(referer)))"
834                                           .($external_only ? $ext_where : '')
835                                           ." ORDER BY time_stamp DESC"
836                                           .($limit ? " LIMIT $limit" : ""));
837         } else {
838             $iter = new WikiDB_Array_generic_iter(0);
839             $logs =& $iter->_array;
840             while ($logentry = $this->read_file()) {
841                 if (!empty($logentry->referer)
842                     and (!$external_only or (substr($logentry->referer,0,$blen) != $base)))
843                 {
844                     $iter->_array[] = $logentry;
845                     if ($limit and count($logs) > $limit)
846                         array_shift($logs);
847                 }
848             }
849             $logs = array_reverse($logs);
850             $logs = array_slice($logs,0,min($limit,count($logs)));
851             return $iter;
852         }
853     }
854
855     /**
856      * Return iterator of matching host items reverse sorted (latest first).
857      */
858     function get_host($host, $since_minutes=20) {
859         if ($this->logtable) {
860             // mysql specific only:
861             return $this->read_sql("request_host=".$this->_dbi->quote($host)." AND time_stamp > ". (time()-$since_minutes*60) 
862                             ." ORDER BY time_stamp DESC");
863         } else {
864             $iter = new WikiDB_Array_generic_iter();
865             $logs =& $iter->_array;
866             $logentry = new Request_AccessLogEntry($this);
867             while ($logentry->read_file()) {
868                 if (!empty($logentry->referer)) {
869                     $iter->_array[] = $logentry;
870                     if ($limit and count($logs) > $limit)
871                         array_shift($logs);
872                     $logentry = new Request_AccessLogEntry($this);
873                 }
874             }
875             $logs = array_reverse($logs);
876             $logs = array_slice($logs,0,min($limit,count($logs)));
877             return $iter;
878         }
879     }
880
881     /**
882      * Read sequentially all previous entries from log file.
883      */
884     function read_file() {
885         global $request;
886         if ($this->logfile) $this->logfile = ACCESS_LOG; // support Request_AccessLog::read
887
888         if (empty($this->reader))       // start at the beginning
889             $this->reader = fopen($this->logfile, "r");
890         if ($s = fgets($this->reader)) {
891             $entry = new Request_AccessLogEntry($this);
892             if (preg_match('/^(\S+)\s(\S+)\s(\S+)\s\[(.+?)\] "([^"]+)" (\d+) (\d+) "([^"]*)" "([^"]*)"$/',$s,$m)) {
893                 list(,$entry->host, $entry->ident, $entry->user, $entry->time,
894                      $entry->request, $entry->status, $entry->size,
895                      $entry->referer, $entry->user_agent) = $m;
896             }
897             return $entry;
898         } else { // until the end
899             fclose($this->reader);
900             return false;
901         }
902     }
903     function _read_sql_query($where='') {
904         $dbh =& $GLOBALS['request']->_dbi;
905         $log_tbl =& $this->logtable;
906         return $dbh->genericSqlIter("SELECT *,request_uri as request,request_time as time,remote_user as user,"
907                                     ."remote_host as host,agent as user_agent"
908                                     ." FROM $log_tbl"
909                                     . ($where ? " WHERE $where" : ""));
910     }
911     function read_sql($where='') {
912         if (empty($this->sqliter))
913             $this->sqliter = $this->_read_sql_query($where);
914         return $this->sqliter->next();
915     }
916
917     /* done in request->finish() before the db is closed */
918     function write_sql() {
919         $dbh =& $GLOBALS['request']->_dbi;
920         if (isset($this->entries) and $dbh and $dbh->isOpen())
921             foreach ($this->entries as $entry) {
922                 $entry->write_sql();
923             }
924     }
925     /* done in the shutdown callback */
926     function write_file() {
927         if (isset($this->entries) and $this->logfile)
928             foreach ($this->entries as $entry) {
929                 $entry->write_file();
930             }
931         unset($this->entries);
932     }
933     /* in an ideal world... */
934     function write() {
935         if ($this->logfile) $this->write_file();
936         if ($this->logtable) $this->write_sql();
937         unset($this->entries);
938     }
939 }
940
941 class Request_AccessLogEntry
942 {
943     /**
944      * Constructor.
945      *
946      * The log entry will be automatically appended to the log file or 
947      * SQL table when the current request terminates.
948      *
949      * If you want to modify a Request_AccessLogEntry before it gets
950      * written (e.g. via the setStatus and setSize methods) you should
951      * use an '&' on the constructor, so that you're working with the
952      * original (rather than a copy) object.
953      *
954      * <pre>
955      *    $log_entry = & new Request_AccessLogEntry("/tmp/wiki_access_log");
956      *    $log_entry->setStatus(401);
957      *    $log_entry->push($request);
958      * </pre>
959      *
960      *
961      */
962     function Request_AccessLogEntry (&$accesslog) {
963         $this->_accesslog = $accesslog;
964         $this->logfile = $accesslog->logfile;
965         $this->time = time();
966         $this->status = 200;    // see setStatus()
967         $this->size = 0;        // see setSize()
968     }
969
970     /**
971      * @param $request object  Request object for current request.
972      */
973     function push(&$request) {
974         $this->host  = $request->get('REMOTE_HOST');
975         $this->ident = $request->get('REMOTE_IDENT');
976         if (!$this->ident)
977             $this->ident = '-';
978         $user = $request->getUser();
979         if ($user->isAuthenticated())
980             $this->user = $user->UserName();
981         else
982             $this->user = '-';
983         $this->request = join(' ', array($request->get('REQUEST_METHOD'),
984                                          $request->get('REQUEST_URI'),
985                                          $request->get('SERVER_PROTOCOL')));
986         $this->referer = (string) $request->get('HTTP_REFERER');
987         $this->user_agent = (string) $request->get('HTTP_USER_AGENT');
988     }
989
990     /**
991      * Set result status code.
992      *
993      * @param $status integer  HTTP status code.
994      */
995     function setStatus ($status) {
996         $this->status = $status;
997     }
998     
999     /**
1000      * Set response size.
1001      *
1002      * @param $size integer
1003      */
1004     function setSize ($size=0) {
1005         $this->size = $size;
1006     }
1007     function setDuration ($seconds) {
1008         $this->duration = $seconds;
1009     }
1010     
1011     /**
1012      * Get time zone offset.
1013      *
1014      * This is a static member function.
1015      *
1016      * @param $time integer Unix timestamp (defaults to current time).
1017      * @return string Zone offset, e.g. "-0800" for PST.
1018      */
1019     function _zone_offset ($time = false) {
1020         if (!$time)
1021             $time = time();
1022         $offset = date("Z", $time);
1023         $negoffset = "";
1024         if ($offset < 0) {
1025             $negoffset = "-";
1026             $offset = -$offset;
1027         }
1028         $offhours = floor($offset / 3600);
1029         $offmins  = $offset / 60 - $offhours * 60;
1030         return sprintf("%s%02d%02d", $negoffset, $offhours, $offmins);
1031     }
1032
1033     /**
1034      * Format time in NCSA format.
1035      *
1036      * This is a static member function.
1037      *
1038      * @param $time integer Unix timestamp (defaults to current time).
1039      * @return string Formatted date & time.
1040      */
1041     function _ncsa_time($time = false) {
1042         if (!$time)
1043             $time = time();
1044         return date("d/M/Y:H:i:s", $time) .
1045             " " . $this->_zone_offset();
1046     }
1047
1048     function write() {
1049         if ($this->_accesslog->logfile) $this->write_file();
1050         if ($this->_accesslog->logtable) $this->write_sql();
1051     }
1052
1053     /**
1054      * Write entry to log file.
1055      */
1056     function write_file() {
1057         $entry = sprintf('%s %s %s [%s] "%s" %d %d "%s" "%s"',
1058                          $this->host, $this->ident, $this->user,
1059                          $this->_ncsa_time($this->time),
1060                          $this->request, $this->status, $this->size,
1061                          $this->referer, $this->user_agent);
1062         if (!empty($this->_accesslog->reader)) {
1063             fclose($this->_accesslog->reader);
1064             unset($this->_accesslog->reader);
1065         }
1066         //Error log doesn't provide locking.
1067         //error_log("$entry\n", 3, $this->logfile);
1068         // Alternate method
1069         if (($fp = fopen($this->logfile, "a"))) {
1070             flock($fp, LOCK_EX);
1071             fputs($fp, "$entry\n");
1072             fclose($fp);
1073         }
1074     }
1075
1076     /* This is better been done by apache mod_log_sql */
1077     /* If ACCESS_LOG_SQL & 2 we do write it by our own */
1078     function write_sql() {
1079         $dbh =& $GLOBALS['request']->_dbi;
1080         if ($dbh and $dbh->isOpen() and $this->_accesslog->logtable) {
1081             $log_tbl =& $this->_accesslog->logtable;
1082             if ($GLOBALS['request']->get('REQUEST_METHOD') == "POST") {
1083                 if (check_php_version(4,2))
1084                   // strangely HTTP_POST_VARS doesn't contain all posted vars.
1085                   $this->request_args = substr(serialize($_POST),0,254); // if VARCHAR(255) is used.
1086                 else
1087                   $this->request_args = substr(serialize($GLOBALS['HTTP_POST_VARS']),0,254);
1088             } else { 
1089                 $this->request_args = $GLOBALS['request']->get('QUERY_STRING'); 
1090             }
1091             $dbh->genericSqlQuery
1092                 (
1093                  sprintf("INSERT DELAYED INTO $log_tbl"
1094                          . " (time_stamp,remote_host,remote_user,request_method,request_line,request_uri,"
1095                          .   "request_args,request_time,status,bytes_sent,referer,agent,request_duration)"
1096                          . " VALUES(%d,%s,%s,%s,%s,%s,%s,%s,%d,%d,%s,%s,%f)",
1097                      $this->time,
1098                      $dbh->quote($this->host), $dbh->quote($this->user),
1099                      $dbh->quote($GLOBALS['request']->get('REQUEST_METHOD')), $dbh->quote($this->request), 
1100                      $dbh->quote($GLOBALS['request']->get('REQUEST_URI')), $dbh->quote($this->request_args),
1101                      $dbh->quote($this->_ncsa_time($this->time)), $this->status, $this->size,
1102                      $dbh->quote($this->referer),
1103                      $dbh->quote($this->user_agent),
1104                      $this->duration));
1105         }
1106     }
1107
1108 }
1109
1110 /**
1111  * Shutdown callback.
1112  *
1113  * @access private
1114  * @see Request_AccessLogEntry
1115  */
1116 function Request_AccessLogEntry_shutdown_function () {
1117     global $request;
1118     
1119     if (isset($request->_accesslog->entries) and $request->_accesslog->logfile)
1120       foreach ($request->_accesslog->entries as $entry) {
1121           $entry->write_file();
1122       }
1123     unset($request->_accesslog->entries);
1124 }
1125
1126
1127 class HTTP_ETag {
1128     function HTTP_ETag($val, $is_weak=false) {
1129         $this->_val = hash($val);
1130         $this->_weak = $is_weak;
1131     }
1132
1133     /** Comparison
1134      *
1135      * Strong comparison: If either (or both) tag is weak, they
1136      *  are not equal.
1137      */
1138     function equals($that, $strong_match=false) {
1139         if ($this->_val != $that->_val)
1140             return false;
1141         if ($strong_match and ($this->_weak or $that->_weak))
1142             return false;
1143         return true;
1144     }
1145
1146
1147     function asString() {
1148         $quoted = '"' . addslashes($this->_val) . '"';
1149         return $this->_weak ? "W/$quoted" : $quoted;
1150     }
1151
1152     /** Parse tag from header.
1153      *
1154      * This is a static member function.
1155      */
1156     function parse($strval) {
1157         if (!preg_match(':^(W/)?"(.+)"$:i', trim($strval), $m))
1158             return false;       // parse failed
1159         list(,$weak,$str) = $m;
1160         return new HTTP_ETag(stripslashes($str), $weak);
1161     }
1162
1163     function matches($taglist, $strong_match=false) {
1164         $taglist = trim($taglist);
1165
1166         if ($taglist == '*') {
1167             if ($strong_match)
1168                 return ! $this->_weak;
1169             else
1170                 return true;
1171         }
1172
1173         while (preg_match('@^(W/)?"((?:\\\\.|[^"])*)"\s*,?\s*@i',
1174                           $taglist, $m)) {
1175             list($match, $weak, $str) = $m;
1176             $taglist = substr($taglist, strlen($match));
1177             $tag = new HTTP_ETag(stripslashes($str), $weak);
1178             if ($this->equals($tag, $strong_match)) {
1179                 return true;
1180             }
1181         }
1182         return false;
1183     }
1184 }
1185
1186 // Possible results from the HTTP_ValidatorSet::_check*() methods.
1187 // (Higher numerical values take precedence.)
1188 define ('_HTTP_VAL_PASS', 0);           // Test is irrelevant
1189 define ('_HTTP_VAL_NOT_MODIFIED', 1);   // Test passed, content not changed
1190 define ('_HTTP_VAL_MODIFIED', 2);       // Test failed, content changed
1191 define ('_HTTP_VAL_FAILED', 3);         // Precondition failed.
1192
1193 class HTTP_ValidatorSet {
1194     function HTTP_ValidatorSet($validators) {
1195         $this->_mtime = $this->_weak = false;
1196         $this->_tag = array();
1197         
1198         foreach ($validators as $key => $val) {
1199             if ($key == '%mtime') {
1200                 $this->_mtime = $val;
1201             }
1202             elseif ($key == '%weak') {
1203                 if ($val)
1204                     $this->_weak = true;
1205             }
1206             else {
1207                 $this->_tag[$key] = $val;
1208             }
1209         }
1210     }
1211
1212     function append($that) {
1213         if (is_array($that))
1214             $that = new HTTP_ValidatorSet($that);
1215
1216         // Pick the most recent mtime
1217         if (isset($that->_mtime))
1218             if (!isset($this->_mtime) || $that->_mtime > $this->_mtime)
1219                 $this->_mtime = $that->_mtime;
1220
1221         // If either is weak, we're weak
1222         if (!empty($that->_weak))
1223             $this->_weak = true;
1224         if (is_array($this->_tag))
1225             $this->_tag = array_merge($this->_tag, $that->_tag);
1226         else
1227             $this->_tag = $that->_tag;
1228     }
1229
1230     function getETag() {
1231         if (! $this->_tag)
1232             return false;
1233         return new HTTP_ETag($this->_tag, $this->_weak);
1234     }
1235
1236     function getModificationTime() {
1237         return $this->_mtime;
1238     }
1239     
1240     function checkConditionalRequest (&$request) {
1241         $result = max($this->_checkIfUnmodifiedSince($request),
1242                       $this->_checkIfModifiedSince($request),
1243                       $this->_checkIfMatch($request),
1244                       $this->_checkIfNoneMatch($request));
1245
1246         if ($result == _HTTP_VAL_PASS || $result == _HTTP_VAL_MODIFIED)
1247             return false;       // "please proceed with normal processing"
1248         elseif ($result == _HTTP_VAL_FAILED)
1249             return 412;         // "412 Precondition Failed"
1250         elseif ($result == _HTTP_VAL_NOT_MODIFIED)
1251             return 304;         // "304 Not Modified"
1252
1253         trigger_error("Ack, shouldn't get here", E_USER_ERROR);
1254         return false;
1255     }
1256
1257     function _checkIfUnmodifiedSince(&$request) {
1258         if ($this->_mtime !== false) {
1259             $since = ParseRfc1123DateTime($request->get("HTTP_IF_UNMODIFIED_SINCE"));
1260             if ($since !== false && $this->_mtime > $since)
1261                 return _HTTP_VAL_FAILED;
1262         }
1263         return _HTTP_VAL_PASS;
1264     }
1265
1266     function _checkIfModifiedSince(&$request) {
1267         if ($this->_mtime !== false and $request->isGetOrHead()) {
1268             $since = ParseRfc1123DateTime($request->get("HTTP_IF_MODIFIED_SINCE"));
1269             if ($since !== false) {
1270                 if ($this->_mtime <= $since)
1271                     return _HTTP_VAL_NOT_MODIFIED;
1272                 return _HTTP_VAL_MODIFIED;
1273             }
1274         }
1275         return _HTTP_VAL_PASS;
1276     }
1277
1278     function _checkIfMatch(&$request) {
1279         if ($this->_tag && ($taglist = $request->get("HTTP_IF_MATCH"))) {
1280             $tag = $this->getETag();
1281             if (!$tag->matches($taglist, 'strong'))
1282                 return _HTTP_VAL_FAILED;
1283         }
1284         return _HTTP_VAL_PASS;
1285     }
1286
1287     function _checkIfNoneMatch(&$request) {
1288         if ($this->_tag && ($taglist = $request->get("HTTP_IF_NONE_MATCH"))) {
1289             $tag = $this->getETag();
1290             $strong_compare = ! $request->isGetOrHead();
1291             if ($taglist) {
1292                 if ($tag->matches($taglist, $strong_compare)) {
1293                     if ($request->isGetOrHead())
1294                         return _HTTP_VAL_NOT_MODIFIED;
1295                     else
1296                         return _HTTP_VAL_FAILED;
1297                 }
1298                 return _HTTP_VAL_MODIFIED;
1299             }
1300         }
1301         return _HTTP_VAL_PASS;
1302     }
1303 }
1304
1305
1306 // $Log: not supported by cvs2svn $
1307 // Revision 1.81  2004/11/27 14:39:04  rurban
1308 // simpified regex search architecture:
1309 //   no db specific node methods anymore,
1310 //   new sql() method for each node
1311 //   parallel to regexp() (which returns pcre)
1312 //   regex types bitmasked (op's not yet)
1313 // new regex=sql
1314 // clarified WikiDB::quote() backend methods:
1315 //   ->quote() adds surrounsing quotes
1316 //   ->qstr() (new method) assumes strings and adds no quotes! (in contrast to ADODB)
1317 //   pear and adodb have now unified quote methods for all generic queries.
1318 //
1319 // Revision 1.80  2004/11/21 11:59:16  rurban
1320 // remove final \n to be ob_cache independent
1321 //
1322 // Revision 1.79  2004/11/11 18:29:44  rurban
1323 // (write_sql) isOpen really is useless in non-SQL, do more explicit check
1324 //
1325 // Revision 1.78  2004/11/10 15:29:20  rurban
1326 // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
1327 // * ACCESS_LOG_SQL: fix cause request not yet initialized
1328 // * WikiDB: moved SQL specific methods upwards
1329 // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
1330 //   fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
1331 //
1332 // Revision 1.77  2004/11/09 17:11:04  rurban
1333 // * revert to the wikidb ref passing. there's no memory abuse there.
1334 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
1335 //   store page ids with getPageLinks (GleanDescription) of all existing pages, which
1336 //   are also needed at the rendering for linkExistingWikiWord().
1337 //   pass options to pageiterator.
1338 //   use this cache also for _get_pageid()
1339 //   This saves about 8 SELECT count per page (num all pagelinks).
1340 // * fix passing of all page fields to the pageiterator.
1341 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
1342 //
1343 // Revision 1.76  2004/11/09 08:15:18  rurban
1344 // fix ADODB quoting style
1345 //
1346 // Revision 1.75  2004/11/07 18:34:28  rurban
1347 // more logging fixes
1348 //
1349 // Revision 1.74  2004/11/07 16:02:51  rurban
1350 // new sql access log (for spam prevention), and restructured access log class
1351 // dbh->quote (generic)
1352 // pear_db: mysql specific parts seperated (using replace)
1353 //
1354 // Revision 1.73  2004/11/06 04:51:25  rurban
1355 // readable ACCESS_LOG support: RecentReferrers, WikiAccessRestrictions
1356 //
1357 // Revision 1.72  2004/11/01 10:43:55  rurban
1358 // seperate PassUser methods into seperate dir (memory usage)
1359 // fix WikiUser (old) overlarge data session
1360 // remove wikidb arg from various page class methods, use global ->_dbi instead
1361 // ...
1362 //
1363 // Revision 1.71  2004/10/22 09:20:36  rurban
1364 // fix for USECACHE=false
1365 //
1366 // Revision 1.70  2004/10/21 19:59:18  rurban
1367 // Patch #991494 (ppo): Avoid notice in PHP >= 4.3.3 if session already started
1368 //
1369 // Revision 1.69  2004/10/21 19:00:37  rurban
1370 // upload errmsgs by Shilad Sen.
1371 // chunkOutput support: flush the buffer piecewise (dumphtml, large pagelists)
1372 //   doesn't gain much because ob_end_clean() doesn't release its
1373 //   memory properly yet.
1374 //
1375 // Revision 1.68  2004/10/12 13:13:19  rurban
1376 // php5 compatibility (5.0.1 ok)
1377 //
1378 // Revision 1.67  2004/09/25 18:56:54  rurban
1379 // make start_debug logic work
1380 //
1381 // Revision 1.66  2004/09/25 16:24:52  rurban
1382 // dont compress on debugging
1383 //
1384 // Revision 1.65  2004/09/17 14:13:49  rurban
1385 // We check for the client Accept-Encoding: "gzip" presence also
1386 // This should eliminate a lot or reported problems.
1387 //
1388 // Note that this doesn#t fix RSS ssues:
1389 // Most RSS clients are NOT(!) application/xml gzip compatible yet.
1390 // Even if they are sending the accept-encoding gzip header!
1391 // wget is, Mozilla, and MSIE no.
1392 // Of the RSS readers only MagpieRSS 0.5.2 is. http://www.rssgov.com/rssparsers.html
1393 //
1394 // Revision 1.64  2004/09/17 13:32:36  rurban
1395 // Disable server-side gzip encoding for RSS (RDF encoding), even if the client says it
1396 // supports it. Mozilla has this error, wget works fine. IE not checked.
1397 //
1398 // Revision 1.63  2004/07/01 09:29:40  rurban
1399 // fixed another DbSession crash: wrong WikiGroup vars
1400 //
1401 // Revision 1.62  2004/06/27 10:26:02  rurban
1402 // oci8 patch by Philippe Vanhaesendonck + some ADODB notes+fixes
1403 //
1404 // Revision 1.61  2004/06/25 14:29:17  rurban
1405 // WikiGroup refactoring:
1406 //   global group attached to user, code for not_current user.
1407 //   improved helpers for special groups (avoid double invocations)
1408 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
1409 // fixed a XHTML validation error on userprefs.tmpl
1410 //
1411 // Revision 1.60  2004/06/19 11:51:13  rurban
1412 // CACHE_CONTROL: NONE => NO_CACHE
1413 //
1414 // Revision 1.59  2004/06/13 11:34:22  rurban
1415 // fixed bug #969532 (space in uploaded filenames)
1416 // improved upload error messages
1417 //
1418 // Revision 1.58  2004/06/04 20:32:53  rurban
1419 // Several locale related improvements suggested by Pierrick Meignen
1420 // LDAP fix by John Cole
1421 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
1422 //
1423 // Revision 1.57  2004/06/03 18:54:25  rurban
1424 // fixed "lost level in session" warning, now that signout sets level = 0 (before -1)
1425 //
1426 // Revision 1.56  2004/05/17 17:43:29  rurban
1427 // CGI: no PATH_INFO fix
1428 //
1429 // Revision 1.55  2004/05/15 18:31:00  rurban
1430 // some action=pdf Request fixes: With MSIE it works now. Now the work with the page formatting begins.
1431 //
1432 // Revision 1.54  2004/05/04 22:34:25  rurban
1433 // more pdf support
1434 //
1435 // Revision 1.53  2004/05/03 21:57:47  rurban
1436 // locale updates: we previously lost some words because of wrong strings in
1437 //   PhotoAlbum, german rewording.
1438 // fixed $_SESSION registering (lost session vars, esp. prefs)
1439 // fixed ending slash in listAvailableLanguages/Themes
1440 //
1441 // Revision 1.52  2004/05/03 13:16:47  rurban
1442 // fixed UserPreferences update, esp for boolean and int
1443 //
1444 // Revision 1.51  2004/05/02 21:26:38  rurban
1445 // limit user session data (HomePageHandle and auth_dbi have to invalidated anyway)
1446 //   because they will not survive db sessions, if too large.
1447 // extended action=upgrade
1448 // some WikiTranslation button work
1449 // revert WIKIAUTH_UNOBTAINABLE (need it for main.php)
1450 // some temp. session debug statements
1451 //
1452 // Revision 1.50  2004/04/29 19:39:44  rurban
1453 // special support for formatted plugins (one-liners)
1454 //   like <small><plugin BlaBla ></small>
1455 // iter->asArray() helper for PopularNearby
1456 // db_session for older php's (no &func() allowed)
1457 //
1458 // Revision 1.49  2004/04/26 20:44:34  rurban
1459 // locking table specific for better databases
1460 //
1461 // Revision 1.48  2004/04/13 09:13:50  rurban
1462 // sf.net bug #933183 and http://bugs.php.net/17557
1463 // disable ob_gzhandler if apache_note cannot be used.
1464 //   (conservative until we find why)
1465 //
1466 // Revision 1.47  2004/04/02 15:06:55  rurban
1467 // fixed a nasty ADODB_mysql session update bug
1468 // improved UserPreferences layout (tabled hints)
1469 // fixed UserPreferences auth handling
1470 // improved auth stability
1471 // improved old cookie handling: fixed deletion of old cookies with paths
1472 //
1473 // Revision 1.46  2004/03/30 02:14:03  rurban
1474 // fixed yet another Prefs bug
1475 // added generic PearDb_iter
1476 // $request->appendValidators no so strict as before
1477 // added some box plugin methods
1478 // PageList commalist for condensed output
1479 //
1480 // Revision 1.45  2004/03/24 19:39:02  rurban
1481 // php5 workaround code (plus some interim debugging code in XmlElement)
1482 //   php5 doesn't work yet with the current XmlElement class constructors,
1483 //   WikiUserNew does work better than php4.
1484 // rewrote WikiUserNew user upgrading to ease php5 update
1485 // fixed pref handling in WikiUserNew
1486 // added Email Notification
1487 // added simple Email verification
1488 // removed emailVerify userpref subclass: just a email property
1489 // changed pref binary storage layout: numarray => hash of non default values
1490 // print optimize message only if really done.
1491 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1492 //   prefs should be stored in db or homepage, besides the current session.
1493 //
1494 // Revision 1.44  2004/03/14 16:26:22  rurban
1495 // copyright line
1496 //
1497 // Revision 1.43  2004/03/12 20:59:17  rurban
1498 // important cookie fix by Konstantin Zadorozhny
1499 // new editpage feature: JS_SEARCHREPLACE
1500 //
1501 // Revision 1.42  2004/03/10 15:38:48  rurban
1502 // store current user->page and ->action in session for WhoIsOnline
1503 // better WhoIsOnline icon
1504 // fixed WhoIsOnline warnings
1505 //
1506 // Revision 1.41  2004/02/27 01:25:14  rurban
1507 // Workarounds for upload handling
1508 //
1509 // Revision 1.40  2004/02/26 01:39:51  rurban
1510 // safer code
1511 //
1512 // Revision 1.39  2004/02/24 15:14:57  rurban
1513 // fixed action=upload problems on Win32, and remove Merge Edit buttons: file does not exist anymore
1514 //
1515 // Revision 1.38  2004/01/25 10:26:02  rurban
1516 // fixed bug [ 541193 ] HTTP_SERVER_VARS are Apache specific
1517 // http://sourceforge.net/tracker/index.php?func=detail&aid=541193&group_id=6121&atid=106121
1518 // CGI and other servers than apache populate _ENV and not _SERVER
1519 //
1520 // Revision 1.37  2003/12/26 06:41:16  carstenklapp
1521 // Bugfix: Try to defer OS errors about session.save_path and ACCESS_LOG,
1522 // so they don't prevent IE from partially (or not at all) rendering the
1523 // page. This should help a little for the IE user who encounters trouble
1524 // when setting up a new PhpWiki for the first time.
1525 //
1526
1527 // Local Variables:
1528 // mode: php
1529 // tab-width: 8
1530 // c-basic-offset: 4
1531 // c-hanging-comment-ender-p: nil
1532 // indent-tabs-mode: nil
1533 // End:   
1534 ?>