summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/UploadWizard/resources/handlers/mw.ApiUploadPostHandler.js
blob: 8efd129d14625aaeed1987851a475f51614c094c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
( function ( mw, OO ) {
	/**
	 * Represents an object which send a direct request to the MediaWiki API.
	 * This is used when there is no actual file payload (eg. Flickr import)
	 *
	 * @param {mw.UploadWizardUpload} upload current upload
	 * @param {mw.Api} api
	 */
	mw.ApiUploadPostHandler = function ( upload, api ) {
		mw.ApiUploadHandler.call( this, upload, api );

		this.request = null;
	};

	OO.inheritClass( mw.ApiUploadPostHandler, mw.ApiUploadHandler );

	mw.ApiUploadPostHandler.prototype.abort = function () {
		this.request.abort();
	};

	/**
	 * @return {jQuery.Promise}
	 */
	mw.ApiUploadPostHandler.prototype.submit = function () {
		var tempname = this.upload.getFilename(),
			ext = tempname.split( '.' ).pop();

		// Limit filename length to 240 bytes (limit hardcoded in UploadBase.php).
		if ( tempname.length > 240 ) {
			tempname = tempname.substr( 0, 240 - ext.length - 1 ) + '.' + ext;
		}

		this.upload.ui.setStatus( 'mwe-upwiz-transport-started' );

		this.request = this.api.postWithToken( 'csrf', {
			action: 'upload',
			stash: 1,
			ignorewarnings: 1,
			url: this.upload.file.url,
			filename: tempname
		} );

		return this.request;
	};
}( mediaWiki, OO ) );