Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
Disable "This is my own work" checkbox in VE upload dialog (via create-page on MediaWiki MCP Server)
 
Also override clear() which resets the checkbox when the dialog opens (via update-page on MediaWiki MCP Server)
 
Line 2: Line 2:
  * Pre-select and hide the "This is my own work" checkbox
  * Pre-select and hide the "This is my own work" checkbox
  * in the VisualEditor media upload dialog.
  * in the VisualEditor media upload dialog.
*
* The dialog calls clear() each time it opens, which explicitly resets
* ownWorkCheckbox to false, so we must wrap both renderUploadForm and clear.
  */
  */
mw.loader.using( 'mediawiki.ForeignStructuredUpload.BookletLayout' ).done( function () {
mw.loader.using( 'mediawiki.ForeignStructuredUpload.BookletLayout' ).done( function () {
Line 10: Line 13:
}
}


var origRender = BookletLayout.prototype.renderUploadForm;
function enforceOwnWork( booklet ) {
BookletLayout.prototype.renderUploadForm = function () {
if ( booklet.ownWorkCheckbox ) {
var form = origRender.call( this );
booklet.ownWorkCheckbox.setSelected( true );
 
booklet.ownWorkCheckbox.$element
if ( this.ownWorkCheckbox ) {
// Pre-check "This is my own work" (also triggers the change handler
// that hides the "not own work" message label)
this.ownWorkCheckbox.setSelected( true );
// Hide the checkbox's FieldLayout so users don't see it
this.ownWorkCheckbox.$element
.closest( '.oo-ui-fieldLayout' )
.closest( '.oo-ui-fieldLayout' )
.hide();
.hide();
}
}
// Hide the "not own work" message that appears when the checkbox is unchecked
if ( booklet.messageLabel ) {
booklet.messageLabel.toggle( false );
}
}


var origRender = BookletLayout.prototype.renderUploadForm;
BookletLayout.prototype.renderUploadForm = function () {
var form = origRender.call( this );
enforceOwnWork( this );
return form;
return form;
};
// clear() is called when the dialog opens and resets ownWorkCheckbox to false.
// Re-enforce own-work state after the reset.
var origClear = BookletLayout.prototype.clear;
BookletLayout.prototype.clear = function () {
origClear.call( this );
enforceOwnWork( this );
};
};
} );
} );

Latest revision as of 10:45, 25 June 2026

/**
 * Pre-select and hide the "This is my own work" checkbox
 * in the VisualEditor media upload dialog.
 *
 * The dialog calls clear() each time it opens, which explicitly resets
 * ownWorkCheckbox to false, so we must wrap both renderUploadForm and clear.
 */
mw.loader.using( 'mediawiki.ForeignStructuredUpload.BookletLayout' ).done( function () {
	var BookletLayout = mw.ForeignStructuredUpload &&
		mw.ForeignStructuredUpload.BookletLayout;
	if ( !BookletLayout ) {
		return;
	}

	function enforceOwnWork( booklet ) {
		if ( booklet.ownWorkCheckbox ) {
			booklet.ownWorkCheckbox.setSelected( true );
			booklet.ownWorkCheckbox.$element
				.closest( '.oo-ui-fieldLayout' )
				.hide();
		}
		// Hide the "not own work" message that appears when the checkbox is unchecked
		if ( booklet.messageLabel ) {
			booklet.messageLabel.toggle( false );
		}
	}

	var origRender = BookletLayout.prototype.renderUploadForm;
	BookletLayout.prototype.renderUploadForm = function () {
		var form = origRender.call( this );
		enforceOwnWork( this );
		return form;
	};

	// clear() is called when the dialog opens and resets ownWorkCheckbox to false.
	// Re-enforce own-work state after the reset.
	var origClear = BookletLayout.prototype.clear;
	BookletLayout.prototype.clear = function () {
		origClear.call( this );
		enforceOwnWork( this );
	};
} );