User:DannyS712/AbuseFilterMessageLinks.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:DannyS712/AbuseFilterMessageLinks. |
// <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(
[ 'oojs-ui-core', 'oojs-ui-widgets' ],
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', '/wiki/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>