Index: trunk/extensions/UploadWizard/UploadWizardHooks.php |
— | — | @@ -218,6 +218,7 @@ |
219 | 219 | 'mwe-upwiz-upload-error-bad-extension-video-firefogg', |
220 | 220 | 'mwe-upwiz-upload-error-bad-filename-extension', |
221 | 221 | 'mwe-upwiz-upload-error-bad-filename-no-extension', |
| 222 | + 'mwe-upwiz-upload-error-duplicate-filename-error', |
222 | 223 | 'mwe-upwiz-allowed-filename-extensions', |
223 | 224 | 'mwe-upwiz-help-allowed-filename-extensions', |
224 | 225 | 'mwe-upwiz-upload-error-duplicate', |
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -128,6 +128,7 @@ |
129 | 129 | 'mwe-upwiz-upload-error-bad-extension-video-firefogg' => 'You have selected a video file for uploading that is not in a free format. |
130 | 130 | You can [$1 install Firefogg] to automatically convert it, or use other [$2 converting options].', |
131 | 131 | '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".', |
132 | 133 | 'mwe-upwiz-allowed-filename-extensions' => 'The allowed extensions are:', |
133 | 134 | 'mwe-upwiz-help-allowed-filename-extensions' => 'Allowed filename extensions', |
134 | 135 | '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 @@ |
224 | 224 | |
225 | 225 | initFileInputCtrl: function() { |
226 | 226 | var _this = this; |
227 | | - this.$fileInputCtrl.change( function() { |
| 227 | + _this.$fileInputCtrl.change( function() { |
228 | 228 | _this.clearErrors(); |
229 | 229 | _this.upload.checkFile( |
230 | | - this, // the file input |
| 230 | + this, // the file input, different from _this |
231 | 231 | function() { _this.fileChangedOk(); }, |
232 | 232 | function( code, info ) { _this.fileChangedError( code, info ); } |
233 | 233 | ); |
— | — | @@ -272,7 +272,7 @@ |
273 | 273 | }, |
274 | 274 | |
275 | 275 | fileChangedError: function( code, info ) { |
276 | | - var filename = this.$fileInputCtrl.value; |
| 276 | + var filename = this.$fileInputCtrl.get(0).value; |
277 | 277 | |
278 | 278 | // ok we now have a fileInputCtrl with a "bad" file in it |
279 | 279 | // you cannot blank a file input ctrl in all browsers, so we |
— | — | @@ -287,7 +287,7 @@ |
288 | 288 | } else if ( code === 'noext' ) { |
289 | 289 | this.showMissingExtensionError( filename ); |
290 | 290 | } else if ( code === 'dup' ) { |
291 | | - this.showDuplicateError( filename ); |
| 291 | + this.showDuplicateError( filename, info ); |
292 | 292 | } else if ( code === 'unparseable' ) { |
293 | 293 | this.showUnparseableFilenameError( filename ); |
294 | 294 | } else { |
— | — | @@ -336,8 +336,8 @@ |
337 | 337 | ); |
338 | 338 | }, |
339 | 339 | |
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 ) ); |
342 | 342 | }, |
343 | 343 | |
344 | 344 | showFilenameError: function( $text ) { |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js |
— | — | @@ -7,12 +7,13 @@ |
8 | 8 | */ |
9 | 9 | ( function( $j ) { |
10 | 10 | |
11 | | -mw.UploadWizardUpload = function( api, filesDiv ) { |
| 11 | +mw.UploadWizardUpload = function( wizard, filesDiv ) { |
12 | 12 | |
13 | 13 | this.index = mw.UploadWizardUpload.prototype.count; |
14 | 14 | mw.UploadWizardUpload.prototype.count++; |
15 | 15 | |
16 | | - this.api = api; |
| 16 | + this.wizard = wizard; |
| 17 | + this.api = wizard.api; |
17 | 18 | this.state = 'new'; |
18 | 19 | this.thumbnails = {}; |
19 | 20 | this.thumbnailPublishers = {}; |
— | — | @@ -20,6 +21,7 @@ |
21 | 22 | this.title = undefined; |
22 | 23 | this.mimetype = undefined; |
23 | 24 | this.extension = undefined; |
| 25 | + this.filename = undefined; |
24 | 26 | |
25 | 27 | this.sessionKey = undefined; |
26 | 28 | |
— | — | @@ -253,6 +255,7 @@ |
254 | 256 | |
255 | 257 | /** |
256 | 258 | * Called when the file is entered into the file input. |
| 259 | + * Checks for file validity, then extracts metadata. |
257 | 260 | * Error out if filename or its contents are determined to be unacceptable |
258 | 261 | * Proceed to thumbnail extraction and image info if acceptable |
259 | 262 | * @param {HTMLFileInput} file input field |
— | — | @@ -264,13 +267,28 @@ |
265 | 268 | |
266 | 269 | var _this = this; |
267 | 270 | |
268 | | - // TODO check if filename has been used already in this wizard |
269 | | - |
270 | 271 | // Check if filename is acceptable |
271 | 272 | // TODO sanitize filename |
272 | 273 | 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 | + |
273 | 291 | try { |
274 | | - this.title = new mw.Title( mw.UploadWizardUtil.getBasename( filename ).replace( /:/g, '_' ), 'file' ); |
| 292 | + this.title = new mw.Title( basename.replace( /:/g, '_' ), 'file' ); |
275 | 293 | } catch ( e ) { |
276 | 294 | fileNameErr( 'unparseable' ); |
277 | 295 | } |
— | — | @@ -306,11 +324,13 @@ |
307 | 325 | meta = null; |
308 | 326 | } |
309 | 327 | _this.extractMetadataFromJpegMeta( meta ); |
| 328 | + _this.filename = filename; |
310 | 329 | fileNameOk(); |
311 | 330 | }; |
312 | 331 | binReader.readAsBinaryString( _this.file ); |
313 | 332 | } else { |
314 | | - fileChangedOk(); |
| 333 | + this.filename = filename; |
| 334 | + fileNameOk(); |
315 | 335 | } |
316 | 336 | |
317 | 337 | } |
— | — | @@ -1262,7 +1282,7 @@ |
1263 | 1283 | return false; |
1264 | 1284 | } |
1265 | 1285 | |
1266 | | - var upload = new mw.UploadWizardUpload( _this.api, '#mwe-upwiz-filelist' ); |
| 1286 | + var upload = new mw.UploadWizardUpload( _this, '#mwe-upwiz-filelist' ); |
1267 | 1287 | _this.uploadToAdd = upload; |
1268 | 1288 | |
1269 | 1289 | // we explicitly move the file input to cover the upload button |