MarkTraceur has submitted this change and it was merged. Change subject: Stop uploading if maxLimit reached ......................................................................
Stop uploading if maxLimit reached Bug: 40158 Change-Id: If0a0362f988d1b9a235c36120d4e07b05755ca77 --- M UploadWizard.i18n.php M resources/mw.UploadWizardUpload.js M resources/mw.UploadWizardUploadInterface.js 3 files changed, 18 insertions(+), 20 deletions(-) Approvals: MarkTraceur: Verified; Looks good to me, approved jenkins-bot: Checked diff --git a/UploadWizard.i18n.php b/UploadWizard.i18n.php index 7744a18..5ad001f 100644 --- a/UploadWizard.i18n.php +++ b/UploadWizard.i18n.php @@ -241,7 +241,7 @@ 'mwe-upwiz-error-license-wikitext-invalid' => 'This does not seem to be valid wikitext, or does not contain a license.', 'mwe-upwiz-details-error-count' => 'There {{PLURAL:$1|is one error|are $1 errors}} with the {{PLURAL:$2|form|forms}} above. Correct the {{PLURAL:$1|error|errors}}, and try submitting again.', 'mwe-upwiz-too-many-files-ok' => 'OK', - 'mwe-upwiz-too-many-files-text' => 'You can only upload $1 {{PLURAL:$1|file|files}} at once. You tried to upload $2 {{PLURAL:$2|file|files}} in total, so $3 {{PLURAL:$3|file has|files have}} been removed.', + 'mwe-upwiz-too-many-files-text' => 'You can only upload $1 {{PLURAL:$1|file|files}} at once but you tried to upload $2 {{PLURAL:$2|file|files}} in total. Please try again with fewer files!', 'mwe-upwiz-too-many-files' => 'Too many files.', 'mwe-upwiz-file-too-large-ok' => 'OK', 'mwe-upwiz-file-too-large-text' => 'You can only upload files with a size of up to $1. You tried to upload a file that is $2.', diff --git a/resources/mw.UploadWizardUpload.js b/resources/mw.UploadWizardUpload.js index b0a92d2..40fd599 100644 --- a/resources/mw.UploadWizardUpload.js +++ b/resources/mw.UploadWizardUpload.js @@ -341,9 +341,9 @@ * @param {Array} of Files. usually one, can be more for multi-file select. * @param {Function()} callback when ok, and upload object is ready * @param {Function(String, Mixed)} callback when filename or contents in error. Signature of string code, mixed info + * @param {Function()} callback when resetting FileInput */ - checkFile: function( filename, files, fileNameOk, fileNameErr ) { - + checkFile: function( filename, files, fileNameOk, fileNameErr, resetFileInput ) { var _this = this; var fileErrors = {}; @@ -358,6 +358,13 @@ // Check if filename is acceptable // TODO sanitize filename var basename = mw.UploadWizardUtil.getBasename( filename ); + + var tooManyFiles = files.length + _this.wizard.uploads.length > mw.UploadWizard.config.maxUploads; + if ( tooManyFiles ) { + _this.showTooManyFilesWarning( files.length ); + resetFileInput(); + return; + } if ( files.length > 1 ) { @@ -504,16 +511,7 @@ // Now that first file has been prepared, process remaining files // in case of a multi-file upload. - var tooManyFiles = files.length + _this.wizard.uploads.length > mw.UploadWizard.config.maxUploads; - - if ( tooManyFiles ) { - var remainingFiles = mw.UploadWizard.config.maxUploads - _this.wizard.uploads.length; - _this.showTooManyFilesWarning( files.length - remainingFiles ); - files = remainingFiles > 1 ? files.slice( 1, remainingFiles ) : []; - } else { - files = files.slice( 1 ); - } - + files = files.slice( 1 ); if ( files.length > 0 ) { $j.each( files, function( i, file ) { @@ -566,14 +564,14 @@ /** * Shows an error dialog informing the user that some uploads have been omitted * since they went over the max files limit. - * @param filesIgnored integer - the number of files that have been omitted + * @param filesUploaded integer - the number of files that have been attempted to upload */ - showTooManyFilesWarning: function( filesIgnored ) { + showTooManyFilesWarning: function( filesUploaded ) { var buttons = [ { text: mw.msg( 'mwe-upwiz-too-many-files-ok' ), click: function() { - $( this ).dialog( "close" ); + $(this).dialog('destroy').remove(); } } ]; @@ -581,8 +579,7 @@ .msg( 'mwe-upwiz-too-many-files-text', mw.UploadWizard.config.maxUploads, - mw.UploadWizard.config.maxUploads + filesIgnored, - filesIgnored + filesUploaded ) .dialog( { width: 500, diff --git a/resources/mw.UploadWizardUploadInterface.js b/resources/mw.UploadWizardUploadInterface.js index fd8f544..74b9bc6 100644 --- a/resources/mw.UploadWizardUploadInterface.js +++ b/resources/mw.UploadWizardUploadInterface.js @@ -277,7 +277,8 @@ _this.getFilename(), _this.getFiles(), function() { _this.fileChangedOk(); }, - function( code, info ) { _this.fileChangedError( code, info ); } + function( code, info ) { _this.fileChangedError( code, info ); }, + function() { _this.$fileInputCtrl.get(0).value = ''; } ); } ); }, @@ -289,7 +290,7 @@ getFiles: function() { var files = []; if ( mw.fileApi.isAvailable() ) { - if( this.providedFile && !this.$fileInputCtrl.get(0).value ) { // default to the fileinput if it's defined. + if( this.providedFile && !this.$fileInputCtrl.first().value ) { // default to the fileinput if it's defined. files[0] = this.providedFile; } else { $j.each( this.$fileInputCtrl.get(0).files, function( i, file ) { -- To view, visit https://gerrit.wikimedia.org/r/65474 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If0a0362f988d1b9a235c36120d4e07b05755ca77 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/UploadWizard Gerrit-Branch: master Gerrit-Owner: Nischayn22 <nischay...@gmail.com> Gerrit-Reviewer: MarkTraceur <mtrac...@member.fsf.org> Gerrit-Reviewer: Nischayn22 <nischay...@gmail.com> Gerrit-Reviewer: Siebrand <siebr...@wikimedia.org> Gerrit-Reviewer: TheDJ <hartman.w...@gmail.com> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits