The beginnings of HipHop compiled mode support. It works now for parser cache hits.
[lhc/web/wiklou.git] / includes / WebStart.php
1 <?php
2 /**
3 * This does the initial setup for a web request.
4 * It does some security checks, starts the profiler and loads the
5 * configuration, and optionally loads Setup.php depending on whether
6 * MW_NO_SETUP is defined.
7 *
8 * @file
9 */
10
11 /**
12 * Detect compiled mode by looking for a function that only exists if compiled
13 * in. Note that we can't use function_exists(), because it is terribly broken
14 * under HipHop due to the "volatile" feature.
15 */
16 function wfDetectCompiledMode() {
17 try {
18 $r = new ReflectionFunction( 'wfHipHopCompilerVersion' );
19 } catch ( ReflectionException $e ) {
20 $r = false;
21 }
22 return $r !== false;
23 }
24
25 # Protect against register_globals
26 # This must be done before any globals are set by the code
27 if ( ini_get( 'register_globals' ) ) {
28 if ( isset( $_REQUEST['GLOBALS'] ) ) {
29 die( '<a href="http://www.hardened-php.net/globals-problem">$GLOBALS overwrite vulnerability</a>');
30 }
31 $verboten = array(
32 'GLOBALS',
33 '_SERVER',
34 'HTTP_SERVER_VARS',
35 '_GET',
36 'HTTP_GET_VARS',
37 '_POST',
38 'HTTP_POST_VARS',
39 '_COOKIE',
40 'HTTP_COOKIE_VARS',
41 '_FILES',
42 'HTTP_POST_FILES',
43 '_ENV',
44 'HTTP_ENV_VARS',
45 '_REQUEST',
46 '_SESSION',
47 'HTTP_SESSION_VARS'
48 );
49 foreach ( $_REQUEST as $name => $value ) {
50 if( in_array( $name, $verboten ) ) {
51 header( "HTTP/1.1 500 Internal Server Error" );
52 echo "register_globals security paranoia: trying to overwrite superglobals, aborting.";
53 die( -1 );
54 }
55 unset( $GLOBALS[$name] );
56 }
57 }
58
59 $wgRequestTime = microtime(true);
60 # getrusage() does not exist on the Microsoft Windows platforms, catching this
61 if ( function_exists ( 'getrusage' ) ) {
62 $wgRUstart = getrusage();
63 } else {
64 $wgRUstart = array();
65 }
66 unset( $IP );
67
68 # Valid web server entry point, enable includes.
69 # Please don't move this line to includes/Defines.php. This line essentially
70 # defines a valid entry point. If you put it in includes/Defines.php, then
71 # any script that includes it becomes an entry point, thereby defeating
72 # its purpose.
73 define( 'MEDIAWIKI', true );
74
75 # Full path to working directory.
76 # Makes it possible to for example to have effective exclude path in apc.
77 # Also doesn't break installations using symlinked includes, like
78 # dirname( __FILE__ ) would do.
79 $IP = getenv( 'MW_INSTALL_PATH' );
80 if ( $IP === false ) {
81 $IP = realpath( '.' );
82 }
83
84 if ( wfDetectCompiledMode() ) {
85 define( 'MW_COMPILED', 1 );
86 }
87
88 if ( !defined( 'MW_COMPILED' ) ) {
89 # Get MWInit class
90 require_once( "$IP/includes/Init.php" );
91
92 # Start profiler
93 # FIXME: rewrite wfProfileIn/wfProfileOut so that they can work in compiled mode
94 if ( file_exists( "$IP/StartProfiler.php" ) ) {
95 require_once( "$IP/StartProfiler.php" );
96 } else {
97 require_once( "$IP/includes/ProfilerStub.php" );
98 }
99
100 # Load up some global defines.
101 require_once( "$IP/includes/Defines.php" );
102
103 # Check for PHP 5
104 if ( !function_exists( 'version_compare' )
105 || version_compare( phpversion(), '5.0.0' ) < 0
106 ) {
107 define( 'MW_PHP4', '1' );
108 require( "$IP/includes/DefaultSettings.php" );
109 require( "$IP/includes/templates/PHP4.php" );
110 exit;
111 }
112
113 # Start the autoloader, so that extensions can derive classes from core files
114 require_once( "$IP/includes/AutoLoader.php" );
115 }
116
117 wfProfileIn( 'WebStart.php-conf' );
118
119 # Load default settings
120 require_once( MWInit::compiledPath( "includes/DefaultSettings.php" ) );
121
122 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
123 # Use a callback function to configure MediaWiki
124 MWFunction::call( MW_CONFIG_CALLBACK );
125 } else {
126 if ( !defined( 'MW_CONFIG_FILE' ) ) {
127 define('MW_CONFIG_FILE', MWInit::interpretedPath( 'LocalSettings.php' ) );
128 }
129
130 # LocalSettings.php is the per site customization file. If it does not exist
131 # the wiki installer needs to be launched or the generated file uploaded to
132 # the root wiki directory
133 if( !file_exists( MW_CONFIG_FILE ) ) {
134 require_once( "$IP/includes/templates/NoLocalSettings.php" );
135 die();
136 }
137
138 # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
139 require_once( MW_CONFIG_FILE );
140 }
141
142 if ( $wgEnableSelenium ) {
143 require_once( MWInit::compiledPath( "includes/SeleniumWebSettings.php" ) );
144 }
145
146 wfProfileOut( 'WebStart.php-conf' );
147
148 wfProfileIn( 'WebStart.php-ob_start' );
149 # Initialise output buffering
150 # Check that there is no previous output or previously set up buffers, because
151 # that would cause us to potentially mix gzip and non-gzip output, creating a
152 # big mess.
153 if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ob_get_level() == 0 ) {
154 if ( !defined( 'MW_COMPILED' ) ) {
155 require_once( "$IP/includes/OutputHandler.php" );
156 }
157 ob_start( 'wfOutputHandler' );
158 }
159 wfProfileOut( 'WebStart.php-ob_start' );
160
161 if ( !defined( 'MW_NO_SETUP' ) ) {
162 require_once( MWInit::compiledPath( "includes/Setup.php" ) );
163 }
164