(bug 26809) Uploading files with multiple extensions where one of the extensions...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 22 Jan 2011 20:33:25 +0000 (20:33 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 22 Jan 2011 20:33:25 +0000 (20:33 +0000)
RELEASE-NOTES
includes/specials/SpecialUpload.php
includes/upload/UploadBase.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php

index 08fb831..45bbe08 100644 (file)
@@ -103,6 +103,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   and add a comment to the ini control file explaining what is going on.
 * Trying to upload a file with no extension or with a disallowed MIME type now gives
   the right message instead of complaining about a MIME/extension mismatch
+* (bug 26809) Uploading files with multiple extensions where one of the extensions
+  is blacklisted now gives the proper extension in the error message.
 
 === API changes in 1.18 ===
 * (bug 26339) Throw warning when truncating an overlarge API result
index 3dd13dc..008ba16 100644 (file)
@@ -583,18 +583,26 @@ class SpecialUpload extends SpecialPage {
                                $this->showUploadError( wfMsgHtml( 'largefileserver' ) );
                                break;
                        case UploadBase::FILETYPE_BADTYPE:
-                               $finalExt = $details['finalExt'];
-                               $this->showUploadError(
-                                       wfMsgExt( 'filetype-banned-type',
-                                               array( 'parseinline' ),
-                                               htmlspecialchars( $finalExt ),
-                                               implode(
-                                                       wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
-                                                       $wgFileExtensions
-                                               ),
-                                               $wgLang->formatNum( count( $wgFileExtensions ) )
-                                       )
-                               );
+                               $msg = wfMessage( 'filetype-banned-type' );
+                               $sep = wfMsg( 'comma-separator' );
+                               if ( isset( $details['blacklistedExt'] ) ) {
+                                       $msg->params( implode( $sep, $details['blacklistedExt'] ) );
+                               } else {
+                                       $msg->params( $details['finalExt'] );
+                               }
+                               $msg->params( implode( $sep, $wgFileExtensions ),
+                                       count( $wgFileExtensions ) );
+                               
+                               // Add PLURAL support for the first parameter. This results 
+                               // in a bit unlogical parameter sequence, but does not break 
+                               // old translations 
+                               if ( isset( $details['blacklistedExt'] ) ) {
+                                       $msg->numParams( count( $details['blacklistedExt'] ) );
+                               } else {
+                                       $msg->numParams( 1 );
+                               }
+                               
+                               $this->showUploadError( $msg->parse() );
                                break;
                        case UploadBase::VERIFICATION_ERROR:
                                unset( $details['status'] );
index a5fb844..25a2b9d 100644 (file)
@@ -287,6 +287,9 @@ abstract class UploadBase {
                        }
                        if ( $this->mTitleError == self::FILETYPE_BADTYPE ) {
                                $result['finalExt'] = $this->mFinalExtension;
+                               if ( count( $this->mBlackListedExtensions ) ) {
+                                       $result['blacklistedExt'] = $this->mBlackListedExtensions;
+                               }
                        }
                        return $result;
                }
@@ -566,12 +569,16 @@ abstract class UploadBase {
                /* Don't allow users to override the blacklist (check file extension) */
                global $wgCheckFileExtensions, $wgStrictFileExtensions;
                global $wgFileExtensions, $wgFileBlacklist;
+               
+               $blackListedExtensions = $this->checkFileExtensionList( $ext, $wgFileBlacklist );
+               
                if ( $this->mFinalExtension == '' ) {
                        $this->mTitleError = self::FILETYPE_MISSING;
                        return $this->mTitle = null;
-               } elseif ( $this->checkFileExtensionList( $ext, $wgFileBlacklist ) ||
+               } elseif ( $blackListedExtensions ||
                                ( $wgCheckFileExtensions && $wgStrictFileExtensions &&
                                        !$this->checkFileExtension( $this->mFinalExtension, $wgFileExtensions ) ) ) {
+                       $this->mBlackListedExtensions = $blackListedExtensions;
                        $this->mTitleError = self::FILETYPE_BADTYPE;
                        return $this->mTitle = null;
                }
@@ -699,19 +706,14 @@ abstract class UploadBase {
 
        /**
         * Perform case-insensitive match against a list of file extensions.
-        * Returns true if any of the extensions are in the list.
+        * Returns an array of matching extensions.
         *
         * @param $ext Array
         * @param $list Array
         * @return Boolean
         */
        public static function checkFileExtensionList( $ext, $list ) {
-               foreach( $ext as $e ) {
-                       if( in_array( strtolower( $e ), $list ) ) {
-                               return true;
-                       }
-               }
-               return false;
+               return array_intersect( array_map( 'strtolower', $ext ), $list );
        }
 
        /**
index c539482..d1c4ed5 100644 (file)
@@ -2114,7 +2114,7 @@ Please rename the file and try uploading it again.',
 'filetype-bad-ie-mime'        => 'Cannot upload this file because Internet Explorer would detect it as "$1", which is a disallowed and potentially dangerous file type.',
 'filetype-unwanted-type'      => "'''\".\$1\"''' is an unwanted file type.
 Preferred {{PLURAL:\$3|file type is|file types are}} \$2.",
-'filetype-banned-type'        => "'''\".\$1\"''' is not a permitted file type.
+'filetype-banned-type'        => "'''\".\$1\"''' {{PLURAL:\$4|is not a permitted file type|are not permitted file types}}.
 Permitted {{PLURAL:\$3|file type is|file types are}} \$2.",
 'filetype-missing'            => 'The file has no extension (like ".jpg").',
 'empty-file'                  => 'The file you submitted was empty.',
index 58f7e35..0e26d22 100644 (file)
@@ -1752,9 +1752,10 @@ Text displayed when uploading a file using [[Special:Upload]].",
 'filetype-unwanted-type'      => "* $1 is the extension of the file which cannot be uploaded
 * $2 is the list of file extensions that can be uploaded (Example: ''png, gif, jpg, jpeg, ogg, pdf, svg.'')
 * $3 is the number of allowed file formats (to be used for the PLURAL function)",
-'filetype-banned-type'        => "* $1 is the extension of the file which cannot be uploaded
+'filetype-banned-type'        => "* $1 is the extension(s) of the file which cannot be uploaded
 * $2 is the list of file extensions that can be uploaded (Example: ''png, gif, jpg, jpeg, ogg, pdf, svg.'')
-* $3 is the number of allowed file formats (to be used for the PLURAL function)",
+* $3 is the number of allowed file formats (to be used for the PLURAL function)
+* $4 is the number of extensions that could not be uploaded (to be used for the PLURAL function)",
 'filetype-missing'            => 'Error when uploading a file with no extension',
 'verification-error'          => 'Error message shown when an uploaded file contents does not pass verification, i.e. the file is corrupted, it is not the type it claims to be etc.',
 'large-file'                  => 'Variables $1 and $2 have appropriate unit symbols already. See for example [[Mediawiki:size-kilobytes]].',