r81106 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81105‎ | r81106 | r81107 >
Date:21:15, 27 January 2011
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
(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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -564,6 +564,24 @@
565565 $this->mFinalExtension = trim( $ext[count( $ext ) - 1] );
566566 } else {
567567 $this->mFinalExtension = '';
 568+
 569+ # No extension, try guessing one
 570+ $magic = MimeMagic::singleton();
 571+ $mime = $magic->guessMimeType( $this->mTempPath );
 572+ if ( $mime !== 'unknown/unknown' ) {
 573+ # Get a space separated list of extensions
 574+ $extList = $magic->getExtensionsForType( $mime );
 575+ if ( $extList ) {
 576+ # Set the extension to the canonical extension
 577+ $this->mFinalExtension = strtok( $extList, ' ' );
 578+
 579+ # Fix up the other variables
 580+ $this->mFilteredName .= ".{$this->mFinalExtension}";
 581+ $nt = Title::makeTitleSafe( NS_FILE, $this->mFilteredName );
 582+ $ext = array( $this->mFinalExtension );
 583+ }
 584+ }
 585+
568586 }
569587
570588 /* Don't allow users to override the blacklist (check file extension) */
Index: trunk/phase3/RELEASE-NOTES
@@ -55,6 +55,8 @@
5656 * Upload warnings now show a thumbnail of the uploaded file
5757 * Introduced the edittools-upload message, which will be inserted under the
5858 upload form instead of edittools if available
 59+* (bug 26285) Extensions will be automatically generated on upload if the user
 60+ specified a filename without extension.
5961
6062 === Bug fixes in 1.18 ===
6163 * (bug 23119) WikiError class and subclasses are now marked as deprecated

Comments

#Comment by Platonides (talk | contribs)   16:57, 28 January 2011

I'm not convinced this is a good idea.

About bug 26285, if mDesiredDestName comes from wpDestFile, I don't see how his host could be providing something different than written.

#Comment by Bryan (talk | contribs)   17:59, 28 January 2011

The point is that users can specify a custom filename in the inputbox, and then forget to add an extension. That is the case this commits tries to solve.

Status & tagging log