Files with a mime type that does not match the extension are now properly thumbnailed...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sun, 6 Feb 2011 19:20:57 +0000 (19:20 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sun, 6 Feb 2011 19:20:57 +0000 (19:20 +0000)
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
includes/media/Generic.php

index 1c92c80..3c2defa 100644 (file)
@@ -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
index cf69a01..1f6dec0 100644 (file)
@@ -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 );
        }