(bug 15543) fix for r38139: don't include $wgUser->mTouched and smaxage=0 in query...
[lhc/web/wiklou.git] / includes / MimeMagic.php
index e4af1f0..8f903a8 100644 (file)
@@ -9,7 +9,7 @@
  * the file mime.types in the includes directory.
  */
 define('MM_WELL_KNOWN_MIME_TYPES',<<<END_STRING
-application/ogg ogg ogm
+application/ogg ogg ogm ogv
 application/pdf pdf
 application/x-javascript js
 application/x-shockwave-flash swf
@@ -29,7 +29,7 @@ image/x-portable-pixmap ppm
 image/x-xcf xcf
 text/plain txt
 text/html html htm
-video/ogg ogm ogg
+video/ogg ogm ogg ogv
 video/mpeg mpg mpeg
 END_STRING
 );
@@ -360,7 +360,7 @@ class MimeMagic {
                        'xbm',
 
                        // Formats we recognize magic numbers for
-                       'djvu', 'ogg', 'mid', 'pdf', 'wmf', 'xcf',
+                       'djvu', 'ogg', 'ogv', 'mid', 'pdf', 'wmf', 'xcf',
 
                        // XML formats we sure hope we recognize reliably
                        'svg',
@@ -402,6 +402,8 @@ class MimeMagic {
                wfRestoreWarnings();
                if( !$f ) return "unknown/unknown";
                $head = fread( $f, 1024 );
+               fseek( $f, -65558, SEEK_END );
+               $tail = fread( $f, 65558 ); // 65558 = maximum size of a zip EOCDR
                fclose( $f );
 
                // Hardcode a few magic number checks...
@@ -457,17 +459,10 @@ class MimeMagic {
                 */
                $xml = new XmlTypeCheck( $file );
                if( $xml->wellFormed ) {
-                       $types = array(
-                               'http://www.w3.org/2000/svg:svg'    => 'image/svg+xml',
-                               'svg'                               => 'image/svg+xml',
-                               'http://www.w3.org/1999/xhtml:html' => 'text/html', // application/xhtml+xml?
-                               'html'                              => 'text/html', // application/xhtml+xml?
-                       );
-                       if( isset( $types[$xml->rootElement] ) ) {
-                               $mime = $types[$xml->rootElement];
-                               return $mime;
+                       global $wgXMLMimeTypes;
+                       if( isset( $wgXMLMimeTypes[$xml->rootElement] ) ) {
+                               return $wgXMLMimeTypes[$xml->rootElement];
                        } else {
-                               /// Fixme -- this would be the place to allow additional XML type checks
                                return 'application/xml';
                        }
                }
@@ -512,6 +507,12 @@ class MimeMagic {
                        }
                }
 
+               // Check for ZIP (before getimagesize)
+               if ( strpos( $tail, "PK\x05\x06" ) !== false ) {
+                       wfDebug( __METHOD__.": ZIP header present at end of $file\n" );
+                       return 'application/zip';
+               }
+
                wfSuppressWarnings();
                $gis = getimagesize( $file );
                wfRestoreWarnings();
@@ -520,8 +521,6 @@ class MimeMagic {
                        $mime = $gis['mime'];
                        wfDebug( __METHOD__.": getimagesize detected $file as $mime\n" );
                        return $mime;
-               } else {
-                       return false;
                }
 
                // Also test DjVu
@@ -530,6 +529,8 @@ class MimeMagic {
                        wfDebug( __METHOD__.": detected $file as image/vnd.djvu\n" );
                        return 'image/vnd.djvu';
                }
+
+               return false;
        }
 
        /** Internal mime type detection, please use guessMimeType() for application code instead.