Follow-up r85929: update MediaWiki::articleFromTitle() calls in extensions (and a...
[lhc/web/wiklou.git] / index.php
1 <?php
2 /**
3 * This is the main web entry point for MediaWiki.
4 *
5 * If you are reading this in your web browser, your server is probably
6 * not configured correctly to run PHP applications!
7 *
8 * See the README, INSTALL, and UPGRADE files for basic setup instructions
9 * and pointers to the online documentation.
10 *
11 * http://www.mediawiki.org/
12 *
13 * ----------
14 *
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.
20 *
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.
25 *
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.
30 *
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
35 *
36 * @file
37 */
38
39 // Bail on old versions of PHP. Pretty much every other file in the codebase
40 // has structures (try/catch, foo()->bar(), etc etc) which throw parse errors in PHP 4.
41 // Setup.php and ObjectCache.php have structures invalid in PHP 5.0 and 5.1, respectively.
42 if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.0' ) < 0 ) {
43 $phpversion = htmlspecialchars( phpversion() );
44 $errorMsg = <<<ENDL
45 <p>
46 MediaWiki requires PHP 5.2.3 or higher. You are running PHP $phpversion.
47 </p>
48 <p>
49 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
50 PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
51 security or bugfix updates.
52 </p>
53 <p>
54 If for some reason you are unable to upgrade your PHP version, you will need to
55 <a href="http://www.mediawiki.org/wiki/Download">download</a> an older version
56 of MediaWiki from our website. See our
57 <a href="http://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
58 for details of which versions are compatible with prior versions of PHP.
59 </p>
60 ENDL;
61 wfDie( $errorMsg );
62 }
63
64 # Initialise common code. This gives us access to GlobalFunctions, the AutoLoader, and
65 # the globals $wgRequest, $wgOut, $wgUser, $wgLang and $wgContLang, amongst others; it
66 # does *not* load $wgTitle or $wgArticle
67 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
68
69 wfProfileIn( 'index.php' );
70 wfProfileIn( 'index.php-setup' );
71
72 $maxLag = $wgRequest->getVal( 'maxlag' );
73 if ( !is_null( $maxLag ) ) {
74 $lb = wfGetLB(); // foo()->bar() is not supported in PHP4
75 list( $host, $lag ) = $lb->getMaxLag();
76 if ( $lag > $maxLag ) {
77 header( 'HTTP/1.1 503 Service Unavailable' );
78 header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
79 header( 'X-Database-Lag: ' . intval( $lag ) );
80 header( 'Content-Type: text/plain' );
81 if( $wgShowHostnames ) {
82 echo "Waiting for $host: $lag seconds lagged\n";
83 } else {
84 echo "Waiting for a database server: $lag seconds lagged\n";
85 }
86 exit;
87 }
88 }
89
90 # Initialize MediaWiki base class
91 $context = RequestContext::getMain();
92 $mediaWiki = new MediaWiki( $context );
93
94 # Set title from request parameters
95 $wgTitle = $mediaWiki->getTitle();
96 $action = $wgRequest->getVal( 'action', 'view' );
97
98 wfProfileOut( 'index.php-setup' );
99
100 # Send Ajax requests to the Ajax dispatcher.
101 if ( $wgUseAjax && $action == 'ajax' ) {
102 $dispatcher = new AjaxDispatcher();
103 $dispatcher->performAction();
104 wfProfileOut( 'index.php' );
105 $mediaWiki->restInPeace();
106 exit;
107 }
108
109 if ( $wgUseFileCache && $wgTitle !== null ) {
110 wfProfileIn( 'index.php-filecache' );
111 // Raw pages should handle cache control on their own,
112 // even when using file cache. This reduces hits from clients.
113 if ( $action != 'raw' && HTMLFileCache::useFileCache() ) {
114 /* Try low-level file cache hit */
115 $cache = new HTMLFileCache( $wgTitle, $action );
116 if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
117 /* Check incoming headers to see if client has this cached */
118 if ( !$context->output->checkLastModified( $cache->fileCacheTime() ) ) {
119 $cache->loadFromFileCache();
120 }
121 # Do any stats increment/watchlist stuff
122 $wgArticle = MediaWiki::articleFromTitle( $wgTitle, $context );
123 $wgArticle->viewUpdates();
124 # Tell OutputPage that output is taken care of
125 $context->output->disable();
126 wfProfileOut( 'index.php-filecache' );
127 $mediaWiki->finalCleanup();
128 wfProfileOut( 'index.php' );
129 $mediaWiki->restInPeace();
130 exit;
131 }
132 }
133 wfProfileOut( 'index.php-filecache' );
134 }
135
136 # Setting global variables in mediaWiki
137 $mediaWiki->setVal( 'DisableHardRedirects', $wgDisableHardRedirects );
138 $mediaWiki->setVal( 'EnableCreativeCommonsRdf', $wgEnableCreativeCommonsRdf );
139 $mediaWiki->setVal( 'EnableDublinCoreRdf', $wgEnableDublinCoreRdf );
140 $mediaWiki->setVal( 'Server', $wgServer );
141 $mediaWiki->setVal( 'SquidMaxage', $wgSquidMaxage );
142 $mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor );
143 $mediaWiki->setVal( 'UsePathInfo', $wgUsePathInfo );
144
145 $mediaWiki->performRequestForTitle( $wgArticle );
146 $mediaWiki->finalCleanup();
147
148 wfProfileOut( 'index.php' );
149
150 $mediaWiki->restInPeace();
151
152 /**
153 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
154 * Does not assume access to *anything*; no globals, no autloader, no database, no localisation.
155 * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
156 * no longer need to be).
157 *
158 * Calling this function kills execution immediately.
159 *
160 * @param $errorMsg String fully-escaped HTML
161 */
162 function wfDie( $errorMsg ){
163 // Use the version set in DefaultSettings if possible, but don't rely on it
164 global $wgVersion, $wgLogo;
165 $version = isset( $wgVersion ) && $wgVersion
166 ? htmlspecialchars( $wgVersion )
167 : '';
168 $logo = isset( $wgLogo ) && $wgLogo
169 ? $wgLogo
170 : 'http://upload.wikimedia.org/wikipedia/commons/1/1c/MediaWiki_logo.png';
171
172 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
173
174 ?>
175 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
176 <html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
177 <head>
178 <title>MediaWiki <?php echo $version; ?></title>
179 <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
180 <style type='text/css' media='screen'>
181 body {
182 color: #000;
183 background-color: #fff;
184 font-family: sans-serif;
185 padding: 2em;
186 text-align: center;
187 }
188 p, img, h1 {
189 text-align: left;
190 margin: 0.5em 0;
191 }
192 h1 {
193 font-size: 120%;
194 }
195 </style>
196 </head>
197 <body>
198 <img src="<?php echo $logo; ?>" alt='The MediaWiki logo' />
199 <h1>MediaWiki <?php echo $version; ?> internal error</h1>
200 <div class='error'> <?php echo $errorMsg; ?> </div>
201 </body>
202 </html>
203 <?php
204 die( 1 );
205 }