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