From: Roan Kattouw Date: Fri, 24 Oct 2008 13:05:44 +0000 (+0000) Subject: API: * BREAKING CHANGE: (bug 16074) Providing prop=revisions&rvprop=content with... X-Git-Tag: 1.31.0-rc.0~44627 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=6ad1e45cd94c77264dc9385209c3c6c4d55c2113;p=lhc%2Fweb%2Fwiklou.git API: * BREAKING CHANGE: (bug 16074) Providing prop=revisions&rvprop=content with too many titles or revisions (typically through a generator) no longer causes an error, but a warning * Added ApiBase::truncateArray() and used it in ApiBase::parseMultiValue() --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index d7895773cb..0e33791d54 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -361,6 +361,8 @@ The following extensions are migrated into MediaWiki 1.14: * (bug 16047) Added activeusers attribute to meta=siteinfo&siprop=statistics output * Added redirect resolution to action=parse +* (bug 16074) rvprop=content combined with a generator with a high limit causes + an error === Languages updated in 1.14 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index b26a6b3d47..fafecfe7bd 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -562,9 +562,7 @@ abstract class ApiBase { return array(); $sizeLimit = $this->mMainModule->canApiHighLimits() ? self::LIMIT_SML2 : self::LIMIT_SML1; $valuesList = explode('|', $value, $sizeLimit + 1); - if( count($valuesList) == $sizeLimit + 1 ) { - $junk = array_pop($valuesList); // kill last jumbled param - // Set a warning too + if( self::truncateArray($valuesList, $sizeLimit) ) { $this->setWarning("Too many values supplied for parameter '$valueName': the limit is $sizeLimit"); } if (!$allowMultiple && count($valuesList) != 1) { @@ -616,6 +614,23 @@ abstract class ApiBase { } } } + + /** + * Truncate an array to a certain length. + * @param $arr array Array to truncate + * @param $limit int Maximum length + * @return bool True if the array was truncated, false otherwise + */ + public static function truncateArray(&$arr, $limit) + { + $modified = false; + while(count($arr) > $limit) + { + $junk = array_pop($arr); + $modified = true; + } + return $modified; + } /** * Call main module's error handler diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 72fcea78d3..a6818c5db2 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -189,23 +189,30 @@ class ApiQueryRevisions extends ApiQueryBase { } } elseif ($revCount > 0) { - $this->validateLimit('rev_count', $revCount, 1, $userMax, $botMax); + $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax; + $revs = $pageSet->getRevisionIDs(); + if(self::truncateArray($revs, $max)) + $this->setWarning("Too many values supplied for parameter 'revids': the limit is $max"); // Get all revision IDs - $this->addWhereFld('rev_id', array_keys($pageSet->getRevisionIDs())); + $this->addWhereFld('rev_id', array_keys($revs)); // assumption testing -- we should never get more then $revCount rows. $limit = $revCount; } elseif ($pageCount > 0) { + $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax; + $titles = $pageSet->getGoodTitles(); + if(self::truncateArray($titles, $max)) + $this->setWarning("Too many values supplied for parameter 'titles': the limit is $max"); + // When working in multi-page non-enumeration mode, // limit to the latest revision only $this->addWhere('page_id=rev_page'); $this->addWhere('page_latest=rev_id'); - $this->validateLimit('page_count', $pageCount, 1, $userMax, $botMax); - + // Get all page IDs - $this->addWhereFld('page_id', array_keys($pageSet->getGoodTitles())); + $this->addWhereFld('page_id', array_keys($titles)); // assumption testing -- we should never get more then $pageCount rows. $limit = $pageCount;