4 * Things which must be done and defined before anything else.
7 function rcs_id ($id) {
9 if (defined('DEBUG') and DEBUG)
10 $GLOBALS['RCS_IDS'] .= "$id\n";
12 rcs_id('$Id: prepend.php,v 1.67 2008-03-17 19:42:36 rurban Exp $');
14 // see lib/stdlib.php: phpwiki_version()
15 define('PHPWIKI_VERSION', '1.3.14-20080124');
18 * Returns true if current php version is at mimimum a.b.c
19 * Called: check_php_version(4,1)
21 function check_php_version ($a = '0', $b = '0', $c = '0') {
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));
28 /** PHP5 deprecated old-style globals if !(bool)ini_get('register_long_arrays').
30 * We want to work with those old ones instead of the new superglobals,
34 foreach (array('SERVER','REQUEST','GET','POST','SESSION','ENV','COOKIE') as $k) {
35 if (!isset($GLOBALS['HTTP_'.$k.'_VARS']) and isset($GLOBALS['_'.$k])) {
36 $GLOBALS['HTTP_'.$k.'_VARS'] =& $GLOBALS['_'.$k];
40 // A new php-5.1.x feature: Turn off php-5.1.x auto_globals_jit = On, or use this mess below.
41 if (empty($GLOBALS['HTTP_SERVER_VARS'])) {
42 $GLOBALS['HTTP_SERVER_VARS'] =& $_SERVER;
43 $GLOBALS['HTTP_ENV_VARS'] =& $_ENV;
44 $GLOBALS['HTTP_GET_VARS'] =& $_GET;
45 $GLOBALS['HTTP_POST_VARS'] =& $_POST;
46 $GLOBALS['HTTP_SESSION_VARS'] =& $_SESSION;
47 $GLOBALS['HTTP_COOKIE_VARS'] =& $_COOKIE;
48 $GLOBALS['HTTP_REQUEST_VARS'] =& $_REQUEST;
51 // catch connection failures on upgrade
52 if (isset($GLOBALS['HTTP_GET_VARS']['action'])
53 and $GLOBALS['HTTP_GET_VARS']['action'] == 'upgrade')
54 define('ADODB_ERROR_HANDLER_TYPE', E_USER_WARNING);
56 // If your php was compiled with --enable-trans-sid it tries to
57 // add a PHPSESSID query argument to all URL strings when cookie
58 // support isn't detected in the client browser. For reasons
59 // which aren't entirely clear (PHP bug) this screws up the URLs
60 // generated by PhpWiki. Therefore, transparent session ids
61 // should be disabled. This next line does that.
63 // (At the present time, you will not be able to log-in to PhpWiki,
64 // unless your browser supports cookies.)
65 @ini_set('session.use_trans_sid', 0);
67 if (defined('DEBUG') and (DEBUG & 8) and extension_loaded("xdebug")) {
68 xdebug_start_trace("trace"); // on Dbgp protocol add 2
71 if (defined('DEBUG') and (DEBUG & 32) and extension_loaded("apd")) {
72 apd_set_pprof_trace();
80 //apd_set_session_trace(99);
83 // Used for debugging purposes
85 function DebugTimer() {
86 $this->_start = $this->microtime();
87 if (function_exists('posix_times'))
88 $this->_times = posix_times();
92 * @param string $which One of 'real', 'utime', 'stime', 'cutime', 'sutime'
93 * @return float Seconds.
95 function getTime($which='real', $now=false) {
97 return $this->microtime() - $this->_start;
99 if (isset($this->_times)) {
100 if (!$now) $now = posix_times();
101 $ticks = $now[$which] - $this->_times[$which];
102 return $ticks / $this->_CLK_TCK();
105 return 0.0; // Not available.
108 function getStats() {
109 if (!isset($this->_times)) {
110 // posix_times() not available.
111 return sprintf("real: %.3f", $this->getTime('real'));
113 $now = posix_times();
114 return sprintf("real: %.3f, user: %.3f, sys: %.3f",
115 $this->getTime('real'),
116 $this->getTime('utime', $now),
117 $this->getTime('stime', $now));
120 function _CLK_TCK() {
121 // FIXME: this is clearly not always right.
122 // But how to figure out the right value?
126 function microtime(){
127 list($usec, $sec) = explode(" ", microtime());
128 return ((float)$usec + (float)$sec);
131 $RUNTIMER = new DebugTimer;
133 if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
134 error_reporting(E_ALL & ~E_STRICT); // exclude E_STRICT
136 error_reporting(E_ALL); // php4
137 //echo " prepend: ", error_reporting();
139 require_once(dirname(__FILE__).'/ErrorManager.php');
140 require_once(dirname(__FILE__).'/WikiCallback.php');
143 function ExitWiki($errormsg = false)
148 if (is_object($request) and method_exists($request,"finish"))
149 $request->finish($errormsg); // NORETURN
156 global $ErrorManager;
157 $ErrorManager->flushPostponedErrors();
159 if(!empty($errormsg)) {
160 PrintXML(HTML::br(), $errormsg);
161 print "\n</body></html>";
165 if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
166 $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
167 $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
169 $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
173 // (c-file-style: "gnu")
178 // c-hanging-comment-ender-p: nil
179 // indent-tabs-mode: nil