From: Bryan Tong Minh Date: Thu, 27 Jan 2011 21:15:50 +0000 (+0000) Subject: (bug 26285) Extensions will be automatically generated on upload if the user specifie... X-Git-Tag: 1.31.0-rc.0~32332 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=659af36f3a7989081bcbffc9a7de9096d2c289e2;p=lhc%2Fweb%2Fwiklou.git (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. --- 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) */