]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/prepend.php
bump intermediate version
[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.36 2005-05-06 16:51:48 rurban Exp $');
9
10 define('PHPWIKI_VERSION', '1.3.11_20050507');
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 /** PHP5 deprecated old-style globals if !ini_get('register-long-arrays'). 
24   *  See Bug #1180115
25   * We want to work with those old ones instead of the new superglobals, 
26   * for easier coding.
27   */
28 foreach (array('SERVER','REQUEST','GET','POST','SESSION','ENV','COOKIE') as $k) {
29     if (!isset($GLOBALS['HTTP_'.$k.'_VARS']) and isset($GLOBALS['_'.$k]))
30         $GLOBALS['HTTP_'.$k.'_VARS'] =& $GLOBALS['_'.$k];
31 }
32 unset($k);
33
34 // If your php was compiled with --enable-trans-sid it tries to
35 // add a PHPSESSID query argument to all URL strings when cookie
36 // support isn't detected in the client browser.  For reasons
37 // which aren't entirely clear (PHP bug) this screws up the URLs
38 // generated by PhpWiki.  Therefore, transparent session ids
39 // should be disabled.  This next line does that.
40 //
41 // (At the present time, you will not be able to log-in to PhpWiki,
42 // unless your browser supports cookies.)
43 @ini_set('session.use_trans_sid', 0);
44
45 if (defined('DEBUG') and (DEBUG & 8) and extension_loaded("xdebug")) {
46     xdebug_start_trace("trace"); // on Dbgp protocol add 2
47     xdebug_enable();
48 }
49
50 // Used for debugging purposes
51 class DebugTimer {
52     function DebugTimer() {
53         $this->_start = $this->microtime();
54         if (function_exists('posix_times'))
55             $this->_times = posix_times();
56     }
57
58     /**
59      * @param string $which  One of 'real', 'utime', 'stime', 'cutime', 'sutime'
60      * @return float Seconds.
61      */
62     function getTime($which='real', $now=false) {
63         if ($which == 'real')
64             return $this->microtime() - $this->_start;
65
66         if (isset($this->_times)) {
67             if (!$now) $now = posix_times();
68             $ticks = $now[$which] - $this->_times[$which];
69             return $ticks / $this->_CLK_TCK();
70         }
71
72         return 0.0;           // Not available.
73     }
74
75     function getStats() {
76         if (!isset($this->_times)) {
77             // posix_times() not available.
78             return sprintf("real: %.3f", $this->getTime('real'));
79         }
80         $now = posix_times();
81         return sprintf("real: %.3f, user: %.3f, sys: %.3f",
82                        $this->getTime('real'),
83                        $this->getTime('utime', $now),
84                        $this->getTime('stime', $now));
85     }
86         
87     function _CLK_TCK() {
88         // FIXME: this is clearly not always right.
89         // But how to figure out the right value?
90         return 100.0;
91     }
92
93     function microtime(){
94         list($usec, $sec) = explode(" ", microtime());
95         return ((float)$usec + (float)$sec);
96     }
97 }
98 $RUNTIMER = new DebugTimer;
99 /*
100 if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
101     error_reporting(E_ALL & ~E_STRICT);         // exclude E_STRICT
102 else
103     error_reporting(E_ALL); // php4
104 //echo " prepend: ", error_reporting();
105 */
106 require_once(dirname(__FILE__).'/ErrorManager.php');
107 require_once(dirname(__FILE__).'/WikiCallback.php');
108
109 // FIXME: deprecated
110 function ExitWiki($errormsg = false)
111 {
112     global $request;
113     static $in_exit = 0;
114
115     if (is_object($request) and method_exists($request,"finish"))
116         $request->finish($errormsg); // NORETURN
117
118     if ($in_exit)
119         exit;
120     
121     $in_exit = true;
122
123     global $ErrorManager;
124     $ErrorManager->flushPostponedErrors();
125    
126     if(!empty($errormsg)) {
127         PrintXML(HTML::br(), $errormsg);
128         print "\n</body></html>";
129     }
130     exit;
131 }
132 if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
133     $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
134     $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
135 } else {
136     $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
137 }
138
139
140 // (c-file-style: "gnu")
141 // Local Variables:
142 // mode: php
143 // tab-width: 8
144 // c-basic-offset: 4
145 // c-hanging-comment-ender-p: nil
146 // indent-tabs-mode: nil
147 // End:   
148 ?>