mw.Upload

Upload to a wiki. Most of the functionality is implemented in mw.Api#upload and friends, but this model class will tie it together as well as let you perform actions in a logical way.

A simple example:

var file = new OO.ui.SelectFileWidget(),
  button = new OO.ui.ButtonWidget( { label: 'Save' } ),
  upload = new mw.Upload;

button.on( 'click', function () {
  upload.setFile( file.getValue() );
  upload.setFilename( file.getValue().name );
  upload.upload();
} );

$( document.body ).append( file.$element, button.$element );

You can also choose to stash the upload and finalize it later:

var file, // Some file object
  upload = new mw.Upload,
  stashPromise = $.Deferred();

upload.setFile( file );
upload.uploadToStash().then( function () {
  stashPromise.resolve();
} );

stashPromise.then( function () {
  upload.setFilename( 'foo' );
  upload.setText( 'bar' );
  upload.finishStashUpload().then( function () {
    console.log( 'Done!' );
  } );
} );

Classes

BookletLayout

Encapsulates the process of uploading a file to MediaWiki using the upload model.

Dialog
Controls a BookletLayout.

Constructor

new mw.Upload(apiconfig) #

Used to represent an upload in progress on the frontend.

Parameters:

Name Type Attributes Description
apiconfig Object | mw.Api optional

A mw.Api object (or subclass), or configuration to pass to the constructor of mw.Api.

Source:

Properties

Statestatic #

Properties:

Name Type Description
NEW

Upload not yet started

WARNING

Upload finished, but there was a warning

ERROR

Upload finished, but there was an error

UPLOADING

Upload in progress

STASHED

Upload finished, but not published, call #finishStashUpload

UPLOADED

Upload finished and published

Source:

Methods

finishStashUpload() → {jQuery.Promise} #

Finish a stash upload.

Source:

Returns:

Type
jQuery.Promise
Finish a stash upload.

getApi() → {jQuery.Promise.<mw.Api>} #

Get the mw.Api instance used by this Upload object.

Source:

Returns:

Type
jQuery.Promise.<mw.Api>
Get the mw.Api instance used by this Upload object.

getBasename(path) → {string} #

Gets the base filename from a path name.

Parameters:

Name Type Description
path string
Source:

Returns:

Type
string
Gets the base filename from a path name.

getComment() → {string} #

Get the current value of the edit comment for the upload.

Source:

Returns:

Type
string
Get the current value of the edit comment for the upload.

getFile() → {HTMLInputElement|File|Blob} #

Get the file being uploaded.

Source:

Returns:

Type
HTMLInputElement | File | Blob
Get the file being uploaded.

getFilename() → {string} #

Get the filename, to be finalized on upload.

Source:

Returns:

Type
string
Get the filename, to be finalized on upload.

getImageInfo() → {Object|undefined} #

Get the imageinfo object for the finished upload. Only available once the upload is finished! Don't try to get it beforehand.

Source:

Returns:

Type
Object | undefined
Get the imageinfo object for the finished upload.

getState() → {mw.Upload.State} #

Gets the state of the upload.

Source:

Returns:

Type
mw.Upload.State
Gets the state of the upload.

getStateDetails() → {string} #

Gets details of the current state.

Source:

Returns:

Type
string
Gets details of the current state.

getText() → {string} #

Get the text of the file page, to be created on file upload.

Source:

Returns:

Type
string
Get the text of the file page, to be created on file upload.

getWatchlist() → {boolean} #

Get the boolean for whether the file will be watchlisted after upload.

Source:

Returns:

Type
boolean
Get the boolean for whether the file will be watchlisted after upload.

setComment(comment) #

Set the edit comment for the upload.

Parameters:

Name Type Description
comment string
Source:
Set the edit comment for the upload.

setFile(file) #

Set the file to be uploaded.

Parameters:

Name Type Description
file HTMLInputElement | File | Blob
Source:
Set the file to be uploaded.

setFilekey(filekey) #

Set the stashed file to finish uploading.

Parameters:

Name Type Description
filekey string
Source:
Set the stashed file to finish uploading.

setFilename(filename) #

Set the filename, to be finalized on upload.

Parameters:

Name Type Description
filename string
Source:
Set the filename, to be finalized on upload.

setFilenameFromFile() #

Sets the filename based on the filename as it was on the upload.

Source:
Sets the filename based on the filename as it was on the upload.

setState(state, stateDetails) #

Sets the state and state details (if any) of the upload.

Parameters:

Name Type Description
state mw.Upload.State
stateDetails Object
Source:
Sets the state and state details (if any) of the upload.

setText(text) #

Set the text of the file page, to be created on file upload.

Parameters:

Name Type Description
text string
Source:
Set the text of the file page, to be created on file upload.

setWatchlist(watchlist) #

Set whether the file should be watchlisted after upload.

Parameters:

Name Type Description
watchlist boolean
Source:
Set whether the file should be watchlisted after upload.

upload() → {jQuery.Promise} #

Upload the file directly.

Source:

Returns:

Type
jQuery.Promise
Upload the file directly.

uploadToStash() → {jQuery.Promise} #

Upload the file to the stash to be completed later.

Source:

Returns:

Type
jQuery.Promise
Upload the file to the stash to be completed later.