mediawiki-extensions-AbuseF.../modules/ext.abuseFilter.examine.js
Daimona Eaytoy 7450fb1d62 Switch /test and /examine/# to OOUI
Standardized Special:AbuseFilter/test and /examine/# to OOUI. They need
to be updated together, since they share the same load filter button
(now centralized) which needs to be handled in a different way.

Bug: T132284
Bug: T58367
Bug: T58368
Depends-On: If3d6a994142e34686bb7fc9f09093f751b599485
Change-Id: Ib935e8c9706e987468e52ec2ad1c7219b35fb9d5
2018-03-30 13:12:36 -04:00

102 lines
2.4 KiB
JavaScript

/**
* Check a filter against a change
*
* @author John Du Hart
* @author Marius Hoch <hoo@online.de>
*/
( function ( mw, $ ) {
'use strict';
// Syntax result div
// @type {jQuery}
var $syntaxResult;
/**
* Processes the results of the filter test
*
* @param {Object} data
*/
function examinerTestProcess( data ) {
var msg, exClass;
$.removeSpinner( 'filter-check' );
if ( data.abusefiltercheckmatch.result ) {
exClass = 'mw-abusefilter-examine-match';
msg = 'abusefilter-examine-match';
} else {
exClass = 'mw-abusefilter-examine-nomatch';
msg = 'abusefilter-examine-nomatch';
}
$syntaxResult
.attr( 'class', exClass )
.text( mw.msg( msg ) )
.show();
}
/**
* Processes the results of the filter test in case of an error
*
* @param {string} error Error code returned from the AJAX request
* @param {Object} details Details about the error
*/
function examinerTestProcessFailure( error, details ) {
var msg;
$.removeSpinner( 'filter-check' );
if ( error === 'badsyntax' ) {
$syntaxResult.attr(
'class', 'mw-abusefilter-syntaxresult-error'
);
msg = 'abusefilter-examine-syntaxerror';
} else if ( error === 'nosuchrcid' || error === 'nosuchlogid' ) {
msg = 'abusefilter-examine-notfound';
} else if ( error === 'permissiondenied' ) {
// The 'abusefilter-modify' right is needed to use this API
msg = 'abusefilter-mustbeeditor';
} else if ( error === 'http' ) {
msg = 'abusefilter-http-error';
} else {
msg = 'unknown-error';
}
$syntaxResult
.text( mw.msg( msg, details && details.exception ) )
.show();
}
/**
* Tests the filter against an rc event or abuse log entry.
*
* @context HTMLElement
* @param {jQuery.Event} e
*/
function examinerTestFilter() {
var filter = $( '#wpTestFilter' ).val(),
examine = mw.config.get( 'abuseFilterExamine' ),
params = {
action: 'abusefiltercheckmatch',
filter: filter
},
api = new mw.Api();
$( this ).injectSpinner( { id: 'filter-check', size: 'large' } );
if ( examine.type === 'rc' ) {
params.rcid = examine.id;
} else {
params.logid = examine.id;
}
// Use post due to the rather large amount of data
api.post( params )
.done( examinerTestProcess )
.fail( examinerTestProcessFailure );
}
$( document ).ready( function () {
$syntaxResult = $( '#mw-abusefilter-syntaxresult' );
$( '#mw-abusefilter-examine-test' ).click( examinerTestFilter );
} );
}( mediaWiki, jQuery ) );