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