Use consistent notation for "@todo FIXME". Should update http://svn.wikimedia.org...
[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 # bug 15461: Make IE8 turn off content sniffing. Everbody else should ignore this
60 # We're adding it here so that it's *always* set, even for alternate entry
61 # points and when $wgOut gets disabled or overridden.
62 header( 'X-Content-Type-Options: nosniff' );
63
64 $wgRequestTime = microtime(true);
65 # getrusage() does not exist on the Microsoft Windows platforms, catching this
66 if ( function_exists ( 'getrusage' ) ) {
67 $wgRUstart = getrusage();
68 } else {
69 $wgRUstart = array();
70 }
71 unset( $IP );
72
73 # Valid web server entry point, enable includes.
74 # Please don't move this line to includes/Defines.php. This line essentially
75 # defines a valid entry point. If you put it in includes/Defines.php, then
76 # any script that includes it becomes an entry point, thereby defeating
77 # its purpose.
78 define( 'MEDIAWIKI', true );
79
80 # Full path to working directory.
81 # Makes it possible to for example to have effective exclude path in apc.
82 # Also doesn't break installations using symlinked includes, like
83 # dirname( __FILE__ ) would do.
84 $IP = getenv( 'MW_INSTALL_PATH' );
85 if ( $IP === false ) {
86 $IP = realpath( '.' );
87 }
88
89 if ( wfDetectCompiledMode() ) {
90 define( 'MW_COMPILED', 1 );
91 }
92
93 if ( !defined( 'MW_COMPILED' ) ) {
94 # Get MWInit class
95 require_once( "$IP/includes/Init.php" );
96
97 # Start the autoloader, so that extensions can derive classes from core files
98 require_once( "$IP/includes/AutoLoader.php" );
99
100 # Start profiler
101 # @todo FIXME: Rewrite wfProfileIn/wfProfileOut so that they can work in compiled mode
102 require_once( "$IP/includes/profiler/Profiler.php" );
103 if ( file_exists( "$IP/StartProfiler.php" ) ) {
104 require_once( "$IP/StartProfiler.php" );
105 }
106
107 # Load up some global defines.
108 require_once( "$IP/includes/Defines.php" );
109 }
110
111 wfProfileIn( 'WebStart.php-conf' );
112
113 # Load default settings
114 require_once( MWInit::compiledPath( "includes/DefaultSettings.php" ) );
115
116 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
117 # Use a callback function to configure MediaWiki
118 MWFunction::call( MW_CONFIG_CALLBACK );
119 } else {
120 if ( !defined( 'MW_CONFIG_FILE' ) ) {
121 define('MW_CONFIG_FILE', MWInit::interpretedPath( 'LocalSettings.php' ) );
122 }
123
124 # LocalSettings.php is the per site customization file. If it does not exist
125 # the wiki installer needs to be launched or the generated file uploaded to
126 # the root wiki directory
127 if( !file_exists( MW_CONFIG_FILE ) ) {
128 $script = $_SERVER['SCRIPT_NAME'];
129 $path = htmlspecialchars( str_replace( '//', '/', pathinfo( $script, PATHINFO_DIRNAME ) ) );
130 $ext = htmlspecialchars( pathinfo( $script, PATHINFO_EXTENSION ) );
131
132 # Check to see if the installer is running
133 if ( !function_exists( 'session_name' ) ) {
134 $installerStarted = false;
135 } else {
136 session_name( 'mw_installer_session' );
137 $oldReporting = error_reporting( E_ALL & ~E_NOTICE );
138 $success = session_start();
139 error_reporting( $oldReporting );
140 $installerStarted = ( $success && isset( $_SESSION['installData'] ) );
141 }
142
143 $please = $installerStarted
144 ? "Please <a href=\"$path/mw-config/index.$ext\"> complete the installation</a> and download LocalSettings.php."
145 : "Please <a href=\"$path/mw-config/index.$ext\"> set up the wiki</a> first.";
146
147 wfDie( "<p>LocalSettings.php not found.</p><p>$please</p>" );
148 }
149
150 # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
151 require_once( MW_CONFIG_FILE );
152 }
153
154 if ( $wgEnableSelenium ) {
155 require_once( MWInit::compiledPath( "includes/SeleniumWebSettings.php" ) );
156 }
157
158 wfProfileOut( 'WebStart.php-conf' );
159
160 wfProfileIn( 'WebStart.php-ob_start' );
161 # Initialise output buffering
162 # Check that there is no previous output or previously set up buffers, because
163 # that would cause us to potentially mix gzip and non-gzip output, creating a
164 # big mess.
165 if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ob_get_level() == 0 ) {
166 if ( !defined( 'MW_COMPILED' ) ) {
167 require_once( "$IP/includes/OutputHandler.php" );
168 }
169 ob_start( 'wfOutputHandler' );
170 }
171 wfProfileOut( 'WebStart.php-ob_start' );
172
173 if ( !defined( 'MW_NO_SETUP' ) ) {
174 require_once( MWInit::compiledPath( "includes/Setup.php" ) );
175 }
176