From 370e83bb0dfd0c70de268c93bf07ad5ee0897192 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 15 Aug 2008 01:29:47 +0200 Subject: Update auf 1.13.0 --- includes/MimeMagic.php | 51 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) (limited to 'includes/MimeMagic.php') diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index 2ca5892f..ec4505ab 100644 --- a/includes/MimeMagic.php +++ b/includes/MimeMagic.php @@ -9,7 +9,7 @@ * the file mime.types in the includes directory. */ define('MM_WELL_KNOWN_MIME_TYPES',<< 'audio/midi', 'OggS' => 'application/ogg', - + // Image formats... // Note that WMF may have a bare header, no magic number. "\x01\x00\x09\x00" => 'application/x-msmetafile', // Possibly prone to false positives? "\xd7\xcd\xc6\x9a" => 'application/x-msmetafile', '%PDF' => 'application/pdf', 'gimp xcf' => 'image/x-xcf', - + // Some forbidden fruit... 'MZ' => 'application/octet-stream', // DOS/Windows executable "\xca\xfe\xba\xbe" => 'application/octet-stream', // Mach-O binary "\x7fELF" => 'application/octet-stream', // ELF binary ); - + foreach( $headers as $magic => $candidate ) { if( strncmp( $head, $magic, strlen( $magic ) ) == 0 ) { wfDebug( __METHOD__ . ": magic header in $file recognized as $candidate\n" ); @@ -451,23 +451,16 @@ class MimeMagic { wfDebug( __METHOD__ . ": recognized $file as application/x-php\n" ); return "application/x-php"; } - + /* * look for XML formats (XHTML and SVG) */ $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'; } } @@ -511,11 +504,11 @@ class MimeMagic { return $mime; } } - + wfSuppressWarnings(); $gis = getimagesize( $file ); wfRestoreWarnings(); - + if( $gis && isset( $gis['mime'] ) ) { $mime = $gis['mime']; wfDebug( __METHOD__.": getimagesize detected $file as $mime\n" ); @@ -535,13 +528,13 @@ class MimeMagic { /** Internal mime type detection, please use guessMimeType() for application code instead. * Detection is done using an external program, if $wgMimeDetectorCommand is set. * Otherwise, the fileinfo extension and mime_content_type are tried (in this order), if they are available. - * If the dections fails and $ext is not false, the mime type is guessed from the file extension, using + * If the dections fails and $ext is not false, the mime type is guessed from the file extension, using * guessTypesForExtension. * If the mime type is still unknown, getimagesize is used to detect the mime type if the file is an image. * If no mime type can be determined, this function returns "unknown/unknown". * * @param string $file The file to check - * @param mixed $ext The file extension, or true to extract it from the filename. + * @param mixed $ext The file extension, or true to extract it from the filename. * Set it to false to ignore the extension. * * @return string the mime type of $file @@ -714,7 +707,7 @@ class MimeMagic { if ( !$m ) return MEDIATYPE_UNKNOWN; $m = explode( ' ', $m ); - } else { + } else { # Normalize mime type if ( isset( $this->mMimeTypeAliases[$extMime] ) ) { $extMime = $this->mMimeTypeAliases[$extMime]; @@ -734,5 +727,3 @@ class MimeMagic { return MEDIATYPE_UNKNOWN; } } - - -- cgit v1.2.3-54-g00ecf