mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-15 02:03:53 +00:00
b235e1040a
Now it's always wider, and so is the "notes" field. Moreover, the fallback textarea has the exact same size. Plus removed a parameter which only made it hard to write a CSS rule for the textarea. Since the textarea is generated by the same code, and we're always using it for the same thing (filter syntax, regardless of the final goal), make it always use the same name. Bug: T230591 Change-Id: Ibb308e80d954c0e81aa09249c38c39572f157948
102 lines
2.5 KiB
JavaScript
102 lines
2.5 KiB
JavaScript
/**
|
|
* Check a filter against a change
|
|
*
|
|
* @author John Du Hart
|
|
* @author Marius Hoch <hoo@online.de>
|
|
*/
|
|
|
|
( function () {
|
|
'use strict';
|
|
|
|
// @var {jQuery} Syntax result div
|
|
var $syntaxResult;
|
|
|
|
/**
|
|
* Processes the results of the filter test
|
|
*
|
|
* @param {Object} data The response of the API request
|
|
*/
|
|
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' or 'abusefilter-view-private' right is needed
|
|
// to use this API
|
|
msg = 'abusefilter-mustviewprivateoredit';
|
|
} 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 The event fired when the function is called
|
|
*/
|
|
function examinerTestFilter() {
|
|
var filter = $( '#wpFilterRules' ).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 );
|
|
}
|
|
|
|
$( function initialize() {
|
|
$syntaxResult = $( '#mw-abusefilter-syntaxresult' );
|
|
$( '#mw-abusefilter-examine-test' ).on( 'click', examinerTestFilter );
|
|
} );
|
|
}() );
|