Recognize webm and matroska files. See also Bug 23888
authorDerk-Jan Hartman <hartman@users.mediawiki.org>
Wed, 28 Jul 2010 19:24:00 +0000 (19:24 +0000)
committerDerk-Jan Hartman <hartman@users.mediawiki.org>
Wed, 28 Jul 2010 19:24:00 +0000 (19:24 +0000)
Currently all webm files are stored as video/webm. It is not possible to detect
wether this file is an audio file without using a full parser. This is why We should
really move mime and mediatype accessors to the MediaHandlers.

Using video/x-matroska for MKV files. There is no official mime for MKV (though the
webm isn't official either, but everyone is already using it apparently).

includes/MimeMagic.php
includes/mime.info
includes/mime.types

index 85f02dc..8c939e0 100644 (file)
@@ -396,7 +396,8 @@ class MimeMagic {
                        'xbm',
 
                        // Formats we recognize magic numbers for
-                       'djvu', 'ogx', 'ogg', 'ogv', 'oga', 'spx', 'mid', 'pdf', 'wmf', 'xcf',
+                       'djvu', 'ogx', 'ogg', 'ogv', 'oga', 'spx',
+                       'mid', 'pdf', 'wmf', 'xcf', 'webm', 'mkv', 'mka',
 
                        // XML formats we sure hope we recognize reliably
                        'svg',
@@ -468,6 +469,24 @@ class MimeMagic {
                        }
                }
 
+               /* Look for WebM and Matroska files */
+               if( strncmp( $head, pack( "C4", 0x1a, 0x45, 0xdf, 0xa3 ), 4 ) == 0 ) {
+                       $doctype = strpos( $head, "\x42\x82" );
+                       if( $doctype ) {
+                               // Next byte is datasize, then data (sizes larger than 1 byte are very stupid muxers)
+                               $data = substr($head, $doctype+3, 8);
+                               if( strncmp( $data, "matroska", 8 ) == 0 ) {
+                                       wfDebug( __METHOD__ . ": recognized file as video/x-matroska\n" );
+                                       return "video/x-matroska";
+                               } else if ( strncmp( $data, "webm", 4 ) == 0 ) {
+                                       wfDebug( __METHOD__ . ": recognized file as video/webm\n" );
+                                       return "video/webm";
+                               }
+                       }
+                       wfDebug( __METHOD__ . ": unknown EBML file\n" );
+                       return "unknown/unknown";
+               }
+
                /*
                 * Look for PHP.  Check for this before HTML/XML...  Warning: this is a
                 * heuristic, and won't match a file with a lot of non-PHP before.  It
index 610f6ec..4999d81 100644 (file)
@@ -35,11 +35,15 @@ audio/ogg           [AUDIO]
 audio/x-aiff           [AUDIO]
 audio/x-pn-realaudio   [AUDIO]
 audio/x-realaudio      [AUDIO]
+audio/webm             [AUDIO]
+audio/x-matroska       [AUDIO]
 
 video/mpeg application/mpeg    [VIDEO]
 video/ogg                      [VIDEO]
 video/x-sgi-video              [VIDEO]
 video/x-flv                    [VIDEO]
+video/webm                     [VIDEO]
+video/x-matroska               [VIDEO]
 
 application/ogg application/x-ogg audio/ogg audio/x-ogg video/ogg video/x-ogg          [MULTIMEDIA]
 
index b9f7e85..4171d28 100644 (file)
@@ -64,7 +64,9 @@ audio/basic au snd
 audio/midi mid midi kar
 audio/mpeg mpga mp2 mp3
 audio/ogg oga ogg spx
+audio/webm webm
 audio/x-aiff aif aiff aifc
+audio/x-matroska mka mkv
 audio/x-mpegurl m3u
 audio/x-ogg oga ogg spx
 audio/x-pn-realaudio ram rm
@@ -114,7 +116,9 @@ video/mpeg mpeg mpg mpe
 video/ogg ogv ogm ogg
 video/quicktime qt mov
 video/vnd.mpegurl mxu
+video/webm webm
 video/x-flv flv
+video/x-matroska mkv mka
 video/x-msvideo avi
 video/x-ogg ogv ogm ogg
 video/x-sgi-movie movie