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
$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'] );
}
if ( $this->mTitleError == self::FILETYPE_BADTYPE ) {
$result['finalExt'] = $this->mFinalExtension;
+ if ( count( $this->mBlackListedExtensions ) ) {
+ $result['blacklistedExt'] = $this->mBlackListedExtensions;
+ }
}
return $result;
}
/* 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;
}
/**
* 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 );
}
/**
'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.',
'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]].',