From 6a9ec236126ba82d6f8e0984a7ef1fd58a68aa3d Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 26 Dec 2012 10:40:43 -0500 Subject: [PATCH] (bug 31849) API imageinfo correctly handle redirects RepoGroup::singleton()->findFiles() returns an associative array mapping the redirect *target* to the image object; the image object refers back to the original title queried. If a redirect and its target are both queried, RepoGroup::singleton()->findFiles() will return an entry for the target title only, mapping to an image object that may have getOriginalTitle() returning the redirect. If this happens, prop=imageinfo will never see an entry for which getOriginalTitle()->isRedirect() is false and so will not return any information about the image. The fix is to ignore getOriginalTitle() entirely. Instead, we just go through each of our queried titles and see if we got any result back. Note this automatically handles a "redirects=1" query correctly, since in that case any local redirect will already have been followed before we ever got the list of titles to query. Change-Id: I0b2982901e2dc4491e2933291fd97697b2a622a9 --- RELEASE-NOTES-1.21 | 6 ++++++ includes/api/ApiQueryImageInfo.php | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 1f344d4396..01ff993d55 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -181,6 +181,12 @@ production. * (bug 35885) Removed version parameter and all getVersion() methods. * action=options now takes a "resetkinds" option, which allows only resetting certain types of preferences when the "reset" option is set. +* (bug 36751) ApiQueryImageInfo now returns imageinfo for the redirect target + when queried with &redirects=. +* (bug 31849) ApiQueryImageInfo no longer gets confused when asked for info on + a redirect and its target. +* (bug 43849) ApiQueryImageInfo no longer throws exceptions with ForeignDBRepo + redirects. === API internal changes in 1.21 === * For debugging only, a new global $wgDebugAPI removes many API restrictions when true. diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 2b6ec66f44..b368af8a0e 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -76,15 +76,14 @@ class ApiQueryImageInfo extends ApiQueryBase { } else { $images = RepoGroup::singleton()->findFiles( $titles ); } - $resolveRedirects = $this->getPageSet()->isResolvingRedirects(); - foreach ( $images as $img ) { - // Skip redirects - if ( $img->getOriginalTitle()->isRedirect() && !$resolveRedirects ) { + foreach ( $titles as $title ) { + if ( !isset( $images[$title] ) ) { continue; } $start = $skip ? $fromTimestamp : $params['start']; - $pageId = $pageIds[NS_FILE][$img->getTitle()->getDBkey()]; + $pageId = $pageIds[NS_FILE][$title]; + $img = $images[$title]; $fit = $result->addValue( array( 'query', 'pages', intval( $pageId ) ), -- 2.20.1