Index: includes/filerepo/ForeignAPIFile.php
===================================================================
--- includes/filerepo/ForeignAPIFile.php	(revision 62543)
+++ includes/filerepo/ForeignAPIFile.php	(working copy)
@@ -17,9 +17,22 @@
 	}
 	
 	static function newFromTitle( $title, $repo ) {
-		$info = $repo->getImageInfo( $title );
-		if( $info ) {
-			return new ForeignAPIFile( $title, $repo, $info, true );
+		$data = $repo->fetchImageQuery( array(
+                        'titles' => 'File:' . $title->getText(),
+                        'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime',
+                        'prop' => 'imageinfo' ) );
+
+		$info = $repo->getImageInfo( $data );
+
+		if( $data && $info) {
+			if( isset( $data['query']['redirects'][0] ) ) {
+				$newtitle = Title::newFromText( $data['query']['redirects'][0]['to']);
+				$img = new ForeignAPIFile( $newtitle, $repo, $info, true );
+				if( $img ) $img->redirectedFrom( $title->getDBkey() );
+			} else {
+				$img = new ForeignAPIFile( $title, $repo, $info, true );
+			}
+			return $img;
 		} else {
 			return null;
 		}
Index: includes/filerepo/ForeignAPIRepo.php
===================================================================
--- includes/filerepo/ForeignAPIRepo.php	(revision 62543)
+++ includes/filerepo/ForeignAPIRepo.php	(working copy)
@@ -103,20 +103,7 @@
 		return false;
 	}
 
-	protected function queryImage( $query ) {
-		$data = $this->fetchImageQuery( $query );
-
-		if( isset( $data['query']['pages'] ) ) {
-			foreach( $data['query']['pages'] as $pageid => $info ) {
-				if( isset( $info['imageinfo'][0] ) ) {
-					return $info['imageinfo'][0];
-				}
-			}
-		}
-		return false;
-	}
-
-	protected function fetchImageQuery( $query ) {
+	function fetchImageQuery( $query ) {
 		global $wgMemc;
 
 		$url = $this->mApiBase .
@@ -125,7 +112,8 @@
 				array_merge( $query,
 					array(
 						'format' => 'json',
-						'action' => 'query' ) ) );
+						'action' => 'query',
+						'redirects' => 'true' ) ) );
 
 		if( !isset( $this->mQueryCache[$url] ) ) {
 			$key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) );
@@ -147,11 +135,15 @@
 		return FormatJson::decode( $this->mQueryCache[$url], true );
 	}
 
-	function getImageInfo( $title, $time = false ) {
-		return $this->queryImage( array(
-			'titles' => 'Image:' . $title->getText(),
-			'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime',
-			'prop' => 'imageinfo' ) );
+	function getImageInfo( $data ) {
+		if( $data && isset( $data['query']['pages'] ) ) {
+			foreach( $data['query']['pages'] as $pageid => $info ) {
+				if( isset( $info['imageinfo'][0] ) ) {
+					return $info['imageinfo'][0];
+				}
+			}
+		}
+		return false;
 	}
 
 	function findBySha1( $hash ) {
@@ -169,13 +161,13 @@
 	}
 
 	function getThumbUrl( $name, $width=-1, $height=-1 ) {
-		$info = $this->queryImage( array(
-			'titles' => 'Image:' . $name,
+		$data = $this->fetchImageQuery( array(
+			'titles' => 'File:' . $name,
 			'iiprop' => 'url',
 			'iiurlwidth' => $width,
 			'iiurlheight' => $height,
 			'prop' => 'imageinfo' ) );
-		if( $info ) {
+		if( $data && $info = $this->getImageInfo( $data )) {
 			wfDebug( __METHOD__ . " got remote thumb " . $info['thumburl'] . "\n" );
 			return $info['thumburl'];
 		} else {
