From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/filerepo/file/ForeignAPIFile.php | 49 ++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'includes/filerepo/file/ForeignAPIFile.php') diff --git a/includes/filerepo/file/ForeignAPIFile.php b/includes/filerepo/file/ForeignAPIFile.php index a96c1f3f..ed96d446 100644 --- a/includes/filerepo/file/ForeignAPIFile.php +++ b/includes/filerepo/file/ForeignAPIFile.php @@ -54,22 +54,22 @@ class ForeignAPIFile extends File { */ static function newFromTitle( Title $title, $repo ) { $data = $repo->fetchImageQuery( array( - 'titles' => 'File:' . $title->getDBKey(), - 'iiprop' => self::getProps(), - 'prop' => 'imageinfo', + 'titles' => 'File:' . $title->getDBkey(), + 'iiprop' => self::getProps(), + 'prop' => 'imageinfo', 'iimetadataversion' => MediaHandler::getMetadataVersion() ) ); $info = $repo->getImageInfo( $data ); - if( $info ) { + if ( $info ) { $lastRedirect = isset( $data['query']['redirects'] ) ? count( $data['query']['redirects'] ) - 1 : -1; - if( $lastRedirect >= 0 ) { - $newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to']); + if ( $lastRedirect >= 0 ) { + $newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to'] ); $img = new self( $newtitle, $repo, $info, true ); - if( $img ) { + if ( $img ) { $img->redirectedFrom( $title->getDBkey() ); } } else { @@ -86,7 +86,7 @@ class ForeignAPIFile extends File { * @return string */ static function getProps() { - return 'timestamp|user|comment|url|size|sha1|metadata|mime'; + return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype'; } // Dummy functions... @@ -111,7 +111,7 @@ class ForeignAPIFile extends File { * @return bool|MediaTransformOutput */ function transform( $params, $flags = 0 ) { - if( !$this->canRender() ) { + if ( !$this->canRender() ) { // show icon return parent::transform( $params, $flags ); } @@ -119,12 +119,25 @@ class ForeignAPIFile extends File { // Note, the this->canRender() check above implies // that we have a handler, and it can do makeParamString. $otherParams = $this->handler->makeParamString( $params ); + $width = isset( $params['width'] ) ? $params['width'] : -1; + $height = isset( $params['height'] ) ? $params['height'] : -1; $thumbUrl = $this->repo->getThumbUrlFromCache( $this->getName(), - isset( $params['width'] ) ? $params['width'] : -1, - isset( $params['height'] ) ? $params['height'] : -1, - $otherParams ); + $width, + $height, + $otherParams + ); + if ( $thumbUrl === false ) { + global $wgLang; + return $this->repo->getThumbError( + $this->getName(), + $width, + $height, + $otherParams, + $wgLang->getCode() + ); + } return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params ); } @@ -161,12 +174,12 @@ class ForeignAPIFile extends File { * @return array */ public static function parseMetadata( $metadata ) { - if( !is_array( $metadata ) ) { + if ( !is_array( $metadata ) ) { return $metadata; } $ret = array(); - foreach( $metadata as $meta ) { - $ret[ $meta['name'] ] = self::parseMetadata( $meta['value'] ); + foreach ( $metadata as $meta ) { + $ret[$meta['name']] = self::parseMetadata( $meta['value'] ); } return $ret; } @@ -224,7 +237,7 @@ class ForeignAPIFile extends File { * @return string */ function getMimeType() { - if( !isset( $this->mInfo['mime'] ) ) { + if ( !isset( $this->mInfo['mime'] ) ) { $magic = MimeMagic::singleton(); $this->mInfo['mime'] = $magic->guessTypesForExtension( $this->getExtension() ); } @@ -232,10 +245,12 @@ class ForeignAPIFile extends File { } /** - * @todo FIXME: May guess wrong on file types that can be eg audio or video * @return int|string */ function getMediaType() { + if ( isset( $this->mInfo['mediatype'] ) ) { + return $this->mInfo['mediatype']; + } $magic = MimeMagic::singleton(); return $magic->getMediaType( null, $this->getMimeType() ); } -- cgit v1.2.2