Don't reinvent the wheel in SpecialMIMEsearch.php to "parseMIME", use File::splitMime
authorSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 22:02:40 +0000 (22:02 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 22:02:40 +0000 (22:02 +0000)
includes/filerepo/File.php
includes/specials/SpecialMIMEsearch.php

index e4de338..8d9c42c 100644 (file)
@@ -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 {
index c9e8898..43f8f8d 100644 (file)
@@ -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(