(bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or one of...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 28 Jul 2010 11:30:14 +0000 (11:30 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 28 Jul 2010 11:30:14 +0000 (11:30 +0000)
RELEASE-NOTES
includes/api/ApiBase.php
includes/api/ApiQueryBacklinks.php
includes/api/ApiQueryDeletedrevs.php
includes/api/ApiQueryRevisions.php
includes/api/ApiResult.php

index ddbad62..255afa5 100644 (file)
@@ -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 ===
 
index 698b2cd..b28224b 100644 (file)
@@ -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] );
index 1ab0c67..4a15e45 100644 (file)
@@ -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();
index d7fb530..5062530 100644 (file)
@@ -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 );
index aefc647..2b95d32 100644 (file)
@@ -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 ) {
index f97bac7..8c86c36 100644 (file)
@@ -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.