Remove dead mime_content_type() code paths
authorKevin Israel <pleasestand@live.com>
Fri, 18 Jul 2014 06:05:26 +0000 (02:05 -0400)
committerKrinkle <krinklemail@gmail.com>
Wed, 3 Sep 2014 16:35:35 +0000 (16:35 +0000)
Since PHP 5.3, mime_content_type() is implemented as part of PHP's
fileinfo extension and thus is deprecated in favor of the newer
alternatives provided by that extension (already in use).

Also updated a comment in DefaultSettings.php that mentioned the
function. Did not modify lessc.inc.php, a third-party library
maintained separately from MediaWiki.

Change-Id: Ic4a0873989ddb634ec9a05c3340941a9ba3f5ec5

includes/DefaultSettings.php
includes/MimeMagic.php
includes/libs/CSSMin.php

index 5fc7377..f9e50f0 100644 (file)
@@ -1156,7 +1156,7 @@ $wgMimeInfoFile = 'includes/mime.info';
  * Sets an external MIME detector program. The command must print only
  * the MIME type to standard output.
  * The name of the file to process will be appended to the command given here.
- * If not set or NULL, mime_content_type will be used if available.
+ * If not set or NULL, PHP's fileinfo extension will be used if available.
  *
  * @par Example:
  * @code
index 8f0a2af..656c1e0 100644 (file)
@@ -898,9 +898,9 @@ class MimeMagic {
        /**
         * Internal MIME type detection. 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 detections fails and $ext is not false, the MIME
-        * type is guessed from the file extension, using guessTypesForExtension.
+        * extension is tried if it is available. If detection 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,
@@ -927,18 +927,7 @@ class MimeMagic {
                        $args = wfEscapeShellArg( $file );
                        $m = wfShellExec( "$wgMimeDetectorCommand $args" );
                } elseif ( function_exists( "finfo_open" ) && function_exists( "finfo_file" ) ) {
-
-                       # This required the fileinfo extension by PECL,
-                       # see http://pecl.php.net/package/fileinfo
-                       # This must be compiled into PHP
-                       #
-                       # finfo is the official replacement for the deprecated
-                       # mime_content_type function, see below.
-                       #
-                       # If you may need to load the fileinfo extension at runtime, set
-                       # $wgLoadFileinfoExtension in LocalSettings.php
-
-                       $mime_magic_resource = finfo_open( FILEINFO_MIME ); /* return MIME type ala mimetype extension */
+                       $mime_magic_resource = finfo_open( FILEINFO_MIME );
 
                        if ( $mime_magic_resource ) {
                                $m = finfo_file( $mime_magic_resource, $file );
@@ -946,21 +935,6 @@ class MimeMagic {
                        } else {
                                wfDebug( __METHOD__ . ": finfo_open failed on " . FILEINFO_MIME . "!\n" );
                        }
-               } elseif ( function_exists( "mime_content_type" ) ) {
-
-                       # 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 Windows, you must set mime_magic.magicfile in php.ini to point
-                       # to the mime.magic file bundled with PHP; sometimes, this may even
-                       # be needed under *nix.
-                       #
-                       # Also note that this has been DEPRECATED in favor of the fileinfo
-                       # extension by PECL, see above.
-                       # See http://www.php.net/manual/en/ref.mime-magic.php for details.
-
-                       $m = mime_content_type( $file );
                } else {
                        wfDebug( __METHOD__ . ": no magic mime detector found!\n" );
                }
index 4e2ca83..dcaa685 100644 (file)
@@ -135,27 +135,21 @@ class CSSMin {
         */
        public static function getMimeType( $file ) {
                $realpath = realpath( $file );
-               // Try a couple of different ways to get the MIME-type of a file, in order of
-               // preference
                if (
                        $realpath
                        && function_exists( 'finfo_file' )
                        && function_exists( 'finfo_open' )
                        && defined( 'FILEINFO_MIME_TYPE' )
                ) {
-                       // As of PHP 5.3, this is how you get the MIME-type of a file; it uses the Fileinfo
-                       // PECL extension
                        return finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $realpath );
-               } elseif ( function_exists( 'mime_content_type' ) ) {
-                       // Before this was deprecated in PHP 5.3, this was how you got the MIME-type of a file
-                       return mime_content_type( $file );
-               } else {
-                       // Worst-case scenario has happened, use the file extension to infer the MIME-type
-                       $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
-                       if ( isset( self::$mimeTypes[$ext] ) ) {
-                               return self::$mimeTypes[$ext];
-                       }
                }
+
+               // Infer the MIME-type from the file extension
+               $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
+               if ( isset( self::$mimeTypes[$ext] ) ) {
+                       return self::$mimeTypes[$ext];
+               }
+
                return false;
        }