// <nowiki>
// Quick script to add links to the "warn" and "disallow" messages used in
// edit filters
// @author DannyS712
$(() => {
const AbuseFilterMessageLinks = {};
window.AbuseFilterMessageLinks = AbuseFilterMessageLinks;

AbuseFilterMessageLinks.init = function () {
	mw.loader.using(
		,
		AbuseFilterMessageLinks.run
	);
};

AbuseFilterMessageLinks.addHandler = function ( selectId, inputId, toggleId ) {
	const selectWidget = OO.ui.infuse( $( '#' + selectId ) );
	const inputWidget = OO.ui.infuse( $( '#' + inputId ) );

	const $link = $( '<a>' ).attr( 'target', '_blank' );
	const updateLink = ( messageName ) => {
		$link.text( 'MediaWiki:' + messageName );
		$link.attr( 'href', 'https://wiki95.com/en/MediaWiki:' + messageName );
	};
	updateLink( inputWidget.getValue() );
	$( '#' + toggleId ).after( ' ', $link );
	
	selectWidget.on( 'change', updateLink );
	inputWidget.on( 'change', updateLink );
};

AbuseFilterMessageLinks.run = function () {
	// Warn
	AbuseFilterMessageLinks.addHandler(
		'mw-abusefilter-warn-message-existing',
		'mw-abusefilter-warn-message-other',
		'mw-abusefilter-warn-preview-button'
	);
	// Disallow
	AbuseFilterMessageLinks.addHandler(
		'mw-abusefilter-disallow-message-existing',
		'mw-abusefilter-disallow-message-other',
		'mw-abusefilter-disallow-preview-button'
	);
};


});

$(document).ready(() => {
	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'AbuseFilter'
		&& mw.config.get( 'wgPageName' ).match( /^Special:AbuseFilter\/\d+$/ )
	) {
		window.AbuseFilterMessageLinks.init();
	}
});

// </nowiki>