Merge "Delete UIDGenerator cache files after unit tests"
[lhc/web/wiklou.git] / includes / api / ApiPageSet.php
index 0d733a2..c712539 100644 (file)
@@ -39,7 +39,6 @@
  * @since 1.21 derives from ApiBase instead of ApiQueryBase
  */
 class ApiPageSet extends ApiBase {
-
        /**
         * Constructor flag: The new instance of ApiPageSet will ignore the 'generator=' parameter
         * @since 1.21
@@ -74,6 +73,30 @@ class ApiPageSet extends ApiBase {
         */
        private $mDefaultNamespace = NS_MAIN;
 
+       /**
+        * Add all items from $values into the result
+        * @param array $result output
+        * @param array $values values to add
+        * @param string $flag the name of the boolean flag to mark this element
+        * @param string $name if given, name of the value
+        */
+       private static function addValues( array &$result, $values, $flag = null, $name = null ) {
+               foreach ( $values as $val ) {
+                       if ( $val instanceof Title ) {
+                               $v = array();
+                               ApiQueryBase::addTitleInfo( $v, $val );
+                       } elseif ( $name !== null ) {
+                               $v = array( $name => $val );
+                       } else {
+                               $v = $val;
+                       }
+                       if ( $flag !== null ) {
+                               $v[$flag] = '';
+                       }
+                       $result[] = $v;
+               }
+       }
+
        /**
         * Constructor
         * @param $dbSource ApiBase Module implementing getDB().
@@ -387,7 +410,7 @@ class ApiPageSet extends ApiBase {
                                'from' => strval( $titleStrFrom ),
                                'to' => $titleTo->getPrefixedText(),
                        );
-                       if ( $titleTo->getFragment() !== '' ) {
+                       if ( $titleTo->hasFragment() ) {
                                $r['tofragment'] = $titleTo->getFragment();
                        }
                        $values[] = $r;
@@ -498,6 +521,46 @@ class ApiPageSet extends ApiBase {
                return $values;
        }
 
+       /**
+        * Get an array of invalid/special/missing titles.
+        *
+        * @param $invalidChecks List of types of invalid titles to include.
+        *   Recognized values are:
+        *   - invalidTitles: Titles from $this->getInvalidTitles()
+        *   - special: Titles from $this->getSpecialTitles()
+        *   - missingIds: ids from $this->getMissingPageIDs()
+        *   - missingRevIds: ids from $this->getMissingRevisionIDs()
+        *   - missingTitles: Titles from $this->getMissingTitles()
+        *   - interwikiTitles: Titles from $this->getInterwikiTitlesAsResult()
+        * @return array Array suitable for inclusion in the response
+        * @since 1.23
+        */
+       public function getInvalidTitlesAndRevisions( $invalidChecks = array( 'invalidTitles',
+               'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles' )
+       ) {
+               $result = array();
+               if ( in_array( "invalidTitles", $invalidChecks ) ) {
+                       self::addValues( $result, $this->getInvalidTitles(), 'invalid', 'title' );
+               }
+               if ( in_array( "special", $invalidChecks ) ) {
+                       self::addValues( $result, $this->getSpecialTitles(), 'special', 'title' );
+               }
+               if ( in_array( "missingIds", $invalidChecks ) ) {
+                       self::addValues( $result, $this->getMissingPageIDs(), 'missing', 'pageid' );
+               }
+               if ( in_array( "missingRevIds", $invalidChecks ) ) {
+                       self::addValues( $result, $this->getMissingRevisionIDs(), 'missing', 'revid' );
+               }
+               if ( in_array( "missingTitles", $invalidChecks ) ) {
+                       self::addValues( $result, $this->getMissingTitles(), 'missing' );
+               }
+               if ( in_array( "interwikiTitles", $invalidChecks ) ) {
+                       self::addValues( $result, $this->getInterwikiTitlesAsResult() );
+               }
+
+               return $result;
+       }
+
        /**
         * Get the list of revision IDs (requested with the revids= parameter)
         * @return array revID (int) => pageID (int)