Revert r88648 per CR
[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.3' ) < 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
67 if ( isset( $_SERVER['MW_COMPILED'] ) ) {
68 require ( 'phase3/includes/WebStart.php' );
69 } else {
70 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
71 }
72
73 try {
74 wfIndexMain();
75 } catch ( Exception $e ) {
76 MWExceptionHandler::handle( $e );
77 }
78
79 function wfIndexMain() {
80 global $wgRequest, $wgShowHostnames, $mediaWiki, $wgTitle, $wgUseAjax, $wgUseFileCache;
81
82 wfProfileIn( 'index.php' );
83 wfProfileIn( 'index.php-setup' );
84
85 $maxLag = $wgRequest->getVal( 'maxlag' );
86 if ( !is_null( $maxLag ) ) {
87 $lb = wfGetLB(); // foo()->bar() is not supported in PHP4
88 list( $host, $lag ) = $lb->getMaxLag();
89 if ( $lag > $maxLag ) {
90 header( 'HTTP/1.1 503 Service Unavailable' );
91 header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
92 header( 'X-Database-Lag: ' . intval( $lag ) );
93 header( 'Content-Type: text/plain' );
94 if( $wgShowHostnames ) {
95 echo "Waiting for $host: $lag seconds lagged\n";
96 } else {
97 echo "Waiting for a database server: $lag seconds lagged\n";
98 }
99 wfProfileOut( 'index.php-setup' );
100 wfProfileOut( 'index.php' );
101 exit;
102 }
103 }
104
105 # Initialize MediaWiki base class
106 $context = RequestContext::getMain();
107 $mediaWiki = new MediaWiki( $context );
108
109 # Set title from request parameters
110 $wgTitle = $mediaWiki->getTitle();
111 $action = $wgRequest->getVal( 'action', 'view' );
112
113 wfProfileOut( 'index.php-setup' );
114
115 # Send Ajax requests to the Ajax dispatcher.
116 if ( $wgUseAjax && $action == 'ajax' ) {
117 $dispatcher = new AjaxDispatcher();
118 $dispatcher->performAction();
119 wfProfileOut( 'index.php' );
120 $mediaWiki->restInPeace();
121 exit;
122 }
123
124 if ( $wgUseFileCache && $wgTitle !== null ) {
125 wfProfileIn( 'index.php-filecache' );
126 // Raw pages should handle cache control on their own,
127 // even when using file cache. This reduces hits from clients.
128 if ( $action != 'raw' && HTMLFileCache::useFileCache() ) {
129 /* Try low-level file cache hit */
130 $cache = new HTMLFileCache( $wgTitle, $action );
131 if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
132 /* Check incoming headers to see if client has this cached */
133 if ( !$context->output->checkLastModified( $cache->fileCacheTime() ) ) {
134 $cache->loadFromFileCache();
135 }
136 # Do any stats increment/watchlist stuff
137 $article = Article::newFromTitle( $wgTitle, $context );
138 $article->viewUpdates();
139 # Tell OutputPage that output is taken care of
140 $context->output->disable();
141 wfProfileOut( 'index.php-filecache' );
142 $mediaWiki->finalCleanup();
143 wfProfileOut( 'index.php' );
144 $mediaWiki->restInPeace();
145 exit;
146 }
147 }
148 wfProfileOut( 'index.php-filecache' );
149 }
150
151 /**
152 * $wgArticle is deprecated, do not use it. This will possibly be removed
153 * entirely in 1.20 or 1.21
154 * @deprecated since 1.19
155 */
156 global $wgArticle;
157
158 $wgArticle = $mediaWiki->performRequest();
159
160 $mediaWiki->finalCleanup();
161
162 wfProfileOut( 'index.php' );
163
164 $mediaWiki->restInPeace();
165 }
166
167 /**
168 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
169 * Does not assume access to *anything*; no globals, no autloader, no database, no localisation.
170 * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
171 * no longer need to be).
172 *
173 * Calling this function kills execution immediately.
174 *
175 * @param $errorMsg String fully-escaped HTML
176 */
177 function wfDie( $errorMsg ){
178 // Use the version set in DefaultSettings if possible, but don't rely on it
179 global $wgVersion, $wgLogo;
180 $version = isset( $wgVersion ) && $wgVersion
181 ? htmlspecialchars( $wgVersion )
182 : '';
183 $logo = isset( $wgLogo ) && $wgLogo
184 ? $wgLogo
185 : 'http://upload.wikimedia.org/wikipedia/commons/1/1c/MediaWiki_logo.png';
186
187 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
188 header( 'Content-type: text/html; charset=UTF-8' );
189 // Don't cache error pages! They cause no end of trouble...
190 header( 'Cache-control: none' );
191 header( 'Pragma: nocache' );
192
193 ?>
194 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
195 <html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
196 <head>
197 <title>MediaWiki <?php echo $version; ?></title>
198 <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
199 <style type='text/css' media='screen'>
200 body {
201 color: #000;
202 background-color: #fff;
203 font-family: sans-serif;
204 padding: 2em;
205 text-align: center;
206 }
207 p, img, h1 {
208 text-align: left;
209 margin: 0.5em 0;
210 }
211 h1 {
212 font-size: 120%;
213 }
214 </style>
215 </head>
216 <body>
217 <img src="<?php echo $logo; ?>" alt='The MediaWiki logo' />
218 <h1>MediaWiki <?php echo $version; ?> internal error</h1>
219 <div class='error'> <?php echo $errorMsg; ?> </div>
220 </body>
221 </html>
222 <?php
223 die( 1 );
224 }