3 * This is the main web entry point for MediaWiki.
5 * If you are reading this in your web browser, your server is probably
6 * not configured correctly to run PHP applications!
8 * See the README, INSTALL, and UPGRADE files for basic setup instructions
9 * and pointers to the online documentation.
11 * http://www.mediawiki.org/
15 * Copyright (C) 2001-2011 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
16 * Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
17 * Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor,
18 * Aaron Schulz, Andrew Garrett, Raimond Spekking, Alexandre Emsenhuber
19 * Siebrand Mazeland, Chad Horohoe, Roan Kattouw and others.
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License along
32 * with this program; if not, write to the Free Software Foundation, Inc.,
33 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34 * http://www.gnu.org/copyleft/gpl.html
39 // Load global constants, including MW_VERSION and MW_MIN_PHP_VERSION
40 require_once( dirname( __FILE__
) . '/includes/Defines.php' );
42 // Bail on old versions of PHP. Pretty much every other file in the codebase
43 // has structures (try/catch, foo()->bar(), etc etc) which throw parse errors in PHP 4.
44 // Setup.php and ObjectCache.php have structures invalid in PHP 5.0 and 5.1, respectively.
45 if ( !function_exists( 'version_compare' ) ||
version_compare( phpversion(), MW_MIN_PHP_VERSION
) < 0 ) {
46 $phpversion = htmlspecialchars( phpversion() );
47 $reqVersion = htmlspecialchars( MW_MIN_PHP_VERSION
);
50 MediaWiki requires PHP $reqVersion or higher. You are running PHP $phpversion.
53 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
54 PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
55 security or bugfix updates.
58 If for some reason you are unable to upgrade your PHP version, you will need to
59 <a href="http://www.mediawiki.org/wiki/Download">download</a> an older version
60 of MediaWiki from our website. See our
61 <a href="http://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
62 for details of which versions are compatible with prior versions of PHP.
68 # Initialise common code. This gives us access to GlobalFunctions, the AutoLoader, and
69 # the globals $wgRequest, $wgOut, $wgUser, $wgLang and $wgContLang, amongst others; it
70 # does *not* load $wgTitle or $wgArticle
71 require ( dirname( __FILE__
) . '/includes/WebStart.php' );
73 wfProfileIn( 'index.php' );
74 wfProfileIn( 'index.php-setup' );
76 $maxLag = $wgRequest->getVal( 'maxlag' );
77 if ( !is_null( $maxLag ) ) {
78 $lb = wfGetLB(); // foo()->bar() is not supported in PHP4
79 list( $host, $lag ) = $lb->getMaxLag();
80 if ( $lag > $maxLag ) {
81 header( 'HTTP/1.1 503 Service Unavailable' );
82 header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
83 header( 'X-Database-Lag: ' . intval( $lag ) );
84 header( 'Content-Type: text/plain' );
85 if( $wgShowHostnames ) {
86 echo "Waiting for $host: $lag seconds lagged\n";
88 echo "Waiting for a database server: $lag seconds lagged\n";
94 # Initialize MediaWiki base class
95 $context = RequestContext
::getMain();
96 $mediaWiki = new MediaWiki( $context );
98 # Set title from request parameters
99 $wgTitle = $mediaWiki->getTitle();
100 $action = $wgRequest->getVal( 'action', 'view' );
102 wfProfileOut( 'index.php-setup' );
104 # Send Ajax requests to the Ajax dispatcher.
105 if ( $wgUseAjax && $action == 'ajax' ) {
106 $dispatcher = new AjaxDispatcher();
107 $dispatcher->performAction();
108 wfProfileOut( 'index.php' );
109 $mediaWiki->restInPeace();
113 if ( $wgUseFileCache && $wgTitle !== null ) {
114 wfProfileIn( 'index.php-filecache' );
115 // Raw pages should handle cache control on their own,
116 // even when using file cache. This reduces hits from clients.
117 if ( $action != 'raw' && HTMLFileCache
::useFileCache() ) {
118 /* Try low-level file cache hit */
119 $cache = new HTMLFileCache( $wgTitle, $action );
120 if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
121 /* Check incoming headers to see if client has this cached */
122 if ( !$context->output
->checkLastModified( $cache->fileCacheTime() ) ) {
123 $cache->loadFromFileCache();
125 # Do any stats increment/watchlist stuff
126 $wgArticle = MediaWiki
::articleFromTitle( $wgTitle, $context );
127 $wgArticle->viewUpdates();
128 # Tell OutputPage that output is taken care of
129 $context->output
->disable();
130 wfProfileOut( 'index.php-filecache' );
131 $mediaWiki->finalCleanup();
132 wfProfileOut( 'index.php' );
133 $mediaWiki->restInPeace();
137 wfProfileOut( 'index.php-filecache' );
140 # Setting global variables in mediaWiki
141 $mediaWiki->setVal( 'DisableHardRedirects', $wgDisableHardRedirects );
142 $mediaWiki->setVal( 'EnableCreativeCommonsRdf', $wgEnableCreativeCommonsRdf );
143 $mediaWiki->setVal( 'EnableDublinCoreRdf', $wgEnableDublinCoreRdf );
144 $mediaWiki->setVal( 'Server', $wgServer );
145 $mediaWiki->setVal( 'SquidMaxage', $wgSquidMaxage );
146 $mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor );
147 $mediaWiki->setVal( 'UsePathInfo', $wgUsePathInfo );
149 $mediaWiki->performRequestForTitle( $wgArticle );
150 $mediaWiki->finalCleanup();
152 wfProfileOut( 'index.php' );
154 $mediaWiki->restInPeace();
157 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
158 * Does not assume access to *anything*; no globals, no autloader, no database, no localisation.
159 * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
160 * no longer need to be).
162 * Calling this function kills execution immediately.
164 * @param $errorMsg String fully-escaped HTML
166 function wfDie( $errorMsg ){
168 $version = htmlspecialchars( MW_VERSION
);
169 $logo = isset( $wgLogo ) && $wgLogo
171 : 'http://upload.wikimedia.org/wikipedia/commons/1/1c/MediaWiki_logo.png';
173 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
174 header( 'Content-type: text/html; charset=UTF-8' );
175 // Don't cache error pages! They cause no end of trouble...
176 header( 'Cache-control: none' );
177 header( 'Pragma: nocache' );
180 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
181 <html xmlns
='http://www.w3.org/1999/xhtml' lang
='en'>
183 <title
>MediaWiki
<?php
echo $version; ?
></title
>
184 <meta http
-equiv
='Content-Type' content
='text/html; charset=utf-8' />
185 <style type
='text/css' media
='screen'>
188 background
-color
: #fff;
189 font
-family
: sans
-serif
;
203 <img src
="<?php echo $logo; ?>" alt
='The MediaWiki logo' />
204 <h1
>MediaWiki
<?php
echo $version; ?
> internal error
</h1
>
205 <div
class='error'> <?php
echo $errorMsg; ?
> </div
>