r91694 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91693‎ | r91694 | r91695 >
Date:22:09, 7 July 2011
Author:raindrift
Status:ok (Comments)
Tags:
Comment:
added early check for attempts to upload duplicate files.
tested in chrome/ie6-xp/ie8-vista
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizard.i18n.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizardHooks.php (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizard.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardUploadInterface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/UploadWizardHooks.php
@@ -218,6 +218,7 @@
219219 'mwe-upwiz-upload-error-bad-extension-video-firefogg',
220220 'mwe-upwiz-upload-error-bad-filename-extension',
221221 'mwe-upwiz-upload-error-bad-filename-no-extension',
 222+ 'mwe-upwiz-upload-error-duplicate-filename-error',
222223 'mwe-upwiz-allowed-filename-extensions',
223224 'mwe-upwiz-help-allowed-filename-extensions',
224225 'mwe-upwiz-upload-error-duplicate',
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php
@@ -128,6 +128,7 @@
129129 'mwe-upwiz-upload-error-bad-extension-video-firefogg' => 'You have selected a video file for uploading that is not in a free format.
130130 You can [$1 install Firefogg] to automatically convert it, or use other [$2 converting options].',
131131 'mwe-upwiz-upload-error-bad-filename-no-extension' => 'This wiki requires that files have an extension — like ".JPG" at the end of the filename.',
 132+ 'mwe-upwiz-upload-error-duplicate-filename-error' => 'You are already uploading the file "$1".',
132133 'mwe-upwiz-allowed-filename-extensions' => 'The allowed extensions are:',
133134 'mwe-upwiz-help-allowed-filename-extensions' => 'Allowed filename extensions',
134135 'mwe-upwiz-upload-error-duplicate' => 'This file was previously uploaded to this wiki.',
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardUploadInterface.js
@@ -223,10 +223,10 @@
224224
225225 initFileInputCtrl: function() {
226226 var _this = this;
227 - this.$fileInputCtrl.change( function() {
 227+ _this.$fileInputCtrl.change( function() {
228228 _this.clearErrors();
229229 _this.upload.checkFile(
230 - this, // the file input
 230+ this, // the file input, different from _this
231231 function() { _this.fileChangedOk(); },
232232 function( code, info ) { _this.fileChangedError( code, info ); }
233233 );
@@ -272,7 +272,7 @@
273273 },
274274
275275 fileChangedError: function( code, info ) {
276 - var filename = this.$fileInputCtrl.value;
 276+ var filename = this.$fileInputCtrl.get(0).value;
277277
278278 // ok we now have a fileInputCtrl with a "bad" file in it
279279 // you cannot blank a file input ctrl in all browsers, so we
@@ -287,7 +287,7 @@
288288 } else if ( code === 'noext' ) {
289289 this.showMissingExtensionError( filename );
290290 } else if ( code === 'dup' ) {
291 - this.showDuplicateError( filename );
 291+ this.showDuplicateError( filename, info );
292292 } else if ( code === 'unparseable' ) {
293293 this.showUnparseableFilenameError( filename );
294294 } else {
@@ -336,8 +336,8 @@
337337 );
338338 },
339339
340 - showDuplicateError: function() {
341 - // to be implemented
 340+ showDuplicateError: function( filename, basename ) {
 341+ this.showFilenameError( $j( '<p>' ).msg( 'mwe-upwiz-upload-error-duplicate-filename-error', basename ) );
342342 },
343343
344344 showFilenameError: function( $text ) {
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js
@@ -7,12 +7,13 @@
88 */
99 ( function( $j ) {
1010
11 -mw.UploadWizardUpload = function( api, filesDiv ) {
 11+mw.UploadWizardUpload = function( wizard, filesDiv ) {
1212
1313 this.index = mw.UploadWizardUpload.prototype.count;
1414 mw.UploadWizardUpload.prototype.count++;
1515
16 - this.api = api;
 16+ this.wizard = wizard;
 17+ this.api = wizard.api;
1718 this.state = 'new';
1819 this.thumbnails = {};
1920 this.thumbnailPublishers = {};
@@ -20,6 +21,7 @@
2122 this.title = undefined;
2223 this.mimetype = undefined;
2324 this.extension = undefined;
 25+ this.filename = undefined;
2426
2527 this.sessionKey = undefined;
2628
@@ -253,6 +255,7 @@
254256
255257 /**
256258 * Called when the file is entered into the file input.
 259+ * Checks for file validity, then extracts metadata.
257260 * Error out if filename or its contents are determined to be unacceptable
258261 * Proceed to thumbnail extraction and image info if acceptable
259262 * @param {HTMLFileInput} file input field
@@ -264,13 +267,28 @@
265268
266269 var _this = this;
267270
268 - // TODO check if filename has been used already in this wizard
269 -
270271 // Check if filename is acceptable
271272 // TODO sanitize filename
272273 var filename = fileInput.value;
 274+ var basename = mw.UploadWizardUtil.getBasename( filename );
 275+
 276+
 277+ // check to see if the file has already been selected for upload.
 278+ var duplicate = false;
 279+ $j.each( this.wizard.uploads, function ( i, upload ) {
 280+ if ( _this !== upload && filename === upload.filename ) {
 281+ duplicate = true;
 282+ return false;
 283+ }
 284+ } );
 285+
 286+ if( duplicate ) {
 287+ fileNameErr( 'dup', basename );
 288+ return false;
 289+ }
 290+
273291 try {
274 - this.title = new mw.Title( mw.UploadWizardUtil.getBasename( filename ).replace( /:/g, '_' ), 'file' );
 292+ this.title = new mw.Title( basename.replace( /:/g, '_' ), 'file' );
275293 } catch ( e ) {
276294 fileNameErr( 'unparseable' );
277295 }
@@ -306,11 +324,13 @@
307325 meta = null;
308326 }
309327 _this.extractMetadataFromJpegMeta( meta );
 328+ _this.filename = filename;
310329 fileNameOk();
311330 };
312331 binReader.readAsBinaryString( _this.file );
313332 } else {
314 - fileChangedOk();
 333+ this.filename = filename;
 334+ fileNameOk();
315335 }
316336
317337 }
@@ -1262,7 +1282,7 @@
12631283 return false;
12641284 }
12651285
1266 - var upload = new mw.UploadWizardUpload( _this.api, '#mwe-upwiz-filelist' );
 1286+ var upload = new mw.UploadWizardUpload( _this, '#mwe-upwiz-filelist' );
12671287 _this.uploadToAdd = upload;
12681288
12691289 // we explicitly move the file input to cover the upload button

Comments

#Comment by NeilK (talk | contribs)   00:21, 8 July 2011

paired for these changes

Status & tagging log