From: Bryan Tong Minh Date: Wed, 28 Jul 2010 11:30:14 +0000 (+0000) Subject: (bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or one of... X-Git-Tag: 1.31.0-rc.0~35868 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=0e61296f98556e8a27232051fcc7b12fc6cc95fa;p=lhc%2Fweb%2Fwiklou.git (bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or one of the backlinks generators with limit=max. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index ddbad62c27..255afa5eff 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -296,6 +296,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Fixed "link" parameter in image links with "thumb" parameter. * (bug 23936) Add "displaytitle" to query/info API * (bug 24485) Make iwbacklinks a generator, optionally display iwprefix and iwtitle +* (bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or + one of the backlinks generators with limit=max. === Languages updated in 1.17 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 698b2cdfcf..b28224b93f 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -682,7 +682,7 @@ abstract class ApiBase { $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : 0; if ( $value == 'max' ) { $value = $this->getMain()->canApiHighLimits() ? $paramSettings[self::PARAM_MAX2] : $paramSettings[self::PARAM_MAX]; - $this->getResult()->addValue( 'limits', $this->getModuleName(), $value ); + $this->getResult()->setParsedLimit( $this->getModuleName(), $value ); } else { $value = intval( $value ); $this->validateLimit( $paramName, $value, $min, $paramSettings[self::PARAM_MAX], $paramSettings[self::PARAM_MAX2] ); diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index 1ab0c67a29..4a15e45ea8 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -203,7 +203,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $botMax = ( $this->redirect ? ApiBase::LIMIT_BIG2 / 2 : ApiBase::LIMIT_BIG2 ); if ( $this->params['limit'] == 'max' ) { $this->params['limit'] = $this->getMain()->canApiHighLimits() ? $botMax : $userMax; - $this->getResult()->addValue( 'limits', $this->getModuleName(), $this->params['limit'] ); + $this->getResult()->setParsedLimit( $this->getModuleName(), $this->params['limit'] ); } $this->processContinue(); diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index d7fb5304fd..5062530134 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -113,7 +113,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { if ( $limit == 'max' ) { $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax; - $this->getResult()->addValue( 'limits', $this->getModuleName(), $limit ); + $this->getResult()->setParsedLimit( $this->getModuleName(), $limit ); } $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax ); diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index aefc647c9c..2b95d32478 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -204,7 +204,7 @@ class ApiQueryRevisions extends ApiQueryBase { $limit = $params['limit']; if ( $limit == 'max' ) { $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax; - $this->getResult()->addValue( 'limits', $this->getModuleName(), $limit ); + $this->getResult()->setParsedLimit( $this->getModuleName(), $limit ); } if ( $enumRevMode ) { diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index f97bac7368..8c86c36af8 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -141,13 +141,14 @@ class ApiResult extends ApiBase { * @param $arr array to add $value to * @param $name string Index of $arr to add $value at * @param $value mixed + * @param $overwrite bool Whether overwriting an existing element is allowed */ - public static function setElement( &$arr, $name, $value ) { + public static function setElement( &$arr, $name, $value, $overwrite = false ) { if ( $arr === null || $name === null || $value === null || !is_array( $arr ) || is_array( $name ) ) { ApiBase::dieDebug( __METHOD__, 'Bad parameter' ); } - if ( !isset ( $arr[$name] ) ) { + if ( !isset ( $arr[$name] ) || $overwrite ) { $arr[$name] = $value; } elseif ( is_array( $arr[$name] ) && is_array( $value ) ) { $merged = array_intersect_key( $arr[$name], $value ); @@ -250,7 +251,7 @@ class ApiResult extends ApiBase { * If $name is empty, the $value is added as a next list element data[] = $value * @return bool True if $value fits in the result, false if not */ - public function addValue( $path, $name, $value ) { + public function addValue( $path, $name, $value, $overwrite = false ) { global $wgAPIMaxResultSize; $data = &$this->mData; if ( $this->mCheckingSize ) { @@ -280,10 +281,21 @@ class ApiResult extends ApiBase { if ( !$name ) { $data[] = $value; // Add list element } else { - ApiResult::setElement( $data, $name, $value ); // Add named element + self::setElement( $data, $name, $value, $overwrite ); // Add named element } return true; } + + /** + * Add a parsed limit=max to the result. + * + * @param $moduleName string + * @param $limit int + */ + public function setParsedLimit( $moduleName, $limit ) { + // Add value, allowing overwriting + $this->addValue( 'limits', $moduleName, $limit, true ); + } /** * Unset a value previously added to the result set.