Expand wfShowMaxLagError() into index.php. It was only being called from here and...
[lhc/web/wiklou.git] / index.php
1 <?php
2
3 /**
4 * This is the main web entry point for MediaWiki.
5 *
6 * If you are reading this in your web browser, your server is probably
7 * not configured correctly to run PHP applications!
8 *
9 * See the README, INSTALL, and UPGRADE files for basic setup instructions
10 * and pointers to the online documentation.
11 *
12 * http://www.mediawiki.org/
13 *
14 * ----------
15 *
16 * Copyright (C) 2001-2011 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
17 * Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
18 * Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor,
19 * Aaron Schulz, Andrew Garrett, Raimond Spekking, Alexandre Emsenhuber
20 * Siebrand Mazeland, Chad Horohoe, Roan Kattouw and others.
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License along
33 * with this program; if not, write to the Free Software Foundation, Inc.,
34 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
35 * http://www.gnu.org/copyleft/gpl.html
36 *
37 * @file
38 */
39
40 # Initialise common code. This gives us access to GlobalFunctions, the AutoLoader, and
41 # the globals $wgRequest, $wgOut, $wgUser, $wgLang and $wgContLang, amongst others; it
42 # does *not* load $wgTitle or $wgArticle
43 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
44
45 wfProfileIn( 'index.php' );
46 wfProfileIn( 'index.php-setup' );
47
48 $maxLag = $wgRequest->getVal( 'maxlag' );
49 if ( !is_null( $maxLag ) ) {
50 list( $host, $lag ) = wfGetLB()->getMaxLag();
51 if ( $lag > $maxLag ) {
52 header( 'HTTP/1.1 503 Service Unavailable' );
53 header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
54 header( 'X-Database-Lag: ' . intval( $lag ) );
55 header( 'Content-Type: text/plain' );
56 if( $wgShowHostnames ) {
57 echo "Waiting for $host: $lag seconds lagged\n";
58 } else {
59 echo "Waiting for a database server: $lag seconds lagged\n";
60 }
61 exit;
62 }
63 }
64
65 # Initialize MediaWiki base class
66 $mediaWiki = new MediaWiki( $wgRequest, $wgOut );
67
68 # Set title from request parameters
69 $wgTitle = $mediaWiki->checkInitialQueries();
70 $action = $wgRequest->getVal( 'action', 'view' );
71
72 wfProfileOut( 'index.php-setup' );
73
74 # Send Ajax requests to the Ajax dispatcher.
75 if ( $wgUseAjax && $action == 'ajax' ) {
76 $dispatcher = new AjaxDispatcher();
77 $dispatcher->performAction();
78 wfProfileOut( 'index.php' );
79 $mediaWiki->restInPeace();
80 exit;
81 }
82
83 if ( $wgUseFileCache && $wgTitle !== null ) {
84 wfProfileIn( 'index.php-filecache' );
85 // Raw pages should handle cache control on their own,
86 // even when using file cache. This reduces hits from clients.
87 if ( $action != 'raw' && HTMLFileCache::useFileCache() ) {
88 /* Try low-level file cache hit */
89 $cache = new HTMLFileCache( $wgTitle, $action );
90 if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
91 /* Check incoming headers to see if client has this cached */
92 if ( !$wgOut->checkLastModified( $cache->fileCacheTime() ) ) {
93 $cache->loadFromFileCache();
94 }
95 # Do any stats increment/watchlist stuff
96 $wgArticle = MediaWiki::articleFromTitle( $wgTitle );
97 $wgArticle->viewUpdates();
98 # Tell $wgOut that output is taken care of
99 $wgOut->disable();
100 wfProfileOut( 'index.php-filecache' );
101 $mediaWiki->finalCleanup();
102 wfProfileOut( 'index.php' );
103 $mediaWiki->restInPeace();
104 exit;
105 }
106 }
107 wfProfileOut( 'index.php-filecache' );
108 }
109
110 # Setting global variables in mediaWiki
111 $mediaWiki->setVal( 'DisableHardRedirects', $wgDisableHardRedirects );
112 $mediaWiki->setVal( 'EnableCreativeCommonsRdf', $wgEnableCreativeCommonsRdf );
113 $mediaWiki->setVal( 'EnableDublinCoreRdf', $wgEnableDublinCoreRdf );
114 $mediaWiki->setVal( 'Server', $wgServer );
115 $mediaWiki->setVal( 'SquidMaxage', $wgSquidMaxage );
116 $mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor );
117 $mediaWiki->setVal( 'UsePathInfo', $wgUsePathInfo );
118
119 $mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgUser );
120 $mediaWiki->finalCleanup();
121
122 wfProfileOut( 'index.php' );
123
124 $mediaWiki->restInPeace();