r66724 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66723‎ | r66724 | r66725 >
Date:15:59, 21 May 2010
Author:hartman
Status:resolved (Comments)
Tags:
Comment:
Bug 22541. Support image redirects on Commons for ForeignAPIRepo

getImageInfo() now requires fetchImageQuery() results as input.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/filerepo/ForeignAPIFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/ForeignAPIRepo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/ForeignAPIRepo.php
@@ -103,20 +103,7 @@
104104 return false;
105105 }
106106
107 - protected function queryImage( $query ) {
108 - $data = $this->fetchImageQuery( $query );
109 -
110 - if( isset( $data['query']['pages'] ) ) {
111 - foreach( $data['query']['pages'] as $pageid => $info ) {
112 - if( isset( $info['imageinfo'][0] ) ) {
113 - return $info['imageinfo'][0];
114 - }
115 - }
116 - }
117 - return false;
118 - }
119 -
120 - protected function fetchImageQuery( $query ) {
 107+ function fetchImageQuery( $query ) {
121108 global $wgMemc;
122109
123110 $url = $this->mApiBase .
@@ -125,7 +112,8 @@
126113 array_merge( $query,
127114 array(
128115 'format' => 'json',
129 - 'action' => 'query' ) ) );
 116+ 'action' => 'query',
 117+ 'redirects' => 'true' ) ) );
130118
131119 if( !isset( $this->mQueryCache[$url] ) ) {
132120 $key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) );
@@ -147,11 +135,15 @@
148136 return FormatJson::decode( $this->mQueryCache[$url], true );
149137 }
150138
151 - function getImageInfo( $title, $time = false ) {
152 - return $this->queryImage( array(
153 - 'titles' => 'Image:' . $title->getText(),
154 - 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime',
155 - 'prop' => 'imageinfo' ) );
 139+ function getImageInfo( $data ) {
 140+ if( $data && isset( $data['query']['pages'] ) ) {
 141+ foreach( $data['query']['pages'] as $pageid => $info ) {
 142+ if( isset( $info['imageinfo'][0] ) ) {
 143+ return $info['imageinfo'][0];
 144+ }
 145+ }
 146+ }
 147+ return false;
156148 }
157149
158150 function findBySha1( $hash ) {
@@ -169,13 +161,15 @@
170162 }
171163
172164 function getThumbUrl( $name, $width=-1, $height=-1 ) {
173 - $info = $this->queryImage( array(
174 - 'titles' => 'Image:' . $name,
 165+ $data = $this->fetchImageQuery( array(
 166+ 'titles' => 'File:' . $name,
175167 'iiprop' => 'url',
176168 'iiurlwidth' => $width,
177169 'iiurlheight' => $height,
178170 'prop' => 'imageinfo' ) );
179 - if( $info && $info['thumburl'] ) {
 171+ $info = $this->getImageInfo( $data );
 172+
 173+ if( $data && $info && $info['thumburl'] ) {
180174 wfDebug( __METHOD__ . " got remote thumb " . $info['thumburl'] . "\n" );
181175 return $info['thumburl'];
182176 } else {
Index: trunk/phase3/includes/filerepo/ForeignAPIFile.php
@@ -17,9 +17,22 @@
1818 }
1919
2020 static function newFromTitle( $title, $repo ) {
21 - $info = $repo->getImageInfo( $title );
22 - if( $info ) {
23 - return new ForeignAPIFile( $title, $repo, $info, true );
 21+ $data = $repo->fetchImageQuery( array(
 22+ 'titles' => 'File:' . $title->getText(),
 23+ 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime',
 24+ 'prop' => 'imageinfo' ) );
 25+
 26+ $info = $repo->getImageInfo( $data );
 27+
 28+ if( $data && $info) {
 29+ if( isset( $data['query']['redirects'][0] ) ) {
 30+ $newtitle = Title::newFromText( $data['query']['redirects'][0]['to']);
 31+ $img = new ForeignAPIFile( $newtitle, $repo, $info, true );
 32+ if( $img ) $img->redirectedFrom( $title->getDBkey() );
 33+ } else {
 34+ $img = new ForeignAPIFile( $title, $repo, $info, true );
 35+ }
 36+ return $img;
2437 } else {
2538 return null;
2639 }
Index: trunk/phase3/RELEASE-NOTES
@@ -171,6 +171,7 @@
172172 * (bug 23563) Old skins now support $wgUploadNavigationUrl and take into account upload rights.
173173 * (bug 1347) Render \phi in math using images, in order to create consistent and correct render results.
174174 * (bug 16573) Render \epsilon in math using images, in order to create consistent and correct render results.
 175+* (bug 22541) Support image redirects when using ForeignAPIRepo
175176
176177 === API changes in 1.17 ===
177178 * (bug 22738) Allow filtering by action type on query=logevent

Follow-up revisions

RevisionCommit summaryAuthorDate
r79708Fixup minor FIXME on r66724reedy03:21, 6 January 2011

Comments

#Comment by Catrope (talk | contribs)   22:18, 14 December 2010
+		$info = $repo->getImageInfo( $data );
+
+		if( $data && $info) {

There's no need to check $data, as getImageInfo() will already have done that.

+				$newtitle = Title::newFromText( $data['query']['redirects'][0]['to']);

If you want proper resolution of redirect chains (double, triple, ... redirects) you should use the last element of $data['query']['redirects'], not the first one.

OK otherwise.

#Comment by TheDJ (talk | contribs)   07:19, 6 January 2011

hmm, thx Reedy. Totally forgot about this one. We reallly need a "my fixmes" filter in Code Review.

#Comment by Shifuimam (talk | contribs)   21:22, 25 January 2013

Per bug 42610, this patch broke the ability to embed images from foreign file repos that redirect to non-image locations on the remote wiki. I can provide examples if necessary - please feel free to contact me through my talk page.

Status & tagging log