MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
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: | ||
} | } | ||
function enforceOwnWork( booklet ) { | |||
if ( booklet.ownWorkCheckbox ) { | |||
booklet.ownWorkCheckbox.setSelected( true ); | |||
booklet.ownWorkCheckbox.$element | |||
if ( | |||
.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 );
};
} );