From ada82a6d3d549ad1c06674d73404523af5226f37 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 13 Mar 2011 22:02:40 +0000 Subject: [PATCH] Don't reinvent the wheel in SpecialMIMEsearch.php to "parseMIME", use File::splitMime --- includes/filerepo/File.php | 4 ++-- includes/specials/SpecialMIMEsearch.php | 19 +++---------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index e4de3383bc..8d9c42c470 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -133,10 +133,10 @@ abstract class File { * Split an internet media type into its two components; if not * a two-part name, set the minor type to 'unknown'. * - * @param $mime "text/html" etc + * @param string $mime "text/html" etc * @return array ("text", "html") etc */ - static function splitMime( $mime ) { + public static function splitMime( $mime ) { if( strpos( $mime, '/' ) !== false ) { return explode( '/', $mime, 2 ); } else { diff --git a/includes/specials/SpecialMIMEsearch.php b/includes/specials/SpecialMIMEsearch.php index c9e8898d0c..43f8f8dc5f 100644 --- a/includes/specials/SpecialMIMEsearch.php +++ b/includes/specials/SpecialMIMEsearch.php @@ -75,8 +75,9 @@ class MIMEsearchPage extends QueryPage { Xml::closeElement( 'form' ) ); - list( $this->major, $this->minor ) = self::parseMIME( $mime ); - if ( $this->major == '' || $this->minor == '' || !self::isValidType( $this->major ) ) { + list( $this->major, $this->minor ) = File::splitMime( $mime ); + if ( $this->major == '' || $this->minor == '' || $this->minor == 'unknown' || + !self::isValidType( $this->major ) ) { return; } parent::execute( $par ); @@ -105,21 +106,7 @@ class MIMEsearchPage extends QueryPage { return "($download) $plink . . $dimensions . . $bytes . . $user . . $time"; } - - protected static function parseMIME( $str ) { - // searched for an invalid MIME type. - if( strpos( $str, '/' ) === false ) { - return array( '', '' ); - } - list( $major, $minor ) = explode( '/', $str, 2 ); - - return array( - ltrim( $major, ' ' ), - rtrim( $minor, ' ' ) - ); - } - protected static function isValidType( $type ) { // From maintenance/tables.sql => img_major_mime $types = array( -- 2.20.1