Revert Special:Log to r20745 with non-ugly form
[lhc/web/wiklou.git] / includes / MimeMagic.php
index 435ab5d..9142cce 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /** Module defining helper functions for detecting and dealing with mime types.
  *
- * @package MediaWiki
  */
 
  /** Defines a set of well known mime types
@@ -26,6 +25,7 @@ image/png png
 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
@@ -54,6 +54,7 @@ image/png [BITMAP]
 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]
@@ -74,8 +75,7 @@ if ($wgLoadFileinfoExtension) {
 * 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 {
 
@@ -97,12 +97,15 @@ 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 ---
                */
@@ -146,7 +149,7 @@ class MimeMagic {
 
                        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);
@@ -155,7 +158,7 @@ class MimeMagic {
                                $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;
                        }
                }
@@ -227,6 +230,16 @@ class MimeMagic {
 
        }
 
+       /**
+        * 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.
        */
@@ -328,7 +341,7 @@ class MimeMagic {
        }
 
 
-       /** 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).
        *
@@ -386,12 +399,10 @@ class MimeMagic {
 
                                        #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;
                                }
                        }
 
@@ -413,7 +424,9 @@ class MimeMagic {
                                        $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";
                                }
@@ -497,7 +510,7 @@ class MimeMagic {
                        # 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.