<?php
/** Module defining helper functions for detecting and dealing with mime types.
*
- * @package MediaWiki
*/
/** Defines a set of well known mime types
image/svg+xml svg
image/tiff tiff tif
image/vnd.djvu djvu
+image/x-portable-pixmap ppm
text/plain txt
text/html html htm
video/ogg ogm ogg
image/svg image/svg+xml [DRAWING]
image/tiff [BITMAP]
image/vnd.djvu [BITMAP]
+image/x-portable-pixmap [BITMAP]
text/plain [TEXT]
text/html [TEXT]
video/ogg [VIDEO]
* file extension,
*
* Instances of this class are stateles, there only needs to be one global instance
-* of MimeMagic. Please use wfGetMimeMagic to get that instance.
-* @package MediaWiki
+* of MimeMagic. Please use MimeMagic::singleton() to get that instance.
*/
class MimeMagic {
*/
var $mExtToMime= NULL;
- /** Initializes the MimeMagic object. This is called by wfGetMimeMagic when instantiation
- * the global MimeMagic singleton object.
+ /** The singleton instance
+ */
+ private static $instance;
+
+ /** Initializes the MimeMagic object. This is called by MimeMagic::singleton().
*
* This constructor parses the mime.types and mime.info files and build internal mappings.
*/
- function MimeMagic() {
+ function __construct() {
/*
* --- load mime.types ---
*/
if (empty($ext)) continue;
- if (@$this->mMimeToExt[$mime]) $this->mMimeToExt[$mime] .= ' '.$ext;
+ if ( !empty($this->mMimeToExt[$mime])) $this->mMimeToExt[$mime] .= ' '.$ext;
else $this->mMimeToExt[$mime]= $ext;
$extensions= explode(' ',$ext);
$e= trim($e);
if (empty($e)) continue;
- if (@$this->mExtToMime[$e]) $this->mExtToMime[$e] .= ' '.$mime;
+ if ( !empty($this->mExtToMime[$e])) $this->mExtToMime[$e] .= ' '.$mime;
else $this->mExtToMime[$e]= $mime;
}
}
}
+ /**
+ * Get an instance of this class
+ */
+ static function &singleton() {
+ if ( !isset( self::$instance ) ) {
+ self::$instance = new MimeMagic;
+ }
+ return self::$instance;
+ }
+
/** returns a list of file extensions for a given mime type
* as a space separated string.
*/
}
- /** mime type detection. This uses detectMimeType to detect the mim type of the file,
+ /** mime type detection. This uses detectMimeType to detect the mime type of the file,
* but applies additional checks to determine some well known file formats that may be missed
* or misinterpreter by the default mime detection (namely xml based formats like XHTML or SVG).
*
#print "<br>ANALYSING $file ($mime): doctype= $doctype; tag= $tag<br>";
- if (strpos($doctype,"-//W3C//DTD SVG")===0) $mime= "image/svg";
- elseif ($tag==="svg") $mime= "image/svg";
+ if (strpos($doctype,"-//W3C//DTD SVG")===0) $mime= "image/svg+xml";
+ elseif ($tag==="svg") $mime= "image/svg+xml";
elseif (strpos($doctype,"-//W3C//DTD XHTML")===0) $mime= "text/html";
elseif ($tag==="html") $mime= "text/html";
-
- $test_more= false;
}
}
$match= array();
$prog= "";
- if (preg_match('%/?([^\s]+/)(w+)%sim',$head,$match)) $script= $match[2];
+ if (preg_match('%/?([^\s]+/)(w+)%sim',$head,$match)) {
+ $script= $match[2]; // FIXME: $script variable not used; should this be "$prog = $match[2];" instead?
+ }
$mime= "application/x-$prog";
}
# NOTE: this function is available since PHP 4.3.0, but only if
# PHP was compiled with --with-mime-magic or, before 4.3.2, with --enable-mime-magic.
#
- # On Winodws, you must set mime_magic.magicfile in php.ini to point to the mime.magic file bundeled with PHP;
+ # On Windows, you must set mime_magic.magicfile in php.ini to point to the mime.magic file bundeled with PHP;
# sometimes, this may even be needed under linus/unix.
#
# Also note that this has been DEPRECATED in favor of the fileinfo extension by PECL, see above.