(bug 26130) Revert changes to WebStart.php in r72349, which turn out to have been...
[lhc/web/wiklou.git] / includes / MimeMagic.php
index da9d1ab..7d7fedd 100644 (file)
@@ -402,6 +402,7 @@ class MimeMagic {
                        // Formats we recognize magic numbers for
                        'djvu', 'ogx', 'ogg', 'ogv', 'oga', 'spx',
                        'mid', 'pdf', 'wmf', 'xcf', 'webm', 'mkv', 'mka',
+                       'webp',
 
                        // XML formats we sure hope we recognize reliably
                        'svg',
@@ -430,7 +431,8 @@ class MimeMagic {
        function improveTypeFromExtension( $mime, $ext ) {
                if ( $mime === "unknown/unknown" ) {
                        if( $this->isRecognizableExtension( $ext ) ) {
-                               wfDebug( __METHOD__. ": refusing to guess mime type for .$ext file, we should have recognized it\n" );
+                               wfDebug( __METHOD__. ": refusing to guess mime type for .$ext file, " .
+                                       "we should have recognized it\n" );
                        } else {
                                /* Not something we can detect, so simply 
                                * trust the file extension */
@@ -443,7 +445,8 @@ class MimeMagic {
                                * find the proper mime type for that file extension */
                                $mime = $this->guessTypesForExtension( $ext );
                        } else {
-                               wfDebug( __METHOD__. ": refusing to guess better type for $mime file, .$ext is not a known OPC extension.\n" );
+                               wfDebug( __METHOD__. ": refusing to guess better type for $mime file, " . 
+                                       ".$ext is not a known OPC extension.\n" );
                                $mime = "application/zip";
                        }
                }
@@ -470,7 +473,8 @@ class MimeMagic {
        */
        function guessMimeType( $file, $ext = true ) {
                if( $ext ) { # TODO: make $ext default to false. Or better, remove it.
-                       wfDebug( __METHOD__.": WARNING: use of the \$ext parameter is deprecated. Use improveTypeFromExtension(\$mime, \$ext) instead.\n" );
+                       wfDebug( __METHOD__.": WARNING: use of the \$ext parameter is deprecated. " .
+                               "Use improveTypeFromExtension(\$mime, \$ext) instead.\n" );
                }
 
                $mime = $this->doGuessMimeType( $file, $ext );
@@ -545,6 +549,12 @@ class MimeMagic {
                        return "unknown/unknown";
                }
 
+               /* Look for WebP */
+               if( strncmp( $head, "RIFF", 4 ) == 0 && strncmp( substr( $head, 8, 8), "WEBPVP8 ", 8 ) == 0 ) {
+                       wfDebug( __METHOD__ . ": recognized file as image/webp\n" );
+                       return "image/webp";
+               }
+
                /*
                 * 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
@@ -663,7 +673,8 @@ class MimeMagic {
         */
        function detectZipType( $header, $tail = null, $ext = false ) {
                if( $ext ) { # TODO: remove $ext param
-                       wfDebug( __METHOD__.": WARNING: use of the \$ext parameter is deprecated. Use improveTypeFromExtension(\$mime, \$ext) instead.\n" );
+                       wfDebug( __METHOD__.": WARNING: use of the \$ext parameter is deprecated. " .
+                               "Use improveTypeFromExtension(\$mime, \$ext) instead.\n" );
                }
 
                $mime = 'application/zip';
@@ -894,7 +905,6 @@ class MimeMagic {
                }
 
                # Check for entry for file extension
-               $e = null;
                if ( $path ) {
                        $i = strrpos( $path, '.' );
                        $e = strtolower( $i ? substr( $path, $i + 1 ) : '' );