]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/prepend.php
Remove unused function _showvalue
[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.5.2');
9
10 /** PHP5 deprecated old-style globals if !(bool)ini_get('register_long_arrays').
11  *  See Bug #1180115
12  * We want to work with those old ones instead of the new superglobals,
13  * for easier coding.
14  */
15 /*
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];
19     }
20 }
21 */
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;
31 }
32 unset($k);
33 // catch connection failures on upgrade
34 if (isset($GLOBALS['HTTP_GET_VARS']['action'])
35     and $GLOBALS['HTTP_GET_VARS']['action'] == 'upgrade'
36 )
37     define('ADODB_ERROR_HANDLER_TYPE', E_USER_WARNING);
38
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.
45 //
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);
49
50 if (defined('DEBUG') and (DEBUG & 8) and extension_loaded("xdebug")) {
51     xdebug_start_trace("trace"); // on Dbgp protocol add 2
52     xdebug_enable();
53 }
54 if (defined('DEBUG') and (DEBUG & 32) and extension_loaded("apd")) {
55     apd_set_pprof_trace();
56     /*    FUNCTION_TRACE      1
57         ARGS_TRACE          2
58         ASSIGNMENT_TRACE    4
59         STATEMENT_TRACE     8
60         MEMORY_TRACE        16
61         TIMING_TRACE        32
62         SUMMARY_TRACE       64 */
63     //apd_set_session_trace(99);
64 }
65
66 // Used for debugging purposes
67 class DebugTimer
68 {
69     function DebugTimer()
70     {
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();
75         }
76     }
77
78     /**
79      * @param  string $which One of 'real', 'utime', 'stime', 'cutime', 'sutime'
80      * @param array $now
81      * @return float  Seconds.
82      */
83     function getTime($which = 'real', $now = array())
84     {
85         if ($which == 'real') {
86             return $this->microtime() - $this->_start;
87         }
88
89         if (isset($this->_times)) {
90             if (empty($now)) {
91                 $now = posix_times();
92             }
93             $ticks = $now[$which] - $this->_times[$which];
94             return $ticks / $this->_CLK_TCK();
95         }
96
97         return 0.0; // Not available.
98     }
99
100     function getStats()
101     {
102         if (!isset($this->_times)) {
103             // posix_times() not available.
104             return sprintf("real: %.3f", $this->getTime('real'));
105         }
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));
111     }
112
113     function _CLK_TCK()
114     {
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     {
122         list($usec, $sec) = explode(" ", microtime());
123         return ((float)$usec + (float)$sec);
124     }
125 }
126
127 $RUNTIMER = new DebugTimer;
128 require_once(dirname(__FILE__) . '/ErrorManager.php');
129 require_once(dirname(__FILE__) . '/WikiCallback.php');
130
131 // FIXME: deprecated
132 function ExitWiki($errormsg = false)
133 {
134     global $request;
135     static $in_exit = 0;
136
137     if (is_object($request) and method_exists($request, "finish"))
138         $request->finish($errormsg); // NORETURN
139
140     if ($in_exit)
141         exit;
142
143     $in_exit = true;
144
145     global $ErrorManager;
146     $ErrorManager->flushPostponedErrors();
147
148     if (!empty($errormsg)) {
149         PrintXML(HTML::br(), $errormsg);
150         print "\n</body></html>";
151     }
152     exit;
153 }
154
155 if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
156     $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
157     $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
158 } else {
159     $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
160 }
161
162 // Local Variables:
163 // mode: php
164 // tab-width: 8
165 // c-basic-offset: 4
166 // c-hanging-comment-ender-p: nil
167 // indent-tabs-mode: nil
168 // End: