4 * Things which must be done and defined before anything else.
7 // see lib/stdlib.php: phpwiki_version()
8 define('PHPWIKI_VERSION', '1.5.2');
10 /** PHP5 deprecated old-style globals if !(bool)ini_get('register_long_arrays').
12 * We want to work with those old ones instead of the new superglobals,
16 foreach (array('SERVER','REQUEST','GET','POST','SESSION','ENV','COOKIE') as $k) {
17 if (!isset($GLOBALS['HTTP_'.$k.'_VARS']) and isset($GLOBALS['_'.$k])) {
18 $GLOBALS['HTTP_'.$k.'_VARS'] =& $GLOBALS['_'.$k];
22 // A new php-5.1.x feature: Turn off php-5.1.x auto_globals_jit = On, or use this mess below.
23 if (empty($GLOBALS['HTTP_SERVER_VARS'])) {
24 $GLOBALS['HTTP_SERVER_VARS'] =& $_SERVER;
25 $GLOBALS['HTTP_ENV_VARS'] =& $_ENV;
26 $GLOBALS['HTTP_GET_VARS'] =& $_GET;
27 $GLOBALS['HTTP_POST_VARS'] =& $_POST;
28 $GLOBALS['HTTP_SESSION_VARS'] =& $_SESSION;
29 $GLOBALS['HTTP_COOKIE_VARS'] =& $_COOKIE;
30 $GLOBALS['HTTP_REQUEST_VARS'] =& $_REQUEST;
33 // catch connection failures on upgrade
34 if (isset($GLOBALS['HTTP_GET_VARS']['action'])
35 and $GLOBALS['HTTP_GET_VARS']['action'] == 'upgrade'
37 define('ADODB_ERROR_HANDLER_TYPE', E_USER_WARNING);
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.
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);
50 if (defined('DEBUG') and (DEBUG & 8) and extension_loaded("xdebug")) {
51 xdebug_start_trace("trace"); // on Dbgp protocol add 2
54 if (defined('DEBUG') and (DEBUG & 32) and extension_loaded("apd")) {
55 apd_set_pprof_trace();
63 //apd_set_session_trace(99);
66 // Used for debugging purposes
71 $this->_start = $this->microtime();
72 // Function 'posix_times' does not exist on Windows
73 if (function_exists('posix_times')) {
74 $this->_times = posix_times();
79 * @param string $which One of 'real', 'utime', 'stime', 'cutime', 'sutime'
81 * @return float Seconds.
83 function getTime($which = 'real', $now = array())
85 if ($which == 'real') {
86 return $this->microtime() - $this->_start;
89 if (isset($this->_times)) {
93 $ticks = $now[$which] - $this->_times[$which];
94 return $ticks / $this->_CLK_TCK();
97 return 0.0; // Not available.
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));
115 // FIXME: this is clearly not always right.
116 // But how to figure out the right value?
122 list($usec, $sec) = explode(" ", microtime());
123 return ((float)$usec + (float)$sec);
127 $RUNTIMER = new DebugTimer;
128 require_once(dirname(__FILE__) . '/ErrorManager.php');
129 require_once(dirname(__FILE__) . '/WikiCallback.php');
132 function ExitWiki($errormsg = false)
137 if (is_object($request) and method_exists($request, "finish"))
138 $request->finish($errormsg); // NORETURN
145 global $ErrorManager;
146 $ErrorManager->flushPostponedErrors();
148 if (!empty($errormsg)) {
149 PrintXML(HTML::br(), $errormsg);
150 print "\n</body></html>";
155 if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
156 $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
157 $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
159 $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
166 // c-hanging-comment-ender-p: nil
167 // indent-tabs-mode: nil