http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70078

Revision: 70078
Author:   btongminh
Date:     2010-07-28 11:30:14 +0000 (Wed, 28 Jul 2010)

Log Message:
-----------
(bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or one 
of the backlinks generators with limit=max.

Modified Paths:
--------------
    trunk/phase3/RELEASE-NOTES
    trunk/phase3/includes/api/ApiBase.php
    trunk/phase3/includes/api/ApiQueryBacklinks.php
    trunk/phase3/includes/api/ApiQueryDeletedrevs.php
    trunk/phase3/includes/api/ApiQueryRevisions.php
    trunk/phase3/includes/api/ApiResult.php

Modified: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES  2010-07-28 11:15:45 UTC (rev 70077)
+++ trunk/phase3/RELEASE-NOTES  2010-07-28 11:30:14 UTC (rev 70078)
@@ -296,6 +296,8 @@
 * 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 ===
 

Modified: trunk/phase3/includes/api/ApiBase.php
===================================================================
--- trunk/phase3/includes/api/ApiBase.php       2010-07-28 11:15:45 UTC (rev 
70077)
+++ trunk/phase3/includes/api/ApiBase.php       2010-07-28 11:30:14 UTC (rev 
70078)
@@ -682,7 +682,7 @@
                                                $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] );

Modified: trunk/phase3/includes/api/ApiQueryBacklinks.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryBacklinks.php     2010-07-28 11:15:45 UTC 
(rev 70077)
+++ trunk/phase3/includes/api/ApiQueryBacklinks.php     2010-07-28 11:30:14 UTC 
(rev 70078)
@@ -203,7 +203,7 @@
                $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();

Modified: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryDeletedrevs.php   2010-07-28 11:15:45 UTC 
(rev 70077)
+++ trunk/phase3/includes/api/ApiQueryDeletedrevs.php   2010-07-28 11:30:14 UTC 
(rev 70078)
@@ -113,7 +113,7 @@
 
                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 );

Modified: trunk/phase3/includes/api/ApiQueryRevisions.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryRevisions.php     2010-07-28 11:15:45 UTC 
(rev 70077)
+++ trunk/phase3/includes/api/ApiQueryRevisions.php     2010-07-28 11:30:14 UTC 
(rev 70078)
@@ -204,7 +204,7 @@
                $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 ) {

Modified: trunk/phase3/includes/api/ApiResult.php
===================================================================
--- trunk/phase3/includes/api/ApiResult.php     2010-07-28 11:15:45 UTC (rev 
70077)
+++ trunk/phase3/includes/api/ApiResult.php     2010-07-28 11:30:14 UTC (rev 
70078)
@@ -141,13 +141,14 @@
         * @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 @@
         * 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 @@
                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.



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to