ForeignAPIRepo fixes:
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 22 May 2008 16:17:42 +0000 (16:17 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 22 May 2008 16:17:42 +0000 (16:17 +0000)
* 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
includes/filerepo/ForeignAPIRepo.php

index 1608442..81d28f8 100644 (file)
@@ -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'];
index 43b2ab1..f9e42be 100644 (file)
@@ -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 ) {