]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/prepend.php
Allow bold, italics or underlined for numbers
[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 {
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 )
49     define('ADODB_ERROR_HANDLER_TYPE', E_USER_WARNING);
50
51 // If your php was compiled with --enable-trans-sid it tries to
52 // add a PHPSESSID query argument to all URL strings when cookie
53 // support isn't detected in the client browser.  For reasons
54 // which aren't entirely clear (PHP bug) this screws up the URLs
55 // generated by PhpWiki.  Therefore, transparent session ids
56 // should be disabled.  This next line does that.
57 //
58 // (At the present time, you will not be able to log-in to PhpWiki,
59 // unless your browser supports cookies.)
60 @ini_set('session.use_trans_sid', 0);
61
62 if (defined('DEBUG') and (DEBUG & 8) and extension_loaded("xdebug")) {
63     xdebug_start_trace("trace"); // on Dbgp protocol add 2
64     xdebug_enable();
65 }
66 if (defined('DEBUG') and (DEBUG & 32) and extension_loaded("apd")) {
67     apd_set_pprof_trace();
68     /*    FUNCTION_TRACE      1
69         ARGS_TRACE          2
70         ASSIGNMENT_TRACE    4
71         STATEMENT_TRACE     8
72         MEMORY_TRACE        16
73         TIMING_TRACE        32
74         SUMMARY_TRACE       64 */
75     //apd_set_session_trace(99);
76 }
77
78 // Used for debugging purposes
79 class DebugTimer
80 {
81     function DebugTimer()
82     {
83         $this->_start = $this->microtime();
84         if (function_exists('posix_times'))
85             $this->_times = posix_times();
86     }
87
88     /**
89      * @param  string $which One of 'real', 'utime', 'stime', 'cutime', 'sutime'
90      * @return float  Seconds.
91      */
92     function getTime($which = 'real', $now = false)
93     {
94         if ($which == 'real')
95             return $this->microtime() - $this->_start;
96
97         if (isset($this->_times)) {
98             if (!$now) $now = posix_times();
99             $ticks = $now[$which] - $this->_times[$which];
100             return $ticks / $this->_CLK_TCK();
101         }
102
103         return 0.0; // Not available.
104     }
105
106     function getStats()
107     {
108         if (!isset($this->_times)) {
109             // posix_times() not available.
110             return sprintf("real: %.3f", $this->getTime('real'));
111         }
112         $now = posix_times();
113         return sprintf("real: %.3f, user: %.3f, sys: %.3f",
114             $this->getTime('real'),
115             $this->getTime('utime', $now),
116             $this->getTime('stime', $now));
117     }
118
119     function _CLK_TCK()
120     {
121         // FIXME: this is clearly not always right.
122         // But how to figure out the right value?
123         return 100.0;
124     }
125
126     function microtime()
127     {
128         list($usec, $sec) = explode(" ", microtime());
129         return ((float)$usec + (float)$sec);
130     }
131 }
132
133 $RUNTIMER = new DebugTimer;
134 require_once(dirname(__FILE__) . '/ErrorManager.php');
135 require_once(dirname(__FILE__) . '/WikiCallback.php');
136
137 // FIXME: deprecated
138 function ExitWiki($errormsg = false)
139 {
140     global $request;
141     static $in_exit = 0;
142
143     if (is_object($request) and method_exists($request, "finish"))
144         $request->finish($errormsg); // NORETURN
145
146     if ($in_exit)
147         exit;
148
149     $in_exit = true;
150
151     global $ErrorManager;
152     $ErrorManager->flushPostponedErrors();
153
154     if (!empty($errormsg)) {
155         PrintXML(HTML::br(), $errormsg);
156         print "\n</body></html>";
157     }
158     exit;
159 }
160
161 if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
162     $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
163     $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
164 } else {
165     $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
166 }
167
168 // Local Variables:
169 // mode: php
170 // tab-width: 8
171 // c-basic-offset: 4
172 // c-hanging-comment-ender-p: nil
173 // indent-tabs-mode: nil
174 // End: