(bug 26285) Extensions will be automatically generated on upload if the user specifie...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 27 Jan 2011 21:15:50 +0000 (21:15 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 27 Jan 2011 21:15:50 +0000 (21:15 +0000)
Note that this still will throw a warning.

RELEASE-NOTES
includes/upload/UploadBase.php

index 154b400..9c22508 100644 (file)
@@ -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
index b48cecb..af9a26e 100644 (file)
@@ -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) */