Index: includes/MimeMagic.php =================================================================== --- includes/MimeMagic.php (revision 103311) +++ includes/MimeMagic.php (working copy) @@ -469,7 +469,7 @@ 'webp', // XML formats we sure hope we recognize reliably - 'svg', + 'svg', 'svgz', ); return in_array( strtolower( $extension ), $types ); } @@ -661,11 +661,16 @@ */ $xml = new XmlTypeCheck( $file ); if ( $xml->wellFormed ) { - global $wgXMLMimeTypes; - if ( isset( $wgXMLMimeTypes[$xml->getRootElement()] ) ) { - return $wgXMLMimeTypes[$xml->getRootElement()]; - } else { - return 'application/xml'; + global $wgXMLMimeTypes, $wgXMLMayBeCompressed; + $t = $wgXMLMimeTypes[$xml->getRootElement()]; + if ( !$xml->compressed ) { + if( $t ) { + return $t; + } else { + return 'application/xml'; + } + } elseif ( $wgXMLMayBeCompressed[$t] ) { + return $t; } } Index: includes/media/SVGMetadataExtractor.php =================================================================== --- includes/media/SVGMetadataExtractor.php (revision 103311) +++ includes/media/SVGMetadataExtractor.php (working copy) @@ -59,13 +59,13 @@ if ( $size > $wgSVGMetadataCutoff ) { $this->debug( "SVG is $size bytes, which is bigger than $wgSVGMetadataCutoff. Truncating." ); - $contents = file_get_contents( $source, false, null, -1, $wgSVGMetadataCutoff ); + $contents = file_get_contents( "compress.zlib://$source", false, null, -1, $wgSVGMetadataCutoff ); if ($contents === false) { throw new MWException( 'Error reading SVG file.' ); } $this->reader->XML( $contents, null, LIBXML_NOERROR | LIBXML_NOWARNING ); } else { - $this->reader->open( $source, null, LIBXML_NOERROR | LIBXML_NOWARNING ); + $this->reader->open( "compress.zlib://$source", null, LIBXML_NOERROR | LIBXML_NOWARNING ); } $this->metadata['width'] = self::DEFAULT_WIDTH; Index: includes/DefaultSettings.php =================================================================== --- includes/DefaultSettings.php (revision 103311) +++ includes/DefaultSettings.php (working copy) @@ -440,6 +440,11 @@ */ $wgMaxUploadSize = 1024*1024*100; # 100MB +$wgXMLMayBeCompressed = array( + 'image/svg+xml' => true, + 'application/x-dia-diagram' => true, +); + /** * Point the upload navigation link to an external URL * Useful if you want to use a shared repository by default Index: includes/XmlTypeCheck.php =================================================================== --- includes/XmlTypeCheck.php (revision 103311) +++ includes/XmlTypeCheck.php (working copy) @@ -20,6 +20,12 @@ public $rootElement = ''; /** + * Name of file compression type (can be only 'gzip' by now), + * or FALSE if the file is uncompressed. + */ + public $compressed = false; + + /** * @param $file string filename * @param $filterCallback callable (optional) * Function to call to do additional custom validity checks from the @@ -54,6 +60,18 @@ if ( file_exists( $fname ) ) { $file = fopen( $fname, "rb" ); + $gz = fread( $file, 2 ); + if ( $gz == "\x1F\x8B" ) { + if ( function_exists( 'gzopen' ) ) { + fclose( $file ); + $this->compressed = 'gzip'; + $file = gzopen( $fname, "rb" ); + } else { + return; + } + } else { + fseek( $file, 0, SEEK_SET ); + } if ( $file ) { do { $chunk = fread( $file, 32768 );