Expand all

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.SelectFileInputWidget(),
  button = new OO.ui.ButtonWidget( { label: 'Save' } ),
  upload = new mw.Upload;

button.on( 'click', () => {
  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( () => {
  stashPromise.resolve();
} );

stashPromise.then( () => {
  upload.setFilename( 'foo' );
  upload.setText( 'bar' );
  upload.finishStashUpload().then( () => {
    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.

Returns:

Type
jQuery.Promise
Source:
Finish a stash upload.

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

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

Returns:

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

getAutoText() → {boolean} #

Get whether the file page wikitext should be generated server-side.

Returns:

Type
boolean
Source:
Get whether the file page wikitext should be generated server-side.

getBasename(path) → {string} #

Gets the base filename from a path name.

Parameters:

Name Type Description
path string

Returns:

Type
string
Source:
Gets the base filename from a path name.

getChunkSize() → {number} #

Get the chunk size used for chunked uploads, in bytes.

Returns:

Type
number
Source:
Get the chunk size used for chunked uploads, in bytes.

getComment() → {string} #

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

Returns:

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

getCopyStatus() → {string} #

Get the copyright status for the upload.

Returns:

Type
string
Source:
Get the copyright status for the upload.

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

Get the file being uploaded.

Returns:

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

getFilename() → {string} #

Get the filename, to be finalized on upload.

Returns:

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

getIgnoreWarnings() → {boolean} #

Check if upload warnings will be ignored when publishing.

Returns:

Type
boolean
Source:
Check if upload warnings will be ignored when publishing.

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.

Returns:

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

getLicense() → {string} #

Get the license for the upload.

Returns:

Type
string
Source:
Get the license for the upload.

getSource() → {string} #

Get the source for the upload.

Returns:

Type
string
Source:
Get the source for the upload.

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

Gets the state of the upload.

Returns:

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

getStateDetails() → {string} #

Gets details of the current state.

Returns:

Type
string
Source:
Gets details of the current state.

getText() → {string} #

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

Returns:

Type
string
Source:
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.

Returns:

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

setAutoText(autotext) #

Set whether the file page wikitext should be generated server-side from the comment, license, copyright status and source, overriding the text.

Parameters:

Name Type Description
autotext boolean
Source:

Set whether the file page wikitext should be generated server-side from the comment, license, copyright status and source, overriding the text.

setChunkSize(chunkSize) #

Set the chunk size used for chunked uploads, in bytes.

Parameters:

Name Type Description
chunkSize number
Source:
Set the chunk size used for chunked uploads, in bytes.

setComment(comment) #

Set the edit comment for the upload.

Parameters:

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

setCopyStatus(copyStatus) #

Set the copyright status for the upload.

Parameters:

Name Type Description
copyStatus string
Source:
Set the copyright status 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.

setIgnoreWarnings(ignoreWarnings) #

Set whether to ignore upload warnings when publishing.

Parameters:

Name Type Description
ignoreWarnings boolean
Source:
Set whether to ignore upload warnings when publishing.

setLicense(license) #

Set the license template for the upload.

Parameters:

Name Type Description
license string
Source:
Set the license template for the upload.

setSource(source) #

Set the source for the upload.

Parameters:

Name Type Description
source string
Source:
Set the source for 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.

Returns:

Type
jQuery.Promise
Source:
Upload the file directly.

uploadToStash() → {jQuery.Promise} #

Upload the file to the stash to be completed later.

Returns:

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