/*
 * 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.
 */
//<nowiki>
(function() {
	/* globals $, mw, OO */
	'use strict';

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

        let $form = $('<form></form>', {
            style: "display: none;",
            action: "https://wiki95.com/en/Special:AbuseFilter/test" + suffix,
            target: "_blank",
            method: "POST"
        });

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

        $('<input>', {
			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);
})();
//</nowiki>