From 7523ffbb6d2c4ca6dae83b313dc26dbffeb62d1b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 8 Jun 2016 17:26:40 +0200 Subject: [PATCH] mw.Upload.BookletLayout: Fail when unable to load config from foreign wiki Previously we just ignored the problem and used the config from the local wiki. This could result in incorrectly formatted uploads (if the error was transient and the upload succeeded), or more confusing error messages appearing later (if the error wasn't transient). Change-Id: Ica6e65abbb678a9942c2bba6370e3ba156085bb8 --- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + resources/Resources.php | 3 +++ .../src/mediawiki/mediawiki.ForeignStructuredUpload.js | 6 +++++- resources/src/mediawiki/mediawiki.Upload.BookletLayout.js | 8 +++++++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/languages/i18n/en.json b/languages/i18n/en.json index a028283e51..f808093b00 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1513,6 +1513,7 @@ "upload-http-error": "An HTTP error occurred: $1", "upload-copy-upload-invalid-domain": "Copy uploads are not available from this domain.", "upload-foreign-cant-upload": "This wiki is not configured to upload files to the requested foreign file repository.", + "upload-foreign-cant-load-config": "Loading file upload configuration for the foreign file repository failed.", "upload-dialog-title": "Upload file", "upload-dialog-button-cancel": "Cancel", "upload-dialog-button-done": "Done", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index ad9a372e3d..8c11752f9b 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1694,6 +1694,7 @@ "upload-http-error": "Parameters:\n* $1 - error message", "upload-copy-upload-invalid-domain": "Error message shown if a user is trying to upload (i.e. copy) a file from a website that is not in $wgCopyUploadsDomains (if set).\n\nSee also:\n* {{msg-mw|http-invalid-url}}\n* {{msg-mw|tmp-create-error}}\n* {{msg-mw|tmp-write-error}}", "upload-foreign-cant-upload": "Error message shown when a user is trying to upload a file to foreign repository that is not configured to receive file uploads from current wiki.", + "upload-foreign-cant-load-config": "Error message shown when a user is trying to upload a file to foreign repository and the foreign wiki is down or otherwise unable to respond to API requests.", "upload-dialog-title": "Title of the upload dialog box\n{{Identical|Upload file}}", "upload-dialog-button-cancel": "Button to cancel the dialog\n{{Identical|Cancel}}", "upload-dialog-button-done": "Button to close the dialog once upload is complete\n{{Identical|Done}}", diff --git a/resources/Resources.php b/resources/Resources.php index b591b289f7..106a83b101 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1195,6 +1195,9 @@ return [ 'mediawiki.ForeignUpload', 'mediawiki.ForeignStructuredUpload.config', ], + 'messages' => [ + 'upload-foreign-cant-load-config', + ], ], 'mediawiki.Upload.Dialog' => [ 'scripts' => [ diff --git a/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.js b/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.js index 4a0366a0ae..c955729cde 100644 --- a/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.js +++ b/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.js @@ -65,8 +65,12 @@ // Foreign wiki might be running a pre-1.27 MediaWiki, without support for this if ( resp.query && resp.query.uploaddialog ) { upload.config = resp.query.uploaddialog; + return upload.config; + } else { + return $.Deferred().reject( 'upload-foreign-cant-load-config' ); } - return upload.config; + }, function () { + return $.Deferred().reject( 'upload-foreign-cant-load-config' ); } ); } ); } diff --git a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js index 7a7469a267..bbd0f1b74e 100644 --- a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js +++ b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js @@ -177,7 +177,13 @@ return this.upload.getApi().then( function ( api ) { return $.when( - booklet.upload.loadConfig(), + booklet.upload.loadConfig().then( + null, + function ( errorMsg ) { + booklet.getPage( 'upload' ).$element.msg( errorMsg ); + return $.Deferred().resolve(); + } + ), // If the user can't upload anything, don't give them the option to. api.getUserInfo().then( function ( userInfo ) { if ( userInfo.rights.indexOf( 'upload' ) === -1 ) { -- 2.20.1