From: Tim Starling Date: Sun, 22 Apr 2007 21:17:10 +0000 (+0000) Subject: maxlag hidden parameter. Allows client-side bots to throttle under slave lag conditio... X-Git-Tag: 1.31.0-rc.0~53283 X-Git-Url: http://git.cyclocoop.org//%22javascript:ModifierStyle%28%27%22.%24id.%22%27%29/%22?a=commitdiff_plain;h=916997d6f65f4bb1d65fe44305cfe3db8ac4a0d8;p=lhc%2Fweb%2Fwiklou.git maxlag hidden parameter. Allows client-side bots to throttle under slave lag conditions, just like server-side maintenance scripts. --- diff --git a/includes/Wiki.php b/includes/Wiki.php index 9437ce40f9..51a88693fa 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -56,6 +56,20 @@ class MediaWiki { return $article; } + function checkMaxLag( $maxLag ) { + global $wgLoadBalancer; + list( $host, $lag ) = $wgLoadBalancer->getMaxLag(); + if ( $lag > $maxLag ) { + header( 'HTTP/1.1 500 Internal server error' ); + header( 'Content-Type: text/plain' ); + echo "Waiting for $host: $lag seconds lagged\n"; + return false; + } else { + return true; + } + } + + /** * Checks some initial queries * Note that $title here is *not* a Title object, but a string! diff --git a/index.php b/index.php index 6b4cab0558..959fe7ff4c 100644 --- a/index.php +++ b/index.php @@ -44,6 +44,13 @@ $mediaWiki = new MediaWiki(); wfProfileIn( 'main-misc-setup' ); OutputPage::setEncodings(); # Not really used yet +$maxLag = $wgRequest->getVal( 'maxlag' ); +if ( !is_null( $maxLag ) ) { + if ( !$mediaWiki->checkMaxLag( $maxLag ) ) { + exit; + } +} + # Query string fields $action = $wgRequest->getVal( 'action', 'view' ); $title = $wgRequest->getVal( 'title' );