From d7908b82e0e852e6610336fe7110d7ccda9c9bb4 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Mon, 19 Nov 2007 15:08:18 +0000 Subject: [PATCH] * Use ApiBase::dieDebug() to render maxlag error properly * Allow modules to ignore maxlag attribute --- includes/api/ApiBase.php | 8 ++++++++ includes/api/ApiHelp.php | 4 ++++ includes/api/ApiMain.php | 26 +++++++++++++++----------- includes/api/ApiQuery.php | 5 +++++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 585b22ee68..684ba0cd73 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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 */ diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php index aeebb50477..21150a6d11 100644 --- a/includes/api/ApiHelp.php +++ b/includes/api/ApiHelp.php @@ -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.' diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index f26f52c984..d80928e3b4 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -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) { diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 0223f6fb79..1b1c3b3fb6 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -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 ( -- 2.20.1