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