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.
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.
16 function wfDetectCompiledMode() {
18 $r = new ReflectionFunction( 'wfHipHopCompilerVersion' );
19 } catch ( ReflectionException
$e ) {
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>');
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.";
55 unset( $GLOBALS[$name] );
59 $wgRequestTime = microtime(true);
60 # getrusage() does not exist on the Microsoft Windows platforms, catching this
61 if ( function_exists ( 'getrusage' ) ) {
62 $wgRUstart = getrusage();
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
73 define( 'MEDIAWIKI', true );
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( '.' );
84 if ( wfDetectCompiledMode() ) {
85 define( 'MW_COMPILED', 1 );
88 if ( !defined( 'MW_COMPILED' ) ) {
90 require_once( "$IP/includes/Init.php" );
92 # Start the autoloader, so that extensions can derive classes from core files
93 require_once( "$IP/includes/AutoLoader.php" );
96 # FIXME: rewrite wfProfileIn/wfProfileOut so that they can work in compiled mode
97 require_once( "$IP/includes/profiler/Profiler.php" );
98 if ( file_exists( "$IP/StartProfiler.php" ) ) {
99 require_once( "$IP/StartProfiler.php" );
102 # Load up some global defines.
103 require_once( "$IP/includes/Defines.php" );
106 wfProfileIn( 'WebStart.php-conf' );
108 # Load default settings
109 require_once( MWInit
::compiledPath( "includes/DefaultSettings.php" ) );
111 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
112 # Use a callback function to configure MediaWiki
113 MWFunction
::call( MW_CONFIG_CALLBACK
);
115 if ( !defined( 'MW_CONFIG_FILE' ) ) {
116 define('MW_CONFIG_FILE', MWInit
::interpretedPath( 'LocalSettings.php' ) );
119 # LocalSettings.php is the per site customization file. If it does not exist
120 # the wiki installer needs to be launched or the generated file uploaded to
121 # the root wiki directory
122 if( !file_exists( MW_CONFIG_FILE
) ) {
123 $script = $_SERVER['SCRIPT_NAME'];
124 $path = htmlspecialchars( str_replace( '//', '/', pathinfo( $script, PATHINFO_DIRNAME
) ) );
125 $ext = htmlspecialchars( pathinfo( $script, PATHINFO_EXTENSION
) );
127 # Check to see if the installer is running
128 if ( !function_exists( 'session_name' ) ) {
129 $installerStarted = false;
131 session_name( 'mw_installer_session' );
132 $oldReporting = error_reporting( E_ALL
& ~E_NOTICE
);
133 $success = session_start();
134 error_reporting( $oldReporting );
135 $installerStarted = ( $success && isset( $_SESSION['installData'] ) );
138 $please = $installerStarted
139 ?
"Please <a href=\"$path/mw-config/index.$ext\"> complete the installation</a> and download LocalSettings.php."
140 : "Please <a href=\"$path/mw-config/index.$ext\"> set up the wiki</a> first.";
142 wfDie( "<p>LocalSettings.php not found.</p><p>$please</p>" );
145 # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
146 require_once( MW_CONFIG_FILE
);
149 if ( $wgEnableSelenium ) {
150 require_once( MWInit
::compiledPath( "includes/SeleniumWebSettings.php" ) );
153 wfProfileOut( 'WebStart.php-conf' );
155 wfProfileIn( 'WebStart.php-ob_start' );
156 # Initialise output buffering
157 # Check that there is no previous output or previously set up buffers, because
158 # that would cause us to potentially mix gzip and non-gzip output, creating a
160 if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ob_get_level() == 0 ) {
161 if ( !defined( 'MW_COMPILED' ) ) {
162 require_once( "$IP/includes/OutputHandler.php" );
164 ob_start( 'wfOutputHandler' );
166 wfProfileOut( 'WebStart.php-ob_start' );
168 if ( !defined( 'MW_NO_SETUP' ) ) {
169 require_once( MWInit
::compiledPath( "includes/Setup.php" ) );