From eac059c7224228b363b59080568faf062eaa86f2 Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Fri, 18 Jul 2014 02:05:26 -0400 Subject: [PATCH] Remove dead mime_content_type() code paths 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 | 2 +- includes/MimeMagic.php | 34 ++++------------------------------ includes/libs/CSSMin.php | 20 +++++++------------- 3 files changed, 12 insertions(+), 44 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 5fc73776a9..f9e50f00e5 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index 8f0a2af230..656c1e0846 100644 --- a/includes/MimeMagic.php +++ b/includes/MimeMagic.php @@ -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" ); } diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 4e2ca836d8..dcaa6857a2 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -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; } -- 2.20.1