File: prepend.php

package info (click to toggle)
phpwiki 1.3.14-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 15,716 kB
  • ctags: 23,548
  • sloc: php: 88,295; sql: 1,476; sh: 1,378; perl: 765; makefile: 602; awk: 28
file content (170 lines) | stat: -rwxr-xr-x 5,257 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/* lib/prepend.php
 *
 * Things which must be done and defined before anything else.
 */
$RCS_IDS = '';
function rcs_id ($id) { 
    // Save memory
    if (defined('DEBUG') and DEBUG)
        $GLOBALS['RCS_IDS'] .= "$id\n"; 
}
rcs_id('$Id: prepend.php,v 1.61 2007/06/07 16:59:06 rurban Exp $');

// see lib/stdlib.php: phpwiki_version()
define('PHPWIKI_VERSION', '1.3.14');

/** 
 * Returns true if current php version is at mimimum a.b.c 
 * Called: check_php_version(4,1)
 */
function check_php_version ($a = '0', $b = '0', $c = '0') {
    static $PHP_VERSION;
    if (!isset($PHP_VERSION))
        $PHP_VERSION = substr( str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'), 0, 3);
    return ($PHP_VERSION >= ($a.$b.$c));
}

/** PHP5 deprecated old-style globals if !(bool)ini_get('register_long_arrays'). 
  *  See Bug #1180115
  * We want to work with those old ones instead of the new superglobals, 
  * for easier coding.
  */
/*
foreach (array('SERVER','REQUEST','GET','POST','SESSION','ENV','COOKIE') as $k) {
    if (!isset($GLOBALS['HTTP_'.$k.'_VARS']) and isset($GLOBALS['_'.$k])) {
        $GLOBALS['HTTP_'.$k.'_VARS'] =& $GLOBALS['_'.$k];
    }
}
*/
// A new php-5.1.x feature: Turn off php-5.1.x auto_globals_jit = On, or use this mess below.
if (empty($GLOBALS['HTTP_SERVER_VARS'])) {
    $GLOBALS['HTTP_SERVER_VARS']  =& $_SERVER;
    $GLOBALS['HTTP_ENV_VARS'] 	  =& $_ENV;
    $GLOBALS['HTTP_GET_VARS'] 	  =& $_GET;
    $GLOBALS['HTTP_POST_VARS'] 	  =& $_POST;
    $GLOBALS['HTTP_SESSION_VARS'] =& $_SESSION;
    $GLOBALS['HTTP_COOKIE_VARS']  =& $_COOKIE;
    $GLOBALS['HTTP_REQUEST_VARS'] =& $_REQUEST;
}
unset($k);
// catch connection failures on upgrade
if (isset($GLOBALS['HTTP_GET_VARS']['action']) 
    and $GLOBALS['HTTP_GET_VARS']['action'] == 'upgrade')
    define('ADODB_ERROR_HANDLER_TYPE', E_USER_WARNING);

// If your php was compiled with --enable-trans-sid it tries to
// add a PHPSESSID query argument to all URL strings when cookie
// support isn't detected in the client browser.  For reasons
// which aren't entirely clear (PHP bug) this screws up the URLs
// generated by PhpWiki.  Therefore, transparent session ids
// should be disabled.  This next line does that.
//
// (At the present time, you will not be able to log-in to PhpWiki,
// unless your browser supports cookies.)
@ini_set('session.use_trans_sid', 0);

if (defined('DEBUG') and (DEBUG & 8) and extension_loaded("xdebug")) {
    xdebug_start_trace("trace"); // on Dbgp protocol add 2
    xdebug_enable();
}

// Used for debugging purposes
class DebugTimer {
    function DebugTimer() {
        $this->_start = $this->microtime();
        if (function_exists('posix_times'))
            $this->_times = posix_times();
    }

    /**
     * @param string $which  One of 'real', 'utime', 'stime', 'cutime', 'sutime'
     * @return float Seconds.
     */
    function getTime($which='real', $now=false) {
        if ($which == 'real')
            return $this->microtime() - $this->_start;

        if (isset($this->_times)) {
            if (!$now) $now = posix_times();
            $ticks = $now[$which] - $this->_times[$which];
            return $ticks / $this->_CLK_TCK();
        }

        return 0.0;           // Not available.
    }

    function getStats() {
        if (!isset($this->_times)) {
            // posix_times() not available.
            return sprintf("real: %.3f", $this->getTime('real'));
        }
        $now = posix_times();
        return sprintf("real: %.3f, user: %.3f, sys: %.3f",
                       $this->getTime('real'),
                       $this->getTime('utime', $now),
                       $this->getTime('stime', $now));
    }
        
    function _CLK_TCK() {
        // FIXME: this is clearly not always right.
        // But how to figure out the right value?
        return 100.0;
    }

    function microtime(){
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }
}
$RUNTIMER = new DebugTimer;
/*
if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
    error_reporting(E_ALL & ~E_STRICT); 	// exclude E_STRICT
else
    error_reporting(E_ALL); // php4
//echo " prepend: ", error_reporting();
*/
require_once(dirname(__FILE__).'/ErrorManager.php');
require_once(dirname(__FILE__).'/WikiCallback.php');

// FIXME: deprecated
function ExitWiki($errormsg = false)
{
    global $request;
    static $in_exit = 0;

    if (is_object($request) and method_exists($request,"finish"))
        $request->finish($errormsg); // NORETURN

    if ($in_exit)
        exit;
    
    $in_exit = true;

    global $ErrorManager;
    $ErrorManager->flushPostponedErrors();
   
    if(!empty($errormsg)) {
        PrintXML(HTML::br(), $errormsg);
        print "\n</body></html>";
    }
    exit;
}
if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
    $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
    $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
} else {
    $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
}


// (c-file-style: "gnu")
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:   
?>