* {@link #createUpload createUpload} method to
* return the new model. The {@link #saveFile saveFile}, and
* the {@link #uploadFile uploadFile} methods need to be
- * overriden to use the new model and data returned from the forms.
+ * overridden to use the new model and data returned from the forms.
*
* @class
* @extends OO.ui.BookletLayout
* @return {jQuery.Promise} Promise resolved when everything is initialized
*/
mw.Upload.BookletLayout.prototype.initialize = function () {
+ var
+ apiPromise,
+ booklet = this,
+ deferred = $.Deferred();
+
this.clear();
this.upload = this.createUpload();
this.setPage( 'upload' );
- return $.Deferred().resolve().promise();
+
+ apiPromise = this.upload.apiPromise || $.Deferred().resolve( this.upload.api );
+ apiPromise.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();
+ } );
+ } );
+
+ return deferred.promise();
};
/**
this.filenameWidget.setValue( file.name );
this.setPage( 'info' );
+ if ( this.shouldRecordBucket ) {
+ this.upload.bucket = this.bucket;
+ }
+
this.upload.setFile( file );
// Explicitly set the filename so that the old filename isn't used in case of retry
this.upload.setFilenameFromFile();
// won't help the fact that the file already exists.
if ( warnings.stashfailed !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'api-error-stashfailed' ).parse()
- ),
+ $( '<p>' ).msg( 'api-error-stashfailed' ),
{ recoverable: false }
);
} else if ( warnings.exists !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'fileexists', 'File:' + warnings.exists ).parse()
- ),
+ $( '<p>' ).msg( 'fileexists', 'File:' + warnings.exists ),
{ recoverable: false }
);
} else if ( warnings[ 'page-exists' ] !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'filepageexists', 'File:' + warnings[ 'page-exists' ] ).parse()
- ),
+ $( '<p>' ).msg( 'filepageexists', 'File:' + warnings[ 'page-exists' ] ),
{ recoverable: false }
);
} else if ( warnings.duplicate !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'api-error-duplicate', warnings.duplicate.length ).parse()
- ),
+ $( '<p>' ).msg( 'api-error-duplicate', warnings.duplicate.length ),
{ recoverable: false }
);
} else if ( warnings[ 'thumb-name' ] !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'filename-thumb-name' ).parse()
- ),
+ $( '<p>' ).msg( 'filename-thumb-name' ),
{ recoverable: false }
);
} else if ( warnings[ 'bad-prefix' ] !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'filename-bad-prefix', warnings[ 'bad-prefix' ] ).parse()
- ),
+ $( '<p>' ).msg( 'filename-bad-prefix', warnings[ 'bad-prefix' ] ),
{ recoverable: false }
);
} else if ( warnings[ 'duplicate-archive' ] !== undefined ) {
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'api-error-duplicate-archive', 1 ).parse()
- ),
+ $( '<p>' ).msg( 'api-error-duplicate-archive', 1 ),
{ recoverable: false }
);
} else if ( warnings.badfilename !== undefined ) {
// TODO This might not really be the best place to do this
this.filenameWidget.setValue( warnings.badfilename );
return new OO.ui.Error(
- $( '<p>' ).html(
- mw.message( 'badfilename', warnings.badfilename ).parse()
- )
+ $( '<p>' ).msg( 'badfilename', warnings.badfilename )
);
} else {
return new OO.ui.Error(