maxlag hidden parameter. Allows client-side bots to throttle under slave lag conditio...
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 22 Apr 2007 21:17:10 +0000 (21:17 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 22 Apr 2007 21:17:10 +0000 (21:17 +0000)
includes/Wiki.php
index.php

index 9437ce4..51a8869 100644 (file)
@@ -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!
index 6b4cab0..959fe7f 100644 (file)
--- 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' );