4 * Things which must be done and defined before anything else.
7 // see lib/stdlib.php: phpwiki_version()
8 define('PHPWIKI_VERSION', '1.4.0');
11 * Returns true if current php version is at mimimum a.b.c
12 * Called: check_php_version(5,2)
14 function check_php_version ($a = '0', $b = '0', $c = '0') {
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));
21 /** PHP5 deprecated old-style globals if !(bool)ini_get('register_long_arrays').
23 * We want to work with those old ones instead of the new superglobals,
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];
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;
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);
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.
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);
60 if (defined('DEBUG') and (DEBUG & 8) and extension_loaded("xdebug")) {
61 xdebug_start_trace("trace"); // on Dbgp protocol add 2
64 if (defined('DEBUG') and (DEBUG & 32) and extension_loaded("apd")) {
65 apd_set_pprof_trace();
73 //apd_set_session_trace(99);
76 // Used for debugging purposes
78 function DebugTimer() {
79 $this->_start = $this->microtime();
80 if (function_exists('posix_times'))
81 $this->_times = posix_times();
85 * @param string $which One of 'real', 'utime', 'stime', 'cutime', 'sutime'
86 * @return float Seconds.
88 function getTime($which='real', $now=false) {
90 return $this->microtime() - $this->_start;
92 if (isset($this->_times)) {
93 if (!$now) $now = posix_times();
94 $ticks = $now[$which] - $this->_times[$which];
95 return $ticks / $this->_CLK_TCK();
98 return 0.0; // Not available.
101 function getStats() {
102 if (!isset($this->_times)) {
103 // posix_times() not available.
104 return sprintf("real: %.3f", $this->getTime('real'));
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));
113 function _CLK_TCK() {
114 // FIXME: this is clearly not always right.
115 // But how to figure out the right value?
119 function microtime(){
120 list($usec, $sec) = explode(" ", microtime());
121 return ((float)$usec + (float)$sec);
124 $RUNTIMER = new DebugTimer;
126 if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
127 error_reporting(E_ALL & ~E_STRICT); // exclude E_STRICT
129 error_reporting(E_ALL); // php4
130 //echo " prepend: ", error_reporting();
132 require_once(dirname(__FILE__).'/ErrorManager.php');
133 require_once(dirname(__FILE__).'/WikiCallback.php');
136 function ExitWiki($errormsg = false)
141 if (is_object($request) and method_exists($request,"finish"))
142 $request->finish($errormsg); // NORETURN
149 global $ErrorManager;
150 $ErrorManager->flushPostponedErrors();
152 if(!empty($errormsg)) {
153 PrintXML(HTML::br(), $errormsg);
154 print "\n</body></html>";
158 if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
159 $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
160 $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
162 $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
169 // c-hanging-comment-ender-p: nil
170 // indent-tabs-mode: nil