From: Bryan Tong Minh Date: Sat, 22 Jan 2011 20:33:25 +0000 (+0000) Subject: (bug 26809) Uploading files with multiple extensions where one of the extensions... X-Git-Tag: 1.31.0-rc.0~32429 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22sites_tous%22%29%20.%20%22?a=commitdiff_plain;h=956b6518cfe4b61249b65564787e5c16f7c6a22b;p=lhc%2Fweb%2Fwiklou.git (bug 26809) Uploading files with multiple extensions where one of the extensions is blacklisted now gives the proper extension in the error message. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 08fb831cd6..45bbe08a57 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 3dd13dc6b6..008ba16901 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -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'] ); diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index a5fb844185..25a2b9d01c 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -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 ); } /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index c539482774..d1c4ed5d88 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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.', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 58f7e35277..0e26d22490 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -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]].',