[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Re-introduce use of mime_content_type()
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/367640 ) Change subject: Re-introduce use of mime_content_type() .. Re-introduce use of mime_content_type() Follows-up eac059c7224. See also https://stackoverflow.com/a/39676272/319266. This function was never deprecated. For a short time, the www.php.net manual page for `mime_content_type` wrongly documented it as having been deprecated in PHP 5.3, but this wasn't true, and it has been present in every PHP version since PHP 4.3, including PHP 7 and HHVM 2.3+. Between PHP 4.3.0-4.3.2 and PHP 5.0-5.3, the function would be absent if the Mimemagic extension was not enabled at compile-time. However, while mime_content_type was first introduced by the Mimemagic PHP ext, it is backend by the Finfo extension since PHP 5.3.0. Confirmed via https://3v4l.org/IQC1Q. * CSSMin: Revert conditional use of finfo back to unconditional use of mime_content_type. * MimeAnalyzer: Replace conditional use of finfo with unconditional use use of mime_content_type. Also remove the now-redundant 'else' branch. The 'else' branch existed because this code was written at a time where MediaWiki still supported PHP 4, of which some minor versions could sometimes be compiled without this function. Change-Id: Iee4a0b6f616a469bb779c40e386045f9c3200446 --- M includes/DefaultSettings.php M includes/libs/CSSMin.php M includes/libs/filebackend/FileBackendStore.php M includes/libs/mime/MimeAnalyzer.php 4 files changed, 5 insertions(+), 31 deletions(-) Approvals: Tim Starling: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f35715e..74d5fa4 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1304,7 +1304,7 @@ * 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, PHP's fileinfo extension will be used if available. + * If not set or NULL, PHP's mime_content_type function will be used. * * @par Example: * @code diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 9e060cd..4c672f4 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -188,17 +188,7 @@ return self::$mimeTypes[$ext]; } - $realpath = realpath( $file ); - if ( - $realpath - && function_exists( 'finfo_file' ) - && function_exists( 'finfo_open' ) - && defined( 'FILEINFO_MIME_TYPE' ) - ) { - return finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $realpath ); - } - - return false; + return mime_content_type( realpath( $file ) ); } /** diff --git a/includes/libs/filebackend/FileBackendStore.php b/includes/libs/filebackend/FileBackendStore.php index 9bfdbe8..77473d1 100644 --- a/includes/libs/filebackend/FileBackendStore.php +++ b/includes/libs/filebackend/FileBackendStore.php @@ -1840,14 +1840,8 @@ return call_user_func_array( $this->mimeCallback, func_get_args() ); } - $mime = null; - if ( $fsPath !== null && function_exists( 'finfo_file' ) ) { - $finfo = finfo_open( FILEINFO_MIME_TYPE ); - $mime = finfo_file( $finfo, $fsPath ); - finfo_close( $finfo ); - } - - return is_string( $mime ) ? $mime : 'unknown/unknown'; + $mime = ( $fsPath !== null ) ? mime_content_type( $fsPath ) : false; + return $mime ?: 'unknown/unknown'; } } diff --git a/includes/libs/mime/MimeAnalyzer.php b/includes/libs/mime/MimeAnalyzer.php index 631bb17..4d860bb 100644 --- a/includes/libs/mime/MimeAnalyzer.php +++ b/includes/libs/mime/MimeAnalyzer.php @@ -988,18 +988,8 @@ $m = null; if ( $callback ) { $m = $callback( $file ); - } elseif ( function_exists( "finfo_open" ) && function_exists( "finfo_file" ) ) { - $mime_magic_resource = finfo_open( FILEINFO_MIME ); - - if ( $mime_magic_resource ) { - $m = finfo_file( $mime_magic_resource, $file ); - finfo_close( $mime_magic_resource ); - } else { - $this->logger->info( __METHOD__ . - ": finfo_open failed on " . FILEINFO_MIME . "!\n" ); - } } else { - $this->logger->info( __METHOD__ . ": no magic mime detector foun
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Re-introduce use of mime_content_type()
Krinkle has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/367640 ) Change subject: Re-introduce use of mime_content_type() .. Re-introduce use of mime_content_type() Follows-up eac059c7224. See also https://stackoverflow.com/a/39676272/319266. This function was never deprecated. For a short time, the www.php.net manual page for `mime_content_type` wrongly documented it as having been deprecated in PHP 5.3, but this wasn't true, and it has been present in every PHP version since PHP 4.3, including PHP 7 and HHVM 2.3+. Between PHP 4.3.0-4.3.2 and PHP 5.0-5.3, the function would be absent if the Mimemagic extension was not enabled at compile-time. However, while mime_content_type was first introduced by the Mimemagic PHP ext, it is backend by the Finfo extension since PHP 5.3.0. Confirmed via https://3v4l.org/IQC1Q. * CSSMin: Revert conditional use of finfo back to unconditional use of mime_content_type. * MimeAnalyzer: Replace conditional use of finfo with unconditional use use of mime_content_type. Also remove the now-redundant 'else' branch. The 'else' branch existed because this code was written at a time where MediaWiki still supported PHP 4, of which some minor versions could sometimes be compiled without this function. Change-Id: Iee4a0b6f616a469bb779c40e386045f9c3200446 --- M includes/DefaultSettings.php M includes/libs/CSSMin.php M includes/libs/filebackend/FileBackendStore.php M includes/libs/mime/MimeAnalyzer.php 4 files changed, 5 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/40/367640/1 diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f35715e..74d5fa4 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1304,7 +1304,7 @@ * 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, PHP's fileinfo extension will be used if available. + * If not set or NULL, PHP's mime_content_type function will be used. * * @par Example: * @code diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 9e060cd..4c672f4 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -188,17 +188,7 @@ return self::$mimeTypes[$ext]; } - $realpath = realpath( $file ); - if ( - $realpath - && function_exists( 'finfo_file' ) - && function_exists( 'finfo_open' ) - && defined( 'FILEINFO_MIME_TYPE' ) - ) { - return finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $realpath ); - } - - return false; + return mime_content_type( realpath( $file ) ); } /** diff --git a/includes/libs/filebackend/FileBackendStore.php b/includes/libs/filebackend/FileBackendStore.php index 9bfdbe8..4c6b265 100644 --- a/includes/libs/filebackend/FileBackendStore.php +++ b/includes/libs/filebackend/FileBackendStore.php @@ -1841,10 +1841,8 @@ } $mime = null; - if ( $fsPath !== null && function_exists( 'finfo_file' ) ) { - $finfo = finfo_open( FILEINFO_MIME_TYPE ); - $mime = finfo_file( $finfo, $fsPath ); - finfo_close( $finfo ); + if ( $fsPath !== null ) { + $mime = mime_content_type( $fsPath ); } return is_string( $mime ) ? $mime : 'unknown/unknown'; diff --git a/includes/libs/mime/MimeAnalyzer.php b/includes/libs/mime/MimeAnalyzer.php index 631bb17..ac821a5 100644 --- a/includes/libs/mime/MimeAnalyzer.php +++ b/includes/libs/mime/MimeAnalyzer.php @@ -988,18 +988,8 @@ $m = null; if ( $callback ) { $m = $callback( $file ); - } elseif ( function_exists( "finfo_open" ) && function_exists( "finfo_file" ) ) { - $mime_magic_resource = finfo_open( FILEINFO_MIME ); - - if ( $mime_magic_resource ) { - $m = finfo_file( $mime_magic_resource, $file ); - finfo_close( $mime_magic_resource ); - } else { - $this->logger->info( __METHOD__ . - ": finfo_open failed on " . FILEINFO_MIME . "!\n" ); - } } else { - $this->logger->info( __METHOD__ . ": no magic mime detector found!\n" ); + $m = mime_content_type( $file ); } if ( $m ) { -- To view, visit https://gerri