ca46b8979ff1a7fb63f70c167b9b3f4bd4505d43
[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 # Protect against register_globals
12 # This must be done before any globals are set by the code
13 if ( ini_get( 'register_globals' ) ) {
14 if ( isset( $_REQUEST['GLOBALS'] ) ) {
15 die( '<a href="http://www.hardened-php.net/globals-problem">$GLOBALS overwrite vulnerability</a>');
16 }
17 $verboten = array(
18 'GLOBALS',
19 '_SERVER',
20 'HTTP_SERVER_VARS',
21 '_GET',
22 'HTTP_GET_VARS',
23 '_POST',
24 'HTTP_POST_VARS',
25 '_COOKIE',
26 'HTTP_COOKIE_VARS',
27 '_FILES',
28 'HTTP_POST_FILES',
29 '_ENV',
30 'HTTP_ENV_VARS',
31 '_REQUEST',
32 '_SESSION',
33 'HTTP_SESSION_VARS'
34 );
35 foreach ( $_REQUEST as $name => $value ) {
36 if( in_array( $name, $verboten ) ) {
37 header( "HTTP/1.1 500 Internal Server Error" );
38 echo "register_globals security paranoia: trying to overwrite superglobals, aborting.";
39 die( -1 );
40 }
41 unset( $GLOBALS[$name] );
42 }
43 }
44
45 # bug 15461: Make IE8 turn off content sniffing. Everbody else should ignore this
46 # We're adding it here so that it's *always* set, even for alternate entry
47 # points and when $wgOut gets disabled or overridden.
48 header( 'X-Content-Type-Options: nosniff' );
49
50 $wgRequestTime = microtime(true);
51 # getrusage() does not exist on the Microsoft Windows platforms, catching this
52 if ( function_exists ( 'getrusage' ) ) {
53 $wgRUstart = getrusage();
54 } else {
55 $wgRUstart = array();
56 }
57 unset( $IP );
58
59 # Valid web server entry point, enable includes.
60 # Please don't move this line to includes/Defines.php. This line essentially
61 # defines a valid entry point. If you put it in includes/Defines.php, then
62 # any script that includes it becomes an entry point, thereby defeating
63 # its purpose.
64 define( 'MEDIAWIKI', true );
65
66 # Full path to working directory.
67 # Makes it possible to for example to have effective exclude path in apc.
68 # Also doesn't break installations using symlinked includes, like
69 # dirname( __FILE__ ) would do.
70 $IP = getenv( 'MW_INSTALL_PATH' );
71 if ( $IP === false ) {
72 $IP = realpath( '.' );
73 }
74
75 if ( isset( $_SERVER['MW_COMPILED'] ) ) {
76 define( 'MW_COMPILED', 1 );
77 } else {
78 # Get MWInit class
79 require_once( "$IP/includes/Init.php" );
80
81 # Start the autoloader, so that extensions can derive classes from core files
82 require_once( "$IP/includes/AutoLoader.php" );
83
84 # Start profiler
85 # @todo FIXME: Rewrite wfProfileIn/wfProfileOut so that they can work in compiled mode
86 require_once( "$IP/includes/profiler/Profiler.php" );
87 if ( file_exists( "$IP/StartProfiler.php" ) ) {
88 require_once( "$IP/StartProfiler.php" );
89 }
90
91 # Load up some global defines.
92 require_once( "$IP/includes/Defines.php" );
93 }
94
95 wfProfileIn( 'WebStart.php-conf' );
96
97 # Load default settings
98 require_once( MWInit::compiledPath( "includes/DefaultSettings.php" ) );
99
100 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
101 # Use a callback function to configure MediaWiki
102 MWFunction::call( MW_CONFIG_CALLBACK );
103 } else {
104 if ( !defined( 'MW_CONFIG_FILE' ) ) {
105 define('MW_CONFIG_FILE', MWInit::interpretedPath( 'LocalSettings.php' ) );
106 }
107
108 # LocalSettings.php is the per site customization file. If it does not exist
109 # the wiki installer needs to be launched or the generated file uploaded to
110 # the root wiki directory
111 if( !file_exists( MW_CONFIG_FILE ) ) {
112 $script = $_SERVER['SCRIPT_NAME'];
113 $path = htmlspecialchars( str_replace( '//', '/', pathinfo( $script, PATHINFO_DIRNAME ) ) );
114 $ext = htmlspecialchars( pathinfo( $script, PATHINFO_EXTENSION ) );
115
116 # Check to see if the installer is running
117 if ( !function_exists( 'session_name' ) ) {
118 $installerStarted = false;
119 } else {
120 session_name( 'mw_installer_session' );
121 $oldReporting = error_reporting( E_ALL & ~E_NOTICE );
122 $success = session_start();
123 error_reporting( $oldReporting );
124 $installerStarted = ( $success && isset( $_SESSION['installData'] ) );
125 }
126
127 $please = $installerStarted
128 ? "Please <a href=\"$path/mw-config/index.$ext\"> complete the installation</a> and download LocalSettings.php."
129 : "Please <a href=\"$path/mw-config/index.$ext\"> set up the wiki</a> first.";
130
131 wfDie( "<p>LocalSettings.php not found.</p><p>$please</p>" );
132 }
133
134 # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
135 require_once( MW_CONFIG_FILE );
136 }
137
138 if ( $wgEnableSelenium ) {
139 require_once( MWInit::compiledPath( "includes/SeleniumWebSettings.php" ) );
140 }
141
142 wfProfileOut( 'WebStart.php-conf' );
143
144 wfProfileIn( 'WebStart.php-ob_start' );
145 # Initialise output buffering
146 # Check that there is no previous output or previously set up buffers, because
147 # that would cause us to potentially mix gzip and non-gzip output, creating a
148 # big mess.
149 if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ob_get_level() == 0 ) {
150 if ( !defined( 'MW_COMPILED' ) ) {
151 require_once( "$IP/includes/OutputHandler.php" );
152 }
153 ob_start( 'wfOutputHandler' );
154 }
155 wfProfileOut( 'WebStart.php-ob_start' );
156
157 if ( !defined( 'MW_NO_SETUP' ) ) {
158 require_once( MWInit::compiledPath( "includes/Setup.php" ) );
159 }
160