Followup r89512
authorSam Reed <reedy@users.mediawiki.org>
Sun, 5 Jun 2011 18:01:30 +0000 (18:01 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 5 Jun 2011 18:01:30 +0000 (18:01 +0000)
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

includes/api/ApiPageSet.php

index cfee7a4..862468d 100644 (file)
@@ -447,6 +447,10 @@ class ApiPageSet extends ApiQueryBase {
                }
 
                $pageids = array_map( 'intval', $pageids ); // paranoia
+               $remaining = array_flip( $pageids );
+
+               $pageids = self::getPositiveIntegers( $pageids );
+
                $set = array(
                        'page_id' => $pageids
                );
@@ -458,7 +462,6 @@ class ApiPageSet extends ApiQueryBase {
                                        __METHOD__ );
                $this->profileDBOut();
 
-               $remaining = array_flip( $pageids );
                $this->initFromQueryResult( $res, $remaining, false );  // process PageIDs
 
                // Resolve any found redirects
@@ -535,14 +538,7 @@ class ApiPageSet extends ApiQueryBase {
                $pageids = array();
                $remaining = array_flip( $revids );
 
-               // bug 25734 API: possible issue with revids validation
-               // It seems with a load of revision rows, MySQL gets upset
-               // Remove any < 0 revids, as they can't be valid
-               foreach( $revids as $i => $revid ) {
-                       if ( $revid < 0 ) {
-                               unset( $revids[$i] );
-                       }
-               }
+               $revids = self::getPositiveIntegers( $revids );
 
                $tables = array( 'revision', 'page' );
                $fields = array( 'rev_id', 'rev_page' );
@@ -721,6 +717,25 @@ class ApiPageSet extends ApiQueryBase {
                return $linkBatch;
        }
 
+       /**
+        * Returns the input array of integers with all values < 0 removed
+        *
+        * @param $array array
+        * @return array
+        */
+       private static function getPositiveIntegers( $array ) {
+               // bug 25734 API: possible issue with revids validation
+               // It seems with a load of revision rows, MySQL gets upset
+               // Remove any < 0 integers, as they can't be valid
+               foreach( $array as $i => $int ) {
+                       if ( $int < 0 ) {
+                               unset( $array[$i] );
+                       }
+               }
+
+               return $array;
+       }
+
        protected function getAllowedParams() {
                return array(
                        'titles' => array(