From fdbfd946efdc19443c0eaeadc1725f083655f6b7 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 22 May 2008 16:25:45 +0000 Subject: [PATCH] * Fix typo in ApiQueryImageInfo which made mime type query fail to work :) * Fix ForeignAPIRepo's query to use the corrected parameter to the API * ForeignAPIFile fixes to use queried mime type if available, and type-safety checks in case some values are missing or funny --- includes/api/ApiQueryImageInfo.php | 2 +- includes/filerepo/ForeignAPIFile.php | 36 +++++++++++++--------------- includes/filerepo/ForeignAPIRepo.php | 2 +- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 505c560882..1186a3a208 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -143,7 +143,7 @@ class ApiQueryImageInfo extends ApiQueryBase { $vals['metadata'] = $metadata ? unserialize( $metadata ) : null; $result->setIndexedTagName_recursive( $vals['metadata'], 'meta' ); } - if( isset( $prop['mimetype'] ) ) + if( isset( $prop['mime'] ) ) $vals['mime'] = $file->getMimeType(); if( isset( $prop['archivename'] ) && $file->isOld() ) diff --git a/includes/filerepo/ForeignAPIFile.php b/includes/filerepo/ForeignAPIFile.php index 81d28f8633..aaf922048e 100644 --- a/includes/filerepo/ForeignAPIFile.php +++ b/includes/filerepo/ForeignAPIFile.php @@ -9,13 +9,6 @@ class ForeignAPIFile extends File { function __construct( $title, $repo, $info ) { parent::__construct( $title, $repo ); - - // For some reason API doesn't currently provide type info - $magic = MimeMagic::singleton(); - $info['mime'] = $magic->guessTypesForExtension( $this->getExtension() ); - list( $info['major_mime'], $info['minor_mime'] ) = self::splitMime( $info['mime'] ); - $info['media_type'] = $magic->getMediaType( null, $info['mime'] ); - $this->mInfo = $info; } @@ -51,48 +44,53 @@ class ForeignAPIFile extends File { // Info we can get from API... public function getWidth( $page = 1 ) { - return intval( $this->mInfo['width'] ); + return intval( @$this->mInfo['width'] ); } public function getHeight( $page = 1 ) { - return intval( $this->mInfo['height'] ); + return intval( @$this->mInfo['height'] ); } public function getMetadata() { - return serialize( (array)$this->mInfo['metadata'] ); + return serialize( (array)@$this->mInfo['metadata'] ); } public function getSize() { - return intval( $this->mInfo['size'] ); + return intval( @$this->mInfo['size'] ); } public function getUrl() { - return $this->mInfo['url']; + return strval( @$this->mInfo['url'] ); } public function getUser( $method='text' ) { - return $this->mInfo['user']; + return strval( @$this->mInfo['user'] ); } public function getDescription() { - return $this->mInfo['comment']; + return strval( @$this->mInfo['comment'] ); } function getSha1() { - return wfBaseConvert( $this->mInfo['sha1'], 16, 36, 31 ); + return wfBaseConvert( strval( @$this->mInfo['sha1'] ), 16, 36, 31 ); } function getTimestamp() { - return wfTimestamp( TS_MW, $this->mInfo['timestamp'] ); + return wfTimestamp( TS_MW, strval( @$this->mInfo['timestamp'] ) ); } - // Info we had to guess... function getMimeType() { - return $this->mInfo['mime']; + if( empty( $info['mime'] ) ) { + $magic = MimeMagic::singleton(); + $info['mime'] = $magic->guessTypesForExtension( $this->getExtension() ); + } + return $info['mime']; } + /// @fixme May guess wrong on file types that can be eg audio or video function getMediaType() { - return $this->mInfo['media_type']; + $magic = MimeMagic::singleton(); + return $magic->getMediaType( null, $this->getMimeType() ); } function getDescriptionUrl() { diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index f9e42be650..2315253a71 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -91,7 +91,7 @@ class ForeignAPIRepo extends FileRepo { function getImageInfo( $title, $time = false ) { return $this->queryImage( array( 'titles' => 'Image:' . $title->getText(), - 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mimetype' ) ); + 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime' ) ); } function getThumbUrl( $name, $width=-1, $height=-1 ) { -- 2.20.1