Merge "Rank aliases in search in order they appear in the messages file."
[lhc/web/wiklou.git] / includes / api / ApiPageSet.php
index 34c17c1..853a805 100644 (file)
@@ -23,6 +23,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * This class contains a list of pages that the client has requested.
@@ -86,10 +87,10 @@ class ApiPageSet extends ApiBase {
         * 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[] $flags The names of boolean flags to mark this element
         * @param string $name If given, name of the value
         */
-       private static function addValues( array &$result, $values, $flag = null, $name = null ) {
+       private static function addValues( array &$result, $values, $flags = [], $name = null ) {
                foreach ( $values as $val ) {
                        if ( $val instanceof Title ) {
                                $v = [];
@@ -99,7 +100,7 @@ class ApiPageSet extends ApiBase {
                        } else {
                                $v = $val;
                        }
-                       if ( $flag !== null ) {
+                       foreach ( $flags as $flag ) {
                                $v[$flag] = true;
                        }
                        $result[] = $v;
@@ -309,8 +310,9 @@ class ApiPageSet extends ApiBase {
                        $pageFlds['page_lang'] = null;
                }
 
-               // only store non-default fields
-               $this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds );
+               foreach ( LinkCache::getSelectFields() as $field ) {
+                       $pageFlds[$field] = null;
+               }
 
                $pageFlds = array_merge( $pageFlds, $this->mRequestedPageFields );
 
@@ -600,19 +602,39 @@ class ApiPageSet extends ApiBase {
        ) {
                $result = [];
                if ( in_array( 'invalidTitles', $invalidChecks ) ) {
-                       self::addValues( $result, $this->getInvalidTitlesAndReasons(), 'invalid' );
+                       self::addValues( $result, $this->getInvalidTitlesAndReasons(), [ 'invalid' ] );
                }
                if ( in_array( 'special', $invalidChecks ) ) {
-                       self::addValues( $result, $this->getSpecialTitles(), 'special', 'title' );
+                       $known = [];
+                       $unknown = [];
+                       foreach ( $this->getSpecialTitles() as $title ) {
+                               if ( $title->isKnown() ) {
+                                       $known[] = $title;
+                               } else {
+                                       $unknown[] = $title;
+                               }
+                       }
+                       self::addValues( $result, $unknown, [ 'special', 'missing' ] );
+                       self::addValues( $result, $known, [ 'special' ] );
                }
                if ( in_array( 'missingIds', $invalidChecks ) ) {
-                       self::addValues( $result, $this->getMissingPageIDs(), 'missing', 'pageid' );
+                       self::addValues( $result, $this->getMissingPageIDs(), [ 'missing' ], 'pageid' );
                }
                if ( in_array( 'missingRevIds', $invalidChecks ) ) {
-                       self::addValues( $result, $this->getMissingRevisionIDs(), 'missing', 'revid' );
+                       self::addValues( $result, $this->getMissingRevisionIDs(), [ 'missing' ], 'revid' );
                }
                if ( in_array( 'missingTitles', $invalidChecks ) ) {
-                       self::addValues( $result, $this->getMissingTitles(), 'missing' );
+                       $known = [];
+                       $unknown = [];
+                       foreach ( $this->getMissingTitles() as $title ) {
+                               if ( $title->isKnown() ) {
+                                       $known[] = $title;
+                               } else {
+                                       $unknown[] = $title;
+                               }
+                       }
+                       self::addValues( $result, $unknown, [ 'missing' ] );
+                       self::addValues( $result, $known, [ 'missing', 'known' ] );
                }
                if ( in_array( 'interwikiTitles', $invalidChecks ) ) {
                        self::addValues( $result, $this->getInterwikiTitlesAsResult() );
@@ -734,6 +756,8 @@ class ApiPageSet extends ApiBase {
                // Store Title object in various data structures
                $title = Title::newFromRow( $row );
 
+               LinkCache::singleton()->addGoodLinkObjFromRow( $title, $row );
+
                $pageId = intval( $row->page_id );
                $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId;
                $this->mTitles[] = $title;
@@ -863,9 +887,11 @@ class ApiPageSet extends ApiBase {
                        // Any items left in the $remaining list are added as missing
                        if ( $processTitles ) {
                                // The remaining titles in $remaining are non-existent pages
+                               $linkCache = LinkCache::singleton();
                                foreach ( $remaining as $ns => $dbkeys ) {
                                        foreach ( array_keys( $dbkeys ) as $dbkey ) {
                                                $title = Title::makeTitle( $ns, $dbkey );
+                                               $linkCache->addBadLinkObj( $title );
                                                $this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
                                                $this->mMissingPages[$ns][$dbkey] = $this->mFakePageId;
                                                $this->mGoodAndMissingPages[$ns][$dbkey] = $this->mFakePageId;
@@ -890,7 +916,7 @@ class ApiPageSet extends ApiBase {
                }
 
                // Get gender information
-               $genderCache = GenderCache::singleton();
+               $genderCache = MediaWikiServices::getInstance()->getGenderCache();
                $genderCache->doQuery( $usernames, __METHOD__ );
        }
 
@@ -1172,7 +1198,7 @@ class ApiPageSet extends ApiBase {
                        }
                }
                // Get gender information
-               $genderCache = GenderCache::singleton();
+               $genderCache = MediaWikiServices::getInstance()->getGenderCache();
                $genderCache->doQuery( $usernames, __METHOD__ );
 
                return $linkBatch;
@@ -1386,13 +1412,7 @@ class ApiPageSet extends ApiBase {
                                ApiBase::PARAM_DFLT => false,
                                ApiBase::PARAM_HELP_MSG => [
                                        'api-pageset-param-converttitles',
-                                       new DeferredStringifier(
-                                               function ( IContextSource $context ) {
-                                                       return $context->getLanguage()
-                                                               ->commaList( LanguageConverter::$languagesWithVariants );
-                                               },
-                                               $this
-                                       )
+                                       [ Message::listParam( LanguageConverter::$languagesWithVariants, 'text' ) ],
                                ],
                        ],
                ];