From 4895ce631f46dfd946f0cf792278bd127b1cbb47 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Mon, 19 Nov 2007 15:57:58 +0000 Subject: [PATCH] Revert part of Brion's 27627: please don't throw away the child (maxlag) with the bathwater (format=raw) --- RELEASE-NOTES | 1 + includes/GlobalFunctions.php | 20 ++++++++++++++++++++ includes/Wiki.php | 12 ++---------- includes/api/ApiBase.php | 8 ++++++++ includes/api/ApiHelp.php | 4 ++++ includes/api/ApiMain.php | 23 +++++++++++++++++++++-- includes/api/ApiQuery.php | 5 +++++ 7 files changed, 61 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index fa2c3eccf3..2dae069955 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -194,6 +194,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API * (bug 11562) Added a user_registration parameter/field to the list=allusers query. * (bug 11588) Preserve document structure for empty dataset in backlinks query. * Outputting list of all user preferences rather than having to request them by name +* (bug 11206) api.php should honor maxlag === Languages updated in 1.12 === diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 008a6d2b4f..fa3eb03502 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2335,4 +2335,24 @@ function wfGetNull() { return wfIsWindows() ? 'NUL' : '/dev/null'; +} + +/** + * Displays a maxlag error + * + * @param string $host Server that lags the most + * @param int $lag Maxlag (actual) + * @param int $maxLag 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"; + } } \ No newline at end of file diff --git a/includes/Wiki.php b/includes/Wiki.php index 02f9430543..4920ff2b21 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -57,18 +57,10 @@ class MediaWiki { } function checkMaxLag( $maxLag ) { - global $wgLoadBalancer, $wgShowHostnames; + global $wgLoadBalancer; list( $host, $lag ) = $wgLoadBalancer->getMaxLag(); if ( $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"; - } + wfMaxlagError( $host, $lag, $maxLag ); return false; } else { return true; diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 37bd4e767a..6c97a5bec9 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -509,6 +509,14 @@ abstract class ApiBase { wfDebugDieBacktrace("Internal error in $method: $message"); } + /** + * 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 406d23a018..6ce44a6bcf 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -289,6 +289,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) { @@ -348,7 +363,10 @@ class ApiMain extends ApiBase { ApiBase :: PARAM_DFLT => 'help', ApiBase :: PARAM_TYPE => $this->mModuleNames ), - 'version' => false + 'version' => false, + 'maxlag' => array ( + ApiBase :: PARAM_TYPE => 'integer' + ), ); } @@ -359,7 +377,8 @@ class ApiMain extends ApiBase { return array ( 'format' => 'The format of the output', 'action' => 'What action you would like to perform', - 'version' => 'When showing help, include version for each module' + 'version' => 'When showing help, include version for each module', + 'maxlag' => 'Maximum lag' ); } 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