User:Suffusion of Yellow/filterTest.js

/* * filterTest: Adds a button at Special:AbuseFilter/nnn pages to open * Special:AbuseFilter/test with what's currently in the _edit window_. * The built-in link only tests the pattern currently in the _database_, * which is probably not what you want. */ // (function {	/* globals $, mw, OO */	'use strict';

function openTest { let id = mw.config.get('wgPageName').match(/\d+$/); let suffix = id ? "/" + id[0] : "";

let $form = $(' ', {            style: "display: none;",            action: "/wiki/Special:AbuseFilter/test" + suffix,            target: "_blank",            method: "POST"        });

$(' ', {			type: 'hidden',           name: 'wpFilterRules',            value: $('#wpFilterRules').val        }).appendTo($form);

$(' ', {			type: 'hidden',           name: 'wpShowNegative',            value: '1'        }).appendTo($form);

$form.appendTo('body').submit.remove; }

function addButtons { if (!$("#mw-abusefilter-editing-form").length) return;

let testButton = new OO.ui.ButtonWidget({			id: "efb-test-changes",			label: "Test changes",			title: "Test the modified pattern against recent changes",		});

testButton.on('click', openTest);

$('#mw-abusefilter-syntaxcheck, #efb-show-changes') .last.after(testButton.$element);

/* Prevent buttons from shifting when "Check syntax" is clicked */ mw.util.addCSS(".mw-spinner { display: none; } "); }

if (mw.config.get('wgCanonicalSpecialPageName') == "AbuseFilter") $.when($.ready,			  mw.loader.using(['mediawiki.util', 'oojs-ui', ])).then(addButtons); }); //