Fix IE9's lack of support for console.warn.apply
[lhc/web/wiklou.git] / includes / WebStart.php
1 <?php
2 /**
3 * This does the initial set up 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 * Setup.php (if loaded) then sets up GlobalFunctions, the AutoLoader,
9 * and the configuration globals (though not $wgTitle).
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * http://www.gnu.org/copyleft/gpl.html
25 *
26 * @file
27 */
28
29 # Protect against register_globals
30 # This must be done before any globals are set by the code
31 if ( ini_get( 'register_globals' ) ) {
32 if ( isset( $_REQUEST['GLOBALS'] ) || isset( $_FILES['GLOBALS'] ) ) {
33 die( '<a href="http://www.hardened-php.net/globals-problem">$GLOBALS overwrite vulnerability</a>' );
34 }
35 $verboten = array(
36 'GLOBALS',
37 '_SERVER',
38 'HTTP_SERVER_VARS',
39 '_GET',
40 'HTTP_GET_VARS',
41 '_POST',
42 'HTTP_POST_VARS',
43 '_COOKIE',
44 'HTTP_COOKIE_VARS',
45 '_FILES',
46 'HTTP_POST_FILES',
47 '_ENV',
48 'HTTP_ENV_VARS',
49 '_REQUEST',
50 '_SESSION',
51 'HTTP_SESSION_VARS'
52 );
53 foreach ( $_REQUEST as $name => $value ) {
54 if ( in_array( $name, $verboten ) ) {
55 header( "HTTP/1.1 500 Internal Server Error" );
56 echo "register_globals security paranoia: trying to overwrite superglobals, aborting.";
57 die( -1 );
58 }
59 unset( $GLOBALS[$name] );
60 }
61 }
62
63 # bug 15461: Make IE8 turn off content sniffing. Everybody else should ignore this
64 # We're adding it here so that it's *always* set, even for alternate entry
65 # points and when $wgOut gets disabled or overridden.
66 header( 'X-Content-Type-Options: nosniff' );
67
68 $wgRequestTime = microtime( true );
69 # getrusage() does not exist on the Microsoft Windows platforms, catching this
70 if ( function_exists ( 'getrusage' ) ) {
71 $wgRUstart = getrusage();
72 } else {
73 $wgRUstart = array();
74 }
75 unset( $IP );
76
77 # Valid web server entry point, enable includes.
78 # Please don't move this line to includes/Defines.php. This line essentially
79 # defines a valid entry point. If you put it in includes/Defines.php, then
80 # any script that includes it becomes an entry point, thereby defeating
81 # its purpose.
82 define( 'MEDIAWIKI', true );
83
84 # Full path to working directory.
85 # Makes it possible to for example to have effective exclude path in apc.
86 # __DIR__ breaks symlinked includes, but realpath() returns false
87 # if we don't have permissions on parent directories.
88 $IP = getenv( 'MW_INSTALL_PATH' );
89 if ( $IP === false ) {
90 if ( realpath( '.' ) ) {
91 $IP = realpath( '.' );
92 } else {
93 $IP = dirname( __DIR__ );
94 }
95 }
96
97 # Start the autoloader, so that extensions can derive classes from core files
98 require_once "$IP/includes/AutoLoader.php";
99
100 # Load the profiler
101 require_once "$IP/includes/profiler/Profiler.php";
102
103 # Load up some global defines.
104 require_once "$IP/includes/Defines.php";
105
106 # Start the profiler
107 $wgProfiler = array();
108 if ( file_exists( "$IP/StartProfiler.php" ) ) {
109 require "$IP/StartProfiler.php";
110 }
111
112 wfProfileIn( 'WebStart.php-conf' );
113
114 # Load default settings
115 require_once "$IP/includes/DefaultSettings.php";
116
117 # Load composer's autoloader if present
118 if ( is_readable( "$IP/vendor/autoload.php" ) ) {
119 require_once "$IP/vendor/autoload.php";
120 }
121
122 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
123 # Use a callback function to configure MediaWiki
124 call_user_func( MW_CONFIG_CALLBACK );
125 } else {
126 if ( !defined( 'MW_CONFIG_FILE' ) ) {
127 define( 'MW_CONFIG_FILE', "$IP/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. Give a hint, if it is not readable by the server.
133 if ( !is_readable( 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 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 require_once "$IP/includes/OutputHandler.php";
151 ob_start( 'wfOutputHandler' );
152 }
153 wfProfileOut( 'WebStart.php-ob_start' );
154
155 if ( !defined( 'MW_NO_SETUP' ) ) {
156 require_once "$IP/includes/Setup.php";
157 }