From 3319058b88f6794c90bddaf888ca1c4b07767ff3 Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Sun, 3 Apr 2011 20:43:50 +0000 Subject: [PATCH] Expand wfShowMaxLagError() into index.php. It was only being called from here and it's pretty non-portable. Doing so reveals that it's safe to move the declaration of $mediaWiki below the maxlag test, which will fractionally improve performance in that instance (partly compensating for having to parse OutputPage as introduced in r85278). --- includes/GlobalFunctions.php | 20 -------------------- index.php | 20 +++++++++++++++----- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 9dbbe54ed3..8520ec8f8a 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3060,26 +3060,6 @@ function wfGetNull() { : '/dev/null'; } -/** - * Displays a maxlag error - * - * @param $host String: server that lags the most - * @param $lag Integer: maxlag (actual) - * @param $maxLag Integer: maxlag (requested) - */ -function wfMaxlagError( $host, $lag, $maxLag ) { - global $wgShowHostnames; - header( 'HTTP/1.1 503 Service Unavailable' ); - header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) ); - header( 'X-Database-Lag: ' . intval( $lag ) ); - header( 'Content-Type: text/plain' ); - if( $wgShowHostnames ) { - echo "Waiting for $host: $lag seconds lagged\n"; - } else { - echo "Waiting for a database server: $lag seconds lagged\n"; - } -} - /** * Throws a warning that $function is deprecated * @param $function String diff --git a/index.php b/index.php index 7184ebf34a..38538cf2d2 100644 --- a/index.php +++ b/index.php @@ -37,24 +37,34 @@ * @file */ -# Initialise common code +# Initialise common code. This gives us access to GlobalFunctions, the AutoLoader, and +# the globals $wgRequest, $wgOut, $wgUser, $wgLang and $wgContLang, amongst others; it +# does *not* load $wgTitle or $wgArticle require ( dirname( __FILE__ ) . '/includes/WebStart.php' ); wfProfileIn( 'index.php' ); wfProfileIn( 'index.php-setup' ); -# Initialize MediaWiki base class -$mediaWiki = new MediaWiki( $wgRequest, $wgOut ); - $maxLag = $wgRequest->getVal( 'maxlag' ); if ( !is_null( $maxLag ) ) { list( $host, $lag ) = wfGetLB()->getMaxLag(); if ( $lag > $maxLag ) { - wfMaxlagError( $host, $lag, $maxLag ); + header( 'HTTP/1.1 503 Service Unavailable' ); + header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) ); + header( 'X-Database-Lag: ' . intval( $lag ) ); + header( 'Content-Type: text/plain' ); + if( $wgShowHostnames ) { + echo "Waiting for $host: $lag seconds lagged\n"; + } else { + echo "Waiting for a database server: $lag seconds lagged\n"; + } exit; } } +# Initialize MediaWiki base class +$mediaWiki = new MediaWiki( $wgRequest, $wgOut ); + # Set title from request parameters $wgTitle = $mediaWiki->checkInitialQueries(); $action = $wgRequest->getVal( 'action', 'view' ); -- 2.20.1