Jump to content

User:MarkTraceur/commonsUploadForEditDialog.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
( function ( mw, $ ) {
	var udscript = importScript( 'User:MarkTraceur/commonsUploadDialog.js' ),
		ready = $.Deferred();

	udscript.addEventListener( 'load', function () {
		mw.commonsUploadDialogPromise.then( ready.resolve, ready.reject );
	} );

	mw.uploadEditToolPromise = ready.then( function () {
		mw.CommonsUploadForEdit = function ( apiconfig ) {
			mw.CommonsUploadForEdit.parent.call( this, apiconfig );
			this.caption = '';
		};

		OO.inheritClass( mw.CommonsUploadForEdit, mw.CommonsUpload );
		
		mw.CommonsUploadForEdit.prototype.getLicense = function () {
			return '{{self|cc-by-sa-4.0}}';
		};

		mw.CommonsUploadForEdit.prototype.getCaption = function () {
			return this.caption;
		};

		mw.CommonsUploadForEdit.prototype.setCaption = function ( caption ) {
			this.caption = caption;
		};

		mw.CommonsUploadForEditDialog = function ( config ) {
			mw.CommonsUploadForEditDialog.parent.call( this, config );
		};

		OO.inheritClass( mw.CommonsUploadForEditDialog, mw.CommonsUploadDialog );

		mw.CommonsUploadForEditDialog.prototype.getFields = function () {
			var fields = mw.CommonsUploadForEditDialog.parent.prototype.getFields.call( this );

			this.captionWidget = new OO.ui.TextInputWidget( {} );
			this.captionField = new OO.ui.FieldLayout( this.captionWidget, {
				label: 'Caption'
			} );

			fields.push( this.captionField );

			return fields;
		};

		mw.CommonsUploadForEditDialog.prototype.setCaption = function ( caption ) {
			this.captionWidget.setValue( caption );
		};

		mw.CommonsUploadForEditDialog.prototype.getCaption = function () {
			return this.captionWidget.getValue();
		};

		mw.CommonsUploadForEditDialog.prototype.finalizeUpload = function () {
			mw.CommonsUploadForEditDialog.parent.prototype.finalizeUpload.call( this );
			this.upload.setCaption( this.getCaption() );
		};

		mw.CommonsUploadForEditDialog.prototype.getUploadObject = function () {
			return new mw.CommonsUploadForEdit( {} );
		};
	} );
}( mediaWiki, jQuery ) );