* @return {jQuery.Promise} Promise resolved when everything is initialized
*/
mw.Upload.BookletLayout.prototype.initialize = function () {
- var
- booklet = this,
- deferred = $.Deferred();
+ var booklet = this;
this.clear();
this.upload = this.createUpload();
this.setPage( 'upload' );
- this.upload.getApi().done( function ( api ) {
- // If the user can't upload anything, don't give them the option to.
- api.getUserInfo().done( function ( userInfo ) {
- if ( userInfo.rights.indexOf( 'upload' ) === -1 ) {
- // TODO Use a better error message when not all logged-in users can upload
- booklet.getPage( 'upload' ).$element.msg( 'api-error-mustbeloggedin' );
- }
- } ).always( function () {
- deferred.resolve();
- } );
- } ).fail( function ( errorMsg ) {
- booklet.getPage( 'upload' ).$element.msg( errorMsg );
- deferred.resolve();
- } );
-
- return deferred.promise();
+ return this.upload.getApi().then(
+ function ( api ) {
+ // If the user can't upload anything, don't give them the option to.
+ return api.getUserInfo().then(
+ function ( userInfo ) {
+ if ( userInfo.rights.indexOf( 'upload' ) === -1 ) {
+ // TODO Use a better error message when not all logged-in users can upload
+ booklet.getPage( 'upload' ).$element.msg( 'api-error-mustbeloggedin' );
+ }
+ return $.Deferred().resolve();
+ },
+ function () {
+ return $.Deferred().resolve();
+ }
+ );
+ },
+ function ( errorMsg ) {
+ booklet.getPage( 'upload' ).$element.msg( errorMsg );
+ return $.Deferred().resolve();
+ }
+ );
};
/**
warnings = stateDetails.upload && stateDetails.upload.warnings;
if ( state === mw.Upload.State.ERROR ) {
+ if ( !error ) {
+ // If there's an 'exception' key, this might be a timeout, or other connection problem
+ return new OO.ui.Error(
+ $( '<p>' ).msg( 'api-error-unknownerror', JSON.stringify( stateDetails ) ),
+ { recoverable: false }
+ );
+ }
+
// HACK We should either have a hook here to allow TitleBlacklist to handle this, or just have
// TitleBlacklist produce sane error messages that can be displayed without arcane knowledge
if ( error.info === 'TitleBlacklist prevents this title from being created' ) {