r83857 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83856‎ | r83857 | r83858 >
Date:22:02, 13 March 2011
Author:reedy
Status:ok
Tags:
Comment:
Don't reinvent the wheel in SpecialMIMEsearch.php to "parseMIME", use File::splitMime
Modified paths:
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMIMEsearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/File.php
@@ -133,10 +133,10 @@
134134 * Split an internet media type into its two components; if not
135135 * a two-part name, set the minor type to 'unknown'.
136136 *
137 - * @param $mime "text/html" etc
 137+ * @param string $mime "text/html" etc
138138 * @return array ("text", "html") etc
139139 */
140 - static function splitMime( $mime ) {
 140+ public static function splitMime( $mime ) {
141141 if( strpos( $mime, '/' ) !== false ) {
142142 return explode( '/', $mime, 2 );
143143 } else {
Index: trunk/phase3/includes/specials/SpecialMIMEsearch.php
@@ -75,8 +75,9 @@
7676 Xml::closeElement( 'form' )
7777 );
7878
79 - list( $this->major, $this->minor ) = self::parseMIME( $mime );
80 - if ( $this->major == '' || $this->minor == '' || !self::isValidType( $this->major ) ) {
 79+ list( $this->major, $this->minor ) = File::splitMime( $mime );
 80+ if ( $this->major == '' || $this->minor == '' || $this->minor == 'unknown' ||
 81+ !self::isValidType( $this->major ) ) {
8182 return;
8283 }
8384 parent::execute( $par );
@@ -105,21 +106,7 @@
106107
107108 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
108109 }
109 -
110 - protected static function parseMIME( $str ) {
111 - // searched for an invalid MIME type.
112 - if( strpos( $str, '/' ) === false ) {
113 - return array( '', '' );
114 - }
115110
116 - list( $major, $minor ) = explode( '/', $str, 2 );
117 -
118 - return array(
119 - ltrim( $major, ' ' ),
120 - rtrim( $minor, ' ' )
121 - );
122 - }
123 -
124111 protected static function isValidType( $type ) {
125112 // From maintenance/tables.sql => img_major_mime
126113 $types = array(

Status & tagging log