Phuedx has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/243124

Change subject: Revert "Revert "Include foreign files in ApiQueryPageImages""
......................................................................

Revert "Revert "Include foreign files in ApiQueryPageImages""

This reverts commit 1690d99e369dbac3c7e11cf61a1b9e42d62150f6.

This also fixes T114417 by testing whether there are missing titles in
the File namespace before going on to operate on them anyway...

Bug: T98791
Bug: T114417
Change-Id: I923e88dde3a8ced4921b4192d90b4f3dc4b19e7b
---
M ApiQueryPageImages.php
1 file changed, 39 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageImages 
refs/changes/24/243124/1

diff --git a/ApiQueryPageImages.php b/ApiQueryPageImages.php
index a629f6e..f5d6870 100644
--- a/ApiQueryPageImages.php
+++ b/ApiQueryPageImages.php
@@ -8,11 +8,40 @@
                parent::__construct( $query, $moduleName, 'pi' );
        }
 
+       /**
+        * Gets the set of titles to get page images for.
+        *
+        * Note well that the set of titles comprises the set of "good" titles
+        * (see {@see ApiPageSet::getGoodTitles}) union the set of "missing"
+        * titles in the File namespace that might correspond to foreign files.
+        * The latter are included because titles in the File namespace are
+        * expected to be found with {@see wfFindFile}.
+        *
+        * @return array A map of page ID, which will be negative in the case
+        *  of missing titles in the File namespace, to Title object
+        */
+       private function getTitles() {
+               $pageSet = $this->getPageSet();
+               $titles = $pageSet->getGoodTitles();
+
+               // T98791: We want foreign files to be treated like local files
+               // in #execute, so include the set of missing filespace pages,
+               // which were initially rejected in ApiPageSet#execute.
+               $missingTitles = $pageSet->getMissingTitlesByNamespace();
+               $missingFileTitles = isset( $missingTitles[NS_FILE] )
+                       ? $missingTitles[NS_FILE]
+                       : array();
+
+               // $titles is a map of ID to title object, which is ideal,
+               // whereas $missingFileTitles is a map of title text to ID.
+               $missingFileTitles = array_map( function ( $text ) {
+                       return Title::newFromText( $text, NS_FILE );
+               }, array_flip( $missingFileTitles ) );
+
+               return $titles + $missingFileTitles;
+       }
+
        public function execute() {
-               $allTitles = $this->getPageSet()->getGoodTitles();
-               if ( count( $allTitles ) == 0 ) {
-                       return;
-               }
                $params = $this->extractRequestParams();
                $prop = array_flip( $params['prop'] );
                if ( !count( $prop ) ) {
@@ -21,6 +50,12 @@
                $size = $params['thumbsize'];
                $limit = $params['limit'];
 
+               $allTitles = $this->getTitles();
+
+               if ( count( $allTitles ) === 0 ) {
+                       return;
+               }
+
                // Find the offset based on the continue param
                $offset = 0;
                if ( isset( $params['continue'] ) ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/243124
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I923e88dde3a8ced4921b4192d90b4f3dc4b19e7b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageImages
Gerrit-Branch: master
Gerrit-Owner: Phuedx <g...@samsmith.io>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to