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