mw.Upload.BookletLayout: Show an error rather than explode when uploads are disabled
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 8 Dec 2015 18:15:50 +0000 (19:15 +0100)
committerJforrester <jforrester@wikimedia.org>
Fri, 22 Jan 2016 19:30:40 +0000 (19:30 +0000)
Also, localise the error messages.

Bug: T119314
Change-Id: I0b2f53b91454f22e2001462397087da9e055b701

languages/i18n/en.json
languages/i18n/qqq.json
resources/Resources.php
resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js
resources/src/mediawiki/mediawiki.ForeignUpload.js
resources/src/mediawiki/mediawiki.Upload.BookletLayout.js

index 43fdbd9..2849963 100644 (file)
        "upload-too-many-redirects": "The URL contained too many redirects",
        "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-dialog-title": "Upload file",
        "upload-dialog-button-cancel": "Cancel",
        "upload-dialog-button-done": "Done",
index 37e1a5a..128e243 100644 (file)
        "upload-too-many-redirects": "Error message shown when uploading a file via URL, if the upload failed because the URL returned too many redirects.",
        "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-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}}",
index 60c3175..18bff51 100644 (file)
@@ -1152,6 +1152,10 @@ return array(
                        'mediawiki.Upload',
                        'oojs',
                ),
+               'messages' => array(
+                       'uploaddisabledtext',
+                       'upload-foreign-cant-upload',
+               )
        ),
        'mediawiki.ForeignStructuredUpload' => array(
                'scripts' => 'resources/src/mediawiki/mediawiki.ForeignStructuredUpload.js',
index 6813ea6..7331df9 100644 (file)
@@ -49,8 +49,9 @@
                                                // Can't reuse the same object, CategorySelector calls #abort on its mw.Api instance
                                                this.categoriesWidget.api = new mw.ForeignApi( api.apiUrl );
                                        }
+                               }.bind( this ) ).always( function () {
                                        deferred.resolve();
-                               }.bind( this ) );
+                               } );
                        }.bind( this ) );
                return deferred.promise();
        };
index aa08b6c..1a0b59a 100644 (file)
                if ( this.target === 'local' ) {
                        // If local uploads were requested, but they are disabled, fail.
                        if ( !mw.config.get( 'wgEnableUploads' ) ) {
-                               throw new Error( 'Local uploads are disabled' );
+                               this.apiPromise = $.Deferred().reject( 'uploaddisabledtext' );
+                       } else {
+                               // We'll ignore the CORS and centralauth stuff if the target is
+                               // the local wiki.
+                               this.apiPromise = $.Deferred().resolve( new mw.Api( apiconfig ) );
                        }
-                       // We'll ignore the CORS and centralauth stuff if the target is
-                       // the local wiki.
-                       this.apiPromise = $.Deferred().resolve( new mw.Api( apiconfig ) );
                } else {
                        api = new mw.Api();
                        this.apiPromise = api.get( {
@@ -76,7 +77,7 @@
                                        }
                                }
 
-                               throw new Error( 'Can not upload to requested foreign repo' );
+                               return $.Deferred().reject( 'upload-foreign-cant-upload' );
                        } );
                }
 
index 84b33fd..7971069 100644 (file)
                        } ).always( function () {
                                deferred.resolve();
                        } );
+               } ).fail( function ( errorMsg ) {
+                       booklet.getPage( 'upload' ).$element.msg( errorMsg );
+                       deferred.resolve();
                } );
 
                return deferred.promise();