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