]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/prepend.php
moved version check forwards: already needed in XmlElement::_quote
[SourceForge/phpwiki.git] / lib / prepend.php
1 <?php
2 /* lib/prepend.php
3  *
4  * Things which must be done and defined before anything else.
5  */
6 $RCS_IDS = '';
7 function rcs_id ($id) { $GLOBALS['RCS_IDS'] .= "$id\n"; }
8 rcs_id('$Id: prepend.php,v 1.21 2004-06-19 11:48:05 rurban Exp $');
9
10 define ('PHPWIKI_VERSION', '1.3.11pre');
11
12 /** 
13  * Returns true if current php version is at mimimum a.b.c 
14  * Called: check_php_version(4,1)
15  */
16 function check_php_version ($a = '0', $b = '0', $c = '0') {
17     static $PHP_VERSION;
18     if (!isset($PHP_VERSION))
19         $PHP_VERSION = substr( str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'), 0, 3);
20     return ($PHP_VERSION >= ($a.$b.$c));
21 }
22
23 // If your php was compiled with --enable-trans-sid it tries to
24 // add a PHPSESSID query argument to all URL strings when cookie
25 // support isn't detected in the client browser.  For reasons
26 // which aren't entirely clear (PHP bug) this screws up the URLs
27 // generated by PhpWiki.  Therefore, transparent session ids
28 // should be disabled.  This next line does that.
29 //
30 // (At the present time, you will not be able to log-in to PhpWiki,
31 // unless your browser supports cookies.)
32 @ini_set('session.use_trans_sid', 0);
33
34
35 // Used for debugging purposes
36 class DebugTimer {
37     function DebugTimer() {
38         $this->_start = $this->microtime();
39         if (function_exists('posix_times'))
40             $this->_times = posix_times();
41     }
42
43     /**
44      * @param string $which  One of 'real', 'utime', 'stime', 'cutime', 'sutime'
45      * @return float Seconds.
46      */
47     function getTime($which='real', $now=false) {
48         if ($which == 'real')
49             return $this->microtime() - $this->_start;
50
51         if (isset($this->_times)) {
52             if (!$now) $now = posix_times();
53             $ticks = $now[$which] - $this->_times[$which];
54             return $ticks / $this->_CLK_TCK();
55         }
56
57         return 0.0;           // Not available.
58     }
59
60     function getStats() {
61         if (!isset($this->_times)) {
62             // posix_times() not available.
63             return sprintf("real: %.3f", $this->getTime('real'));
64         }
65         $now = posix_times();
66         return sprintf("real: %.3f, user: %.3f, sys: %.3f",
67                        $this->getTime('real'),
68                        $this->getTime('utime', $now),
69                        $this->getTime('stime', $now));
70     }
71         
72     function _CLK_TCK() {
73         // FIXME: this is clearly not always right.
74         // But how to figure out the right value?
75         return 100.0;
76     }
77
78     function microtime(){
79         list($usec, $sec) = explode(" ", microtime());
80         return ((float)$usec + (float)$sec);
81     }
82 }
83 $RUNTIMER = new DebugTimer;
84
85 error_reporting(E_ALL);
86 require_once(dirname(__FILE__).'/ErrorManager.php');
87 require_once(dirname(__FILE__).'/WikiCallback.php');
88
89 // FIXME: deprecated
90 function ExitWiki($errormsg = false)
91 {
92     global $request;
93     static $in_exit = 0;
94
95     if (is_object($request))
96         $request->finish($errormsg); // NORETURN
97
98     if ($in_exit)
99         exit;
100     
101     $in_exit = true;
102
103     global $ErrorManager;
104     $ErrorManager->flushPostponedErrors();
105    
106     if(!empty($errormsg)) {
107         PrintXML(HTML::br(), $errormsg);
108         print "\n</body></html>";
109     }
110     exit;
111 }
112 if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
113     $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
114     $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
115 } else {
116     $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
117 }
118
119
120 // (c-file-style: "gnu")
121 // Local Variables:
122 // mode: php
123 // tab-width: 8
124 // c-basic-offset: 4
125 // c-hanging-comment-ender-p: nil
126 // indent-tabs-mode: nil
127 // End:   
128 ?>