]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/prepend.php
bump version
[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 $RCS_IDS = '';
7 function rcs_id ($id) { 
8     // Save memory
9     if (defined('DEBUG') and DEBUG)
10         $GLOBALS['RCS_IDS'] .= "$id\n"; 
11 }
12 rcs_id('$Id: prepend.php,v 1.66 2007-09-15 12:37:00 rurban Exp $');
13
14 // see lib/stdlib.php: phpwiki_version()
15 define('PHPWIKI_VERSION', '1.3.14-20070915');
16
17 /** 
18  * Returns true if current php version is at mimimum a.b.c 
19  * Called: check_php_version(4,1)
20  */
21 function check_php_version ($a = '0', $b = '0', $c = '0') {
22     static $PHP_VERSION;
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));
26 }
27
28 /** PHP5 deprecated old-style globals if !(bool)ini_get('register_long_arrays'). 
29   *  See Bug #1180115
30   * We want to work with those old ones instead of the new superglobals, 
31   * for easier coding.
32   */
33 /*
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];
37     }
38 }
39 */
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;
49 }
50 unset($k);
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);
55
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.
62 //
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);
66
67 if (defined('DEBUG') and (DEBUG & 8) and extension_loaded("xdebug")) {
68     xdebug_start_trace("trace"); // on Dbgp protocol add 2
69     xdebug_enable();
70 }
71
72 // Used for debugging purposes
73 class DebugTimer {
74     function DebugTimer() {
75         $this->_start = $this->microtime();
76         if (function_exists('posix_times'))
77             $this->_times = posix_times();
78     }
79
80     /**
81      * @param string $which  One of 'real', 'utime', 'stime', 'cutime', 'sutime'
82      * @return float Seconds.
83      */
84     function getTime($which='real', $now=false) {
85         if ($which == 'real')
86             return $this->microtime() - $this->_start;
87
88         if (isset($this->_times)) {
89             if (!$now) $now = posix_times();
90             $ticks = $now[$which] - $this->_times[$which];
91             return $ticks / $this->_CLK_TCK();
92         }
93
94         return 0.0;           // Not available.
95     }
96
97     function getStats() {
98         if (!isset($this->_times)) {
99             // posix_times() not available.
100             return sprintf("real: %.3f", $this->getTime('real'));
101         }
102         $now = posix_times();
103         return sprintf("real: %.3f, user: %.3f, sys: %.3f",
104                        $this->getTime('real'),
105                        $this->getTime('utime', $now),
106                        $this->getTime('stime', $now));
107     }
108         
109     function _CLK_TCK() {
110         // FIXME: this is clearly not always right.
111         // But how to figure out the right value?
112         return 100.0;
113     }
114
115     function microtime(){
116         list($usec, $sec) = explode(" ", microtime());
117         return ((float)$usec + (float)$sec);
118     }
119 }
120 $RUNTIMER = new DebugTimer;
121 /*
122 if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
123     error_reporting(E_ALL & ~E_STRICT);         // exclude E_STRICT
124 else
125     error_reporting(E_ALL); // php4
126 //echo " prepend: ", error_reporting();
127 */
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 if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
155     $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
156     $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
157 } else {
158     $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
159 }
160
161
162 // (c-file-style: "gnu")
163 // Local Variables:
164 // mode: php
165 // tab-width: 8
166 // c-basic-offset: 4
167 // c-hanging-comment-ender-p: nil
168 // indent-tabs-mode: nil
169 // End:   
170 ?>