]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/WebStart.php
MediaWiki 1.15.4-scripts
[autoinstalls/mediawiki.git] / includes / WebStart.php
1 <?php
2
3 # This does the initial setup for a web request. It does some security checks,
4 # starts the profiler and loads the configuration, and optionally loads
5 # Setup.php depending on whether MW_NO_SETUP is defined.
6
7 # Protect against register_globals
8 # This must be done before any globals are set by the code
9 if ( ini_get( 'register_globals' ) ) {
10         if ( isset( $_REQUEST['GLOBALS'] ) ) {
11                 die( '<a href="http://www.hardened-php.net/index.76.html">$GLOBALS overwrite vulnerability</a>');
12         }
13         $verboten = array(
14                 'GLOBALS',
15                 '_SERVER',
16                 'HTTP_SERVER_VARS',
17                 '_GET',
18                 'HTTP_GET_VARS',
19                 '_POST',
20                 'HTTP_POST_VARS',
21                 '_COOKIE',
22                 'HTTP_COOKIE_VARS',
23                 '_FILES',
24                 'HTTP_POST_FILES',
25                 '_ENV',
26                 'HTTP_ENV_VARS',
27                 '_REQUEST',
28                 '_SESSION',
29                 'HTTP_SESSION_VARS'
30         );
31         foreach ( $_REQUEST as $name => $value ) {
32                 if( in_array( $name, $verboten ) ) {
33                         header( "HTTP/1.x 500 Internal Server Error" );
34                         echo "register_globals security paranoia: trying to overwrite superglobals, aborting.";
35                         die( -1 );
36                 }
37                 unset( $GLOBALS[$name] );
38         }
39 }
40
41 $wgRequestTime = microtime(true);
42 # getrusage() does not exist on the Microsoft Windows platforms, catching this
43 if ( function_exists ( 'getrusage' ) ) {
44         $wgRUstart = getrusage();
45 } else {
46         $wgRUstart = array();
47 }
48 unset( $IP );
49 @ini_set( 'allow_url_fopen', 0 ); # For security
50
51 # Valid web server entry point, enable includes.
52 # Please don't move this line to includes/Defines.php. This line essentially
53 # defines a valid entry point. If you put it in includes/Defines.php, then
54 # any script that includes it becomes an entry point, thereby defeating
55 # its purpose.
56 define( 'MEDIAWIKI', true );
57
58 # Full path to working directory.
59 # Makes it possible to for example to have effective exclude path in apc.
60 # Also doesn't break installations using symlinked includes, like
61 # dirname( __FILE__ ) would do.
62 $IP = getenv( 'MW_INSTALL_PATH' );
63 if ( $IP === false ) {
64         $IP = realpath( '.' );
65 }
66
67
68 # Start profiler
69 require_once( "$IP/StartProfiler.php" );
70 wfProfileIn( 'WebStart.php-conf' );
71
72 # Load up some global defines.
73 require_once( "$IP/includes/Defines.php" );
74
75 # Check for PHP 5
76 if ( !function_exists( 'version_compare' ) 
77         || version_compare( phpversion(), '5.0.0' ) < 0
78 ) {
79         define( 'MW_PHP4', '1' );
80         require( "$IP/includes/DefaultSettings.php" );
81         require( "$IP/includes/templates/PHP4.php" );
82         exit;
83 }
84
85 # Test for PHP bug which breaks PHP 5.0.x on 64-bit...
86 # As of 1.8 this breaks lots of common operations instead
87 # of just some rare ones like export.
88 $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
89 if( !isset( $borked[-1] ) ) {
90         echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
91              "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
92         exit;
93 }
94
95 # Start the autoloader, so that extensions can derive classes from core files
96 require_once( "$IP/includes/AutoLoader.php" );
97
98 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
99         # Use a callback function to configure MediaWiki
100         require_once( "$IP/includes/DefaultSettings.php" );
101         call_user_func( MW_CONFIG_CALLBACK );
102 } else {
103         # LocalSettings.php is the per site customization file. If it does not exit
104         # the wiki installer need to be launched or the generated file moved from
105         # ./config/ to ./
106         if( !file_exists( "$IP/LocalSettings.php" ) ) {
107                 require_once( "$IP/includes/DefaultSettings.php" ); # used for printing the version
108                 require_once( "$IP/includes/templates/NoLocalSettings.php" );
109                 die();
110         }
111
112         # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
113         require_once( "$IP/LocalSettings.php" );
114 }
115 wfProfileOut( 'WebStart.php-conf' );
116
117 wfProfileIn( 'WebStart.php-ob_start' );
118 # Initialise output buffering
119 if ( ob_get_level() ) {
120         # Someone's been mixing configuration data with code!
121         # How annoying.
122 } elseif ( !defined( 'MW_NO_OUTPUT_BUFFER' ) ) {
123         require_once( "$IP/includes/OutputHandler.php" );
124         ob_start( 'wfOutputHandler' );
125 }
126 wfProfileOut( 'WebStart.php-ob_start' );
127
128 if ( !defined( 'MW_NO_SETUP' ) ) {
129         require_once( "$IP/includes/Setup.php" );
130 }