r70078 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70077‎ | r70078 | r70079 >
Date:11:30, 28 July 2010
Author:btongminh
Status:ok
Tags:
Comment:
(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 (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBacklinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiResult.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBacklinks.php
@@ -203,7 +203,7 @@
204204 $botMax = ( $this->redirect ? ApiBase::LIMIT_BIG2 / 2 : ApiBase::LIMIT_BIG2 );
205205 if ( $this->params['limit'] == 'max' ) {
206206 $this->params['limit'] = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
207 - $this->getResult()->addValue( 'limits', $this->getModuleName(), $this->params['limit'] );
 207+ $this->getResult()->setParsedLimit( $this->getModuleName(), $this->params['limit'] );
208208 }
209209
210210 $this->processContinue();
Index: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -113,7 +113,7 @@
114114
115115 if ( $limit == 'max' ) {
116116 $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
117 - $this->getResult()->addValue( 'limits', $this->getModuleName(), $limit );
 117+ $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
118118 }
119119
120120 $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
Index: trunk/phase3/includes/api/ApiResult.php
@@ -141,13 +141,14 @@
142142 * @param $arr array to add $value to
143143 * @param $name string Index of $arr to add $value at
144144 * @param $value mixed
 145+ * @param $overwrite bool Whether overwriting an existing element is allowed
145146 */
146 - public static function setElement( &$arr, $name, $value ) {
 147+ public static function setElement( &$arr, $name, $value, $overwrite = false ) {
147148 if ( $arr === null || $name === null || $value === null || !is_array( $arr ) || is_array( $name ) ) {
148149 ApiBase::dieDebug( __METHOD__, 'Bad parameter' );
149150 }
150151
151 - if ( !isset ( $arr[$name] ) ) {
 152+ if ( !isset ( $arr[$name] ) || $overwrite ) {
152153 $arr[$name] = $value;
153154 } elseif ( is_array( $arr[$name] ) && is_array( $value ) ) {
154155 $merged = array_intersect_key( $arr[$name], $value );
@@ -250,7 +251,7 @@
251252 * If $name is empty, the $value is added as a next list element data[] = $value
252253 * @return bool True if $value fits in the result, false if not
253254 */
254 - public function addValue( $path, $name, $value ) {
 255+ public function addValue( $path, $name, $value, $overwrite = false ) {
255256 global $wgAPIMaxResultSize;
256257 $data = &$this->mData;
257258 if ( $this->mCheckingSize ) {
@@ -280,10 +281,21 @@
281282 if ( !$name ) {
282283 $data[] = $value; // Add list element
283284 } else {
284 - ApiResult::setElement( $data, $name, $value ); // Add named element
 285+ self::setElement( $data, $name, $value, $overwrite ); // Add named element
285286 }
286287 return true;
287288 }
 289+
 290+ /**
 291+ * Add a parsed limit=max to the result.
 292+ *
 293+ * @param $moduleName string
 294+ * @param $limit int
 295+ */
 296+ public function setParsedLimit( $moduleName, $limit ) {
 297+ // Add value, allowing overwriting
 298+ $this->addValue( 'limits', $moduleName, $limit, true );
 299+ }
288300
289301 /**
290302 * Unset a value previously added to the result set.
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -204,7 +204,7 @@
205205 $limit = $params['limit'];
206206 if ( $limit == 'max' ) {
207207 $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
208 - $this->getResult()->addValue( 'limits', $this->getModuleName(), $limit );
 208+ $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
209209 }
210210
211211 if ( $enumRevMode ) {
Index: trunk/phase3/includes/api/ApiBase.php
@@ -682,7 +682,7 @@
683683 $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : 0;
684684 if ( $value == 'max' ) {
685685 $value = $this->getMain()->canApiHighLimits() ? $paramSettings[self::PARAM_MAX2] : $paramSettings[self::PARAM_MAX];
686 - $this->getResult()->addValue( 'limits', $this->getModuleName(), $value );
 686+ $this->getResult()->setParsedLimit( $this->getModuleName(), $value );
687687 } else {
688688 $value = intval( $value );
689689 $this->validateLimit( $paramName, $value, $min, $paramSettings[self::PARAM_MAX], $paramSettings[self::PARAM_MAX2] );
Index: trunk/phase3/RELEASE-NOTES
@@ -296,6 +296,8 @@
297297 * Fixed "link" parameter in image links with "thumb" parameter.
298298 * (bug 23936) Add "displaytitle" to query/info API
299299 * (bug 24485) Make iwbacklinks a generator, optionally display iwprefix and iwtitle
 300+* (bug 24564) Fix fatal errors when using list=deletedrevs, prop=revisions or
 301+ one of the backlinks generators with limit=max.
300302
301303 === Languages updated in 1.17 ===
302304

Follow-up revisions

RevisionCommit summaryAuthorDate
r70189MFT r70078: Fix fatal errors when using list=deletedrevs, prop=revisions or o...tstarling05:38, 30 July 2010
r70818MFT r70078 to REL1_15...reedy14:21, 10 August 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r70062Reintroduced the extractRequestParams() memoization as in r69782, but respect...tstarling04:12, 28 July 2010
r70066* MFT r70062: fix for bug 24564 (fatal error with limit=max)...tstarling05:52, 28 July 2010

Status & tagging log