From 659af36f3a7989081bcbffc9a7de9096d2c289e2 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Thu, 27 Jan 2011 21:15:50 +0000 Subject: [PATCH] (bug 26285) Extensions will be automatically generated on upload if the user specified a filename without extension. Note that this still will throw a warning. --- RELEASE-NOTES | 2 ++ includes/upload/UploadBase.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 154b400075..9c22508bf7 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -55,6 +55,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Upload warnings now show a thumbnail of the uploaded file * Introduced the edittools-upload message, which will be inserted under the upload form instead of edittools if available +* (bug 26285) Extensions will be automatically generated on upload if the user + specified a filename without extension. === Bug fixes in 1.18 === * (bug 23119) WikiError class and subclasses are now marked as deprecated diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index b48cecb144..af9a26ec86 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -564,6 +564,24 @@ abstract class UploadBase { $this->mFinalExtension = trim( $ext[count( $ext ) - 1] ); } else { $this->mFinalExtension = ''; + + # No extension, try guessing one + $magic = MimeMagic::singleton(); + $mime = $magic->guessMimeType( $this->mTempPath ); + if ( $mime !== 'unknown/unknown' ) { + # Get a space separated list of extensions + $extList = $magic->getExtensionsForType( $mime ); + if ( $extList ) { + # Set the extension to the canonical extension + $this->mFinalExtension = strtok( $extList, ' ' ); + + # Fix up the other variables + $this->mFilteredName .= ".{$this->mFinalExtension}"; + $nt = Title::makeTitleSafe( NS_FILE, $this->mFilteredName ); + $ext = array( $this->mFinalExtension ); + } + } + } /* Don't allow users to override the blacklist (check file extension) */ -- 2.20.1