From a6617a4959af1af2680e1bd4244b7402de4eeba8 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sun, 6 Feb 2011 19:20:57 +0000 Subject: [PATCH] Files with a mime type that does not match the extension are now properly thumbnailed. Partial bug fix to bug 26661. MediaHandler::getThumbType now checks if the extension and the mime type match. If they do not, a new extension is generated for the mime type. The rest of the thumbnailing code should then magically work. Bonus: this also works with file names without extension, so might be a step closer to extension-less files. --- RELEASE-NOTES | 2 ++ includes/media/Generic.php | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 1c92c80e62..3c2defafdd 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -119,6 +119,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN enabled, but user cannot see rc patrol links. * (bug 26548) ForeignAPIRepo (InstantCommons) now works with PDF files and other multi-paged file formats. +* Files with a mime type that does not match the extension are now properly + thumbnailed === API changes in 1.18 === * (bug 26339) Throw warning when truncating an overlarge API result diff --git a/includes/media/Generic.php b/includes/media/Generic.php index cf69a01987..1f6dec039d 100644 --- a/includes/media/Generic.php +++ b/includes/media/Generic.php @@ -141,6 +141,18 @@ abstract class MediaHandler { * @return array thumbnail extension and MIME type */ function getThumbType( $ext, $mime, $params = null ) { + $magic = MimeMagic::singleton(); + if ( !$ext || $magic->isMatchingExtension( $ext, $mime ) === false ) { + // The extension is not valid for this mime type and we do + // recognize the mime type + $extensions = $magic->getExtensionsForType( $mime ); + if ( $extensions ) { + return array( strtok( $extensions, ' ' ), $mime ); + } + } + + // The extension is correct (true) or the mime type is unknown to + // MediaWiki (null) return array( $ext, $mime ); } -- 2.20.1