* Use ApiBase::dieDebug() to render maxlag error properly
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Mon, 19 Nov 2007 15:08:18 +0000 (15:08 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Mon, 19 Nov 2007 15:08:18 +0000 (15:08 +0000)
* Allow modules to ignore maxlag attribute

includes/api/ApiBase.php
includes/api/ApiHelp.php
includes/api/ApiMain.php
includes/api/ApiQuery.php

index 585b22e..684ba0c 100644 (file)
@@ -532,6 +532,14 @@ abstract class ApiBase {
                return $this->mRawFormat;
        }
 
+       /**
+        * Indicates if API needs to check maxlag
+        */
+       public function shouldCheckMaxlag() {
+               return true;
+       }
+
+
        /**
         * Profiling: total module execution time
         */
index aeebb50..21150a6 100644 (file)
@@ -46,6 +46,10 @@ class ApiHelp extends ApiBase {
                $this->dieUsage('', 'help');
        }
 
+       public function shouldCheckMaxlag() {
+               return false;
+       }
+
        protected function getDescription() {
                return array (
                        'Display this help screen.'
index f26f52c..d80928e 100644 (file)
@@ -186,17 +186,6 @@ class ApiMain extends ApiBase {
         * have been accumulated, and replace it with an error message and a help screen.
         */
        protected function executeActionWithErrorHandling() {
-               $params = $this->extractRequestParams();
-               if( isset( $params['maxlag'] ) ) {
-                       // Check for maxlag
-                       global $wgLoadBalancer;
-                       $maxLag = $params['maxlag'];
-                       list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
-                       if ( $lag > $maxLag ) {
-                               wfMaxlagError( $host, $lag, $maxLag );
-                               return;
-                       }
-               }
 
                // In case an error occurs during data output,
                // clear the output buffer and print just the error information
@@ -301,6 +290,21 @@ class ApiMain extends ApiBase {
 
                // Instantiate the module requested by the user
                $module = new $this->mModules[$this->mAction] ($this, $this->mAction);
+               
+               if( $module->shouldCheckMaxlag() && isset( $params['maxlag'] ) ) {
+                       // Check for maxlag
+                       global $wgLoadBalancer, $wgShowHostnames;
+                       $maxLag = $params['maxlag'];
+                       list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
+                       if ( $lag > $maxLag ) {
+                               if( $wgShowHostnames ) {
+                                       ApiBase :: dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
+                               } else {
+                                       ApiBase :: dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
+                               }
+                               return;
+                       }
+               }
 
                if (!$this->mInternalMode) {
 
index 0223f6f..1b1c3b3 100644 (file)
@@ -456,6 +456,11 @@ class ApiQuery extends ApiBase {
                $psModule = new ApiPageSet($this);
                return $psModule->makeHelpMsgParameters() . parent :: makeHelpMsgParameters();
        }
+       
+       // @todo should work correctly
+       public function shouldCheckMaxlag() {
+               return true;
+       }
 
        protected function getParamDescription() {
                return array (