r89513 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89512‎ | r89513 | r89514 >
Date:18:01, 5 June 2011
Author:reedy
Status:ok
Tags:
Comment:
Followup r89512

Apply the same positive integer validation to pageids (as the same behaviour can occur)

Refactor out common code, and reorganise initFromPageIds code to be similar to that of initFromRevIDs
Modified paths:
  • /trunk/phase3/includes/api/ApiPageSet.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiPageSet.php
@@ -447,6 +447,10 @@
448448 }
449449
450450 $pageids = array_map( 'intval', $pageids ); // paranoia
 451+ $remaining = array_flip( $pageids );
 452+
 453+ $pageids = self::getPositiveIntegers( $pageids );
 454+
451455 $set = array(
452456 'page_id' => $pageids
453457 );
@@ -458,7 +462,6 @@
459463 __METHOD__ );
460464 $this->profileDBOut();
461465
462 - $remaining = array_flip( $pageids );
463466 $this->initFromQueryResult( $res, $remaining, false ); // process PageIDs
464467
465468 // Resolve any found redirects
@@ -535,14 +538,7 @@
536539 $pageids = array();
537540 $remaining = array_flip( $revids );
538541
539 - // bug 25734 API: possible issue with revids validation
540 - // It seems with a load of revision rows, MySQL gets upset
541 - // Remove any < 0 revids, as they can't be valid
542 - foreach( $revids as $i => $revid ) {
543 - if ( $revid < 0 ) {
544 - unset( $revids[$i] );
545 - }
546 - }
 542+ $revids = self::getPositiveIntegers( $revids );
547543
548544 $tables = array( 'revision', 'page' );
549545 $fields = array( 'rev_id', 'rev_page' );
@@ -721,6 +717,25 @@
722718 return $linkBatch;
723719 }
724720
 721+ /**
 722+ * Returns the input array of integers with all values < 0 removed
 723+ *
 724+ * @param $array array
 725+ * @return array
 726+ */
 727+ private static function getPositiveIntegers( $array ) {
 728+ // bug 25734 API: possible issue with revids validation
 729+ // It seems with a load of revision rows, MySQL gets upset
 730+ // Remove any < 0 integers, as they can't be valid
 731+ foreach( $array as $i => $int ) {
 732+ if ( $int < 0 ) {
 733+ unset( $array[$i] );
 734+ }
 735+ }
 736+
 737+ return $array;
 738+ }
 739+
725740 protected function getAllowedParams() {
726741 return array(
727742 'titles' => array(

Follow-up revisions

RevisionCommit summaryAuthorDate
r89514MFT r89512, r89513reedy18:05, 5 June 2011
r89549follow up r89513: avoid internal error when only invalid revids/pageids are p...gurch08:45, 6 June 2011
r92339REL1_18 MFT r89401, r89451, r89512, r89513, r89523, r89529, r89532, r89549, r...reedy23:08, 15 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89512* (bug 25734) API: possible issue with revids validation...reedy17:49, 5 June 2011

Status & tagging log