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