http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70103

Revision: 70103
Author:   hartman
Date:     2010-07-28 19:24:00 +0000 (Wed, 28 Jul 2010)

Log Message:
-----------
Recognize webm and matroska files. See also Bug 23888

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).

Modified Paths:
--------------
    trunk/phase3/includes/MimeMagic.php
    trunk/phase3/includes/mime.info
    trunk/phase3/includes/mime.types

Modified: trunk/phase3/includes/MimeMagic.php
===================================================================
--- trunk/phase3/includes/MimeMagic.php 2010-07-28 18:56:42 UTC (rev 70102)
+++ trunk/phase3/includes/MimeMagic.php 2010-07-28 19:24:00 UTC (rev 70103)
@@ -396,7 +396,8 @@
                        '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 @@
                        }
                }
 
+               /* 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

Modified: trunk/phase3/includes/mime.info
===================================================================
--- trunk/phase3/includes/mime.info     2010-07-28 18:56:42 UTC (rev 70102)
+++ trunk/phase3/includes/mime.info     2010-07-28 19:24:00 UTC (rev 70103)
@@ -35,11 +35,15 @@
 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]
 

Modified: trunk/phase3/includes/mime.types
===================================================================
--- trunk/phase3/includes/mime.types    2010-07-28 18:56:42 UTC (rev 70102)
+++ trunk/phase3/includes/mime.types    2010-07-28 19:24:00 UTC (rev 70103)
@@ -64,7 +64,9 @@
 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/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



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to