From 73d5fd73a295ff61ab686e7b137e40d226b00fb7 Mon Sep 17 00:00:00 2001 From: Ilmari Karonen Date: Fri, 21 Jan 2011 23:35:58 +0000 Subject: [PATCH] Check that the MIME type is allowed before checking that it matches the extension, and skip the latter check entirely if there is no extension so that the right message (filetype-missing) will be given instead of filetype-mime-mismatch. --- RELEASE-NOTES | 2 ++ includes/upload/UploadBase.php | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 59f15478e6..08fb831cd6 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -101,6 +101,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 26781) {{PAGENAME}} and related parser functions escape their output better. * (bug 26716) Provide link to instructions for external editor related preferences 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 === API changes in 1.18 === * (bug 26339) Throw warning when truncating an overlarge API result diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 86da818fd7..84f78b28c0 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -305,15 +305,16 @@ abstract class UploadBase { global $wgVerifyMimeType; if ( $wgVerifyMimeType ) { wfDebug ( "\n\nmime: <$mime> extension: <{$this->mFinalExtension}>\n\n"); - if ( !$this->verifyExtension( $mime, $this->mFinalExtension ) ) { - return array( 'filetype-mime-mismatch' ); - } - global $wgMimeTypeBlacklist; if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) { return array( 'filetype-badmime', $mime ); } + # XXX: Missing extension will be caught by validateName() via getTitle() + if ( $this->mFinalExtension != '' && !$this->verifyExtension( $mime, $this->mFinalExtension ) ) { + return array( 'filetype-mime-mismatch' ); + } + # Check IE type $fp = fopen( $this->mTempPath, 'rb' ); $chunk = fread( $fp, 256 ); -- 2.20.1