jenkins-bot has submitted this change and it was merged.

Change subject: mw.Upload.BookletLayout: Show errors and try to recover from 
warnings
......................................................................


mw.Upload.BookletLayout: Show errors and try to recover from warnings

Show useful errors and try and recover from warning by changing the
state of the upload.

Bug: T114130
Change-Id: I08704108704ffaa70245c5facfca4b063a61f01b
---
M languages/i18n/en.json
M languages/i18n/qqq.json
M resources/Resources.php
M resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
M resources/src/mediawiki/mediawiki.Upload.js
5 files changed, 86 insertions(+), 17 deletions(-)

Approvals:
  MarkTraceur: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index f73315d..818edff 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -1391,6 +1391,7 @@
        "upload-options": "Upload options",
        "watchthisupload": "Watch this file",
        "filewasdeleted": "A file of this name has been previously uploaded and 
subsequently deleted.\nYou should check the $1 before proceeding to upload it 
again.",
+       "filename-thumb-name": "This looks like a thumbnail title. Please do 
not upload thumbnails back to the same wiki. Otherwise, please fix the filename 
so it is more meaningful, and does not have the thumbnail prefix.",
        "filename-bad-prefix": "The name of the file you are uploading begins 
with <strong>\"$1\"</strong>, which is a non-descriptive name typically 
assigned automatically by digital cameras.\nPlease choose a more descriptive 
name for your file.",
        "filename-prefix-blacklist": " #<!-- leave this line exactly as it is 
--> <pre>\n# Syntax is as follows:\n#   * Everything from a \"#\" character to 
the end of the line is a comment\n#   * Every non-blank line is a prefix for 
typical filenames assigned automatically by digital cameras\nCIMG # Casio\nDSC_ 
# Nikon\nDSCF # Fuji\nDSCN # Nikon\nDUW # some mobile phones\nIMG # generic\nJD 
# Jenoptik\nMGP # Pentax\nPICT # misc.\n #</pre> <!-- leave this line exactly 
as it is -->",
        "upload-success-subj": "Successful upload",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index c03578d..3893577 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -1564,6 +1564,7 @@
        "upload-options": "Caption above a section of the [[Special:Upload]] 
page",
        "watchthisupload": "In [[Special:Upload]]",
        "filewasdeleted": "This warning is shown when trying to upload a file 
that does not exist, but has previously been deleted.\n\nParameters:\n* $1 - a 
link to the deletion log, with the text from {{msg-mw|deletionlog}}",
+       "filename-thumb-name": "Appears when thumbnail title is similar to 
\"22px-Example.jpg\" - the prefix is what MW adds when downloading pictures as 
thumbnails.",
        "filename-bad-prefix": "Used as warning in [[Special:Upload]]. 
Parameters:\n* $1 - prefix\nSee also:\n* {{msg-mw|fileexists}}\n* 
{{msg-mw|filepageexists}}\n* {{msg-mw|fileexists-extension}}\n* 
{{msg-mw|fileexists-thumbnail-yes}}\n* {{msg-mw|file-thumbnail-no}}\n* 
{{msg-mw|filewasdeleted}}",
        "filename-prefix-blacklist": "{{optional}}\nDo not translate the file 
name prefixes before the hash mark (#). Leave all the wiki markup, including 
the spaces, as is. You can translate the text, including 'Leave this line 
exactly as it is'. The first line of this messages has one (1) leading space.",
        "upload-success-subj": "Used as message subject which is posted on the 
user talk page.\n\nSee also:\n* {{msg-mw|upload-success-subj|subject}}\n* 
{{msg-mw|upload-success-msg|message}}\n* 
{{msg-mw|upload-failure-subj|subject}}\n* 
{{msg-mw|upload-failure-msg|message}}",
diff --git a/resources/Resources.php b/resources/Resources.php
index ccc3cd5..9affe26 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1220,6 +1220,7 @@
                'dependencies' => array(
                        'oojs-ui',
                        'mediawiki.Upload',
+                       'mediawiki.jqueryMsg',
                ),
                'messages' => array(
                        'upload-process-error',
@@ -1230,6 +1231,12 @@
                        'upload-form-label-infoform-description',
                        'upload-form-label-usage-title',
                        'upload-form-label-usage-filename',
+                       'fileexists',
+                       'filepageexists',
+                       'filename-bad-prefix',
+                       'filename-thumb-name',
+                       'badfilename',
+                       'api-error-duplicate-archive',
                ),
        ),
        'mediawiki.ForeignStructuredUpload.BookletLayout' => array(
diff --git a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js 
b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
index d1e01b1..b574a5d 100644
--- a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
+++ b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
@@ -232,23 +232,9 @@
                this.upload.setFilename( this.getFilename() );
                this.upload.setText( this.getText() );
 
-               this.uploadPromise.always( function () {
-                       layout.upload.finishStashUpload().always( function () {
+               this.uploadPromise.then( function () {
+                       layout.upload.finishStashUpload().then( function () {
                                var name;
-
-                               if ( layout.upload.getState() === 
mw.Upload.State.ERROR ) {
-                                       deferred.reject( new OO.ui.Error( 
mw.msg( 'upload-process-error' ), {
-                                               recoverable: false
-                                       } ) );
-                                       return false;
-                               }
-
-                               if ( layout.upload.getState() === 
mw.Upload.State.WARNING ) {
-                                       deferred.reject( new OO.ui.Error( 
mw.msg( 'upload-process-warning' ), {
-                                               recoverable: false
-                                       } ) );
-                                       return false;
-                               }
 
                                // Normalize page name and localise the 'File:' 
prefix
                                name = new mw.Title( 'File:' + 
layout.upload.getFilename() ).toString();
@@ -257,6 +243,64 @@
 
                                deferred.resolve();
                                layout.emit( 'fileSaved' );
+                       }, function () {
+                               var stateDetails = 
layout.upload.getStateDetails();
+
+                               if ( layout.upload.getState() === 
mw.Upload.State.ERROR ) {
+                                       deferred.reject( new OO.ui.Error( 
stateDetails, {
+                                               recoverable: false
+                                       } ) );
+                                       return false;
+                               }
+
+                               if ( layout.upload.getState() === 
mw.Upload.State.WARNING ) {
+                                       if ( stateDetails.exists !== undefined 
) {
+                                               deferred.reject( new 
OO.ui.Error(
+                                                       $( '<p>' ).html(
+                                                               mw.message( 
'filepageexists', stateDetails.exists ).parse()
+                                                       ),
+                                                       { recoverable: false }
+                                               ) );
+                                       } else if ( stateDetails.duplicate !== 
undefined ) {
+                                               deferred.reject( new 
OO.ui.Error(
+                                                       $( '<p>' ).html(
+                                                               mw.message( 
'fileexists', stateDetails.duplicate[ 0 ] ).parse()
+                                                       ),
+                                                       { recoverable: false }
+                                               ) );
+                                       } else if ( stateDetails[ 'thumb-name' 
] !== undefined ) {
+                                               deferred.reject( new 
OO.ui.Error(
+                                                       $( '<p>' ).html(
+                                                               mw.message( 
'filename-thumb-name' ).parse()
+                                                       ),
+                                                       { recoverable: false }
+                                               ) );
+                                       } else if ( stateDetails[ 'bad-prefix' 
] !== undefined ) {
+                                               deferred.reject( new 
OO.ui.Error(
+                                                       $( '<p>' ).html(
+                                                               mw.message( 
'filename-bad-prefix', stateDetails[ 'bad-prefix' ] ).parse()
+                                                       ),
+                                                       { recoverable: false }
+                                               ) );
+                                       } else if ( stateDetails[ 
'duplicate-archive' ] !== undefined ) {
+                                               deferred.reject( new 
OO.ui.Error(
+                                                       $( '<p>' ).html(
+                                                               mw.message( 
'api-error-duplicate-archive', stateDetails[ 'duplicate-archive' ] ).parse()
+                                                       ),
+                                                       { recoverable: false }
+                                               ) );
+                                       } else if ( stateDetails.badfilename 
!== undefined ) {
+                                               // Change the name if the 
current name isn't acceptable
+                                               layout.filenameWidget.setValue( 
stateDetails.badfilename );
+                                               deferred.reject( new 
OO.ui.Error(
+                                                       $( '<p>' ).html(
+                                                               mw.message( 
'badfilename', stateDetails.badfilename ).parse()
+                                                       )
+                                               ) );
+                                       }
+
+                                       return false;
+                               }
                        } );
                } );
 
diff --git a/resources/src/mediawiki/mediawiki.Upload.js 
b/resources/src/mediawiki/mediawiki.Upload.js
index 56f4f83..007c855 100644
--- a/resources/src/mediawiki/mediawiki.Upload.js
+++ b/resources/src/mediawiki/mediawiki.Upload.js
@@ -189,6 +189,9 @@
 
        /**
         * Sets the state and state details (if any) of the upload.
+        *
+        * @param {mw.Upload.State} state
+        * @param {string|Object} stateDetails
         */
        UP.setState = function ( state, stateDetails ) {
                this.state = state;
@@ -310,7 +313,20 @@
                                upload.setState( Upload.State.UPLOADED );
                                upload.imageinfo = result.upload.imageinfo;
                                return result;
-                       }, function () {
+                       }, function ( result ) {
+                               // Errors are strings that can be used to get 
error message
+                               if ( typeof result === 'string' ) {
+                                       upload.setState( Upload.State.ERROR, 
mw.message( 'api-error-' + result ) );
+                                       return;
+                               }
+
+                               // Warnings come in the form of objects
+                               if ( $.isPlainObject( result ) ) {
+                                       upload.setState( Upload.State.WARNING, 
result );
+                                       return;
+                               }
+
+                               // Throw an empty error if we can't figure it 
out
                                upload.setState( Upload.State.ERROR );
                        } );
                } );

-- 
To view, visit https://gerrit.wikimedia.org/r/243144
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I08704108704ffaa70245c5facfca4b063a61f01b
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Prtksxna <[email protected]>
Gerrit-Reviewer: Bartosz DziewoƄski <[email protected]>
Gerrit-Reviewer: Edokter <[email protected]>
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: Prtksxna <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to