API: * BREAKING CHANGE: (bug 16074) Providing prop=revisions&rvprop=content with...
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 24 Oct 2008 13:05:44 +0000 (13:05 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 24 Oct 2008 13:05:44 +0000 (13:05 +0000)
* Added ApiBase::truncateArray() and used it in ApiBase::parseMultiValue()

RELEASE-NOTES
includes/api/ApiBase.php
includes/api/ApiQueryRevisions.php

index d789577..0e33791 100644 (file)
@@ -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 ===
 
index b26a6b3..fafecfe 100644 (file)
@@ -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
index 72fcea7..a6818c5 100644 (file)
@@ -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;