From 960011dc612723b167c710f4e4efa3d610e033f8 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 22 May 2008 16:17:42 +0000 Subject: [PATCH] ForeignAPIRepo fixes: * use the proper factory method so findFile accepts strings as well as Title objects; fixes API image queries * pass timestamp and SHA-1 hash on --- includes/filerepo/ForeignAPIFile.php | 17 +++++++++++++++++ includes/filerepo/ForeignAPIRepo.php | 13 +++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/includes/filerepo/ForeignAPIFile.php b/includes/filerepo/ForeignAPIFile.php index 1608442d26..81d28f8633 100644 --- a/includes/filerepo/ForeignAPIFile.php +++ b/includes/filerepo/ForeignAPIFile.php @@ -19,6 +19,15 @@ class ForeignAPIFile extends File { $this->mInfo = $info; } + static function newFromTitle( $title, $repo ) { + $info = $repo->getImageInfo( $title ); + if( $info ) { + return new ForeignAPIFile( $title, $repo, $info ); + } else { + return null; + } + } + // Dummy functions... public function exists() { return true; @@ -69,6 +78,14 @@ class ForeignAPIFile extends File { return $this->mInfo['comment']; } + function getSha1() { + return wfBaseConvert( $this->mInfo['sha1'], 16, 36, 31 ); + } + + function getTimestamp() { + return wfTimestamp( TS_MW, $this->mInfo['timestamp'] ); + } + // Info we had to guess... function getMimeType() { return $this->mInfo['mime']; diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 43b2ab1058..f9e42be650 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -17,6 +17,7 @@ * @ingroup FileRepo */ class ForeignAPIRepo extends FileRepo { + var $fileFactory = array( 'ForeignAPIFile', 'newFromTitle' ); protected $mQueryCache = array(); function __construct( $info ) { @@ -44,9 +45,6 @@ class ForeignAPIRepo extends FileRepo { function getFileProps( $virtualUrl ) { return false; } - function newFile( $title, $time = false ) { - return false; - } protected function queryImage( $query ) { $data = $this->fetchImageQuery( $query ); @@ -90,15 +88,10 @@ class ForeignAPIRepo extends FileRepo { return json_decode( $this->mQueryCache[$url], true ); } - function findFile( $title, $time = false ) { - $info = $this->queryImage( array( + function getImageInfo( $title, $time = false ) { + return $this->queryImage( array( 'titles' => 'Image:' . $title->getText(), 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mimetype' ) ); - if( $info ) { - return new ForeignAPIFile( $title, $this, $info ); - } else { - return false; - } } function getThumbUrl( $name, $width=-1, $height=-1 ) { -- 2.20.1