Added DatabaseUpdater::addExtensionUpdate() to let extensions add their own updates...
[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.x 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 $wgRequestTime = microtime(true);
46 # getrusage() does not exist on the Microsoft Windows platforms, catching this
47 if ( function_exists ( 'getrusage' ) ) {
48 $wgRUstart = getrusage();
49 } else {
50 $wgRUstart = array();
51 }
52 unset( $IP );
53
54 # Valid web server entry point, enable includes.
55 # Please don't move this line to includes/Defines.php. This line essentially
56 # defines a valid entry point. If you put it in includes/Defines.php, then
57 # any script that includes it becomes an entry point, thereby defeating
58 # its purpose.
59 define( 'MEDIAWIKI', true );
60
61 # Full path to working directory.
62 # Makes it possible to for example to have effective exclude path in apc.
63 # Also doesn't break installations using symlinked includes, like
64 # dirname( __FILE__ ) would do.
65 $IP = getenv( 'MW_INSTALL_PATH' );
66 if ( $IP === false ) {
67 $IP = realpath( '.' );
68 }
69
70
71 # Start profiler
72 if( file_exists("$IP/StartProfiler.php") ) {
73 require_once( "$IP/StartProfiler.php" );
74 } else {
75 require_once( "$IP/includes/ProfilerStub.php" );
76 }
77 wfProfileIn( 'WebStart.php-conf' );
78
79 # Load up some global defines.
80 require_once( "$IP/includes/Defines.php" );
81
82 # Check for PHP 5
83 if ( !function_exists( 'version_compare' )
84 || version_compare( phpversion(), '5.0.0' ) < 0
85 ) {
86 define( 'MW_PHP4', '1' );
87 require( "$IP/includes/DefaultSettings.php" );
88 require( "$IP/includes/templates/PHP4.php" );
89 exit;
90 }
91
92 # Test for PHP bug which breaks PHP 5.0.x on 64-bit...
93 # As of 1.8 this breaks lots of common operations instead
94 # of just some rare ones like export.
95 $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
96 if( !isset( $borked[-1] ) ) {
97 echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
98 "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
99 exit;
100 }
101
102 # Start the autoloader, so that extensions can derive classes from core files
103 require_once( "$IP/includes/AutoLoader.php" );
104
105 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
106 # Use a callback function to configure MediaWiki
107 require_once( "$IP/includes/DefaultSettings.php" );
108
109 $callback = MW_CONFIG_CALLBACK;
110 if ( strpos( $callback, '::' ) !== false ) {
111 $callback = explode( '::', $callback, 2);
112 }
113 call_user_func( $callback );
114 } else {
115 # LocalSettings.php is the per site customization file. If it does not exit
116 # the wiki installer need to be launched or the generated file moved from
117 # ./config/ to ./
118 if( !file_exists( "$IP/LocalSettings.php" ) ) {
119 require_once( "$IP/includes/DefaultSettings.php" ); # used for printing the version
120 require_once( "$IP/includes/templates/NoLocalSettings.php" );
121 die();
122 }
123
124 # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
125 require_once( "$IP/LocalSettings.php" );
126 }
127 wfProfileOut( 'WebStart.php-conf' );
128
129 wfProfileIn( 'WebStart.php-ob_start' );
130 # Initialise output buffering
131
132 # Check that there is no previous output or previously set up buffers, because
133 # that would cause us to potentially mix gzip and non-gzip output, creating a
134 # big mess.
135 # In older versions of PHP ob_get_level() returns 0 if there is no buffering or
136 # previous output, in newer versions the default output buffer is always set up
137 # and ob_get_level() returns 1. In this case we check that the buffer is empty.
138 # FIXME: Check that this is the right way to handle this
139 if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ( ob_get_level() == 0 || ( ob_get_level() == 1 && ob_get_contents() === '' ) ) ) {
140 require_once( "$IP/includes/OutputHandler.php" );
141 ob_start( 'wfOutputHandler' );
142 }
143 wfProfileOut( 'WebStart.php-ob_start' );
144
145 if ( !defined( 'MW_NO_SETUP' ) ) {
146 require_once( "$IP/includes/Setup.php" );
147 }