mediawiki-extensions-AbuseF.../modules/ext.abuseFilter.examine.js
Marius Hoch 1958d74854 Fix AbuseFilter JS
Temp. fix, please look at https://gerrit.wikimedia.org/r/30110

Change-Id: Ic890a6f7b39618dba9f310244777e69435940cce
2012-10-26 16:21:08 +02:00

79 lines
1.9 KiB
JavaScript

// Filter checking for examine
( function( $, mw ) {
// Reference to this
var that = this,
// Syntax result div
// @type {jQuery}
$syntaxResult;
// Tests the filter against an rc event or abuse log entry
this.examinerTestFilter = function() {
var filter = $( '#wpTestFilter' ).val(),
examine = mw.config.get( 'abuseFilterExamine' ),
params = {};
$( this ).injectSpinner( 'filter-check' );
if ( examine.type === 'rc' ) {
params = {
rcid: examine.id
};
} else {
params = {
logid: examine.id
};
}
// Large amount of data
$.post(
mw.util.wikiScript( 'api' ), $.extend( params, {
action: 'abusefiltercheckmatch',
filter: filter,
format: 'json'
} ), that.examinerTestProcess, 'json'
);
};
// Processes the results of the filter test
// @param {Object} data
this.examinerTestProcess = function( data ) {
var msg;
$.removeSpinner( 'filter-check' );
if ( data.error !== undefined ) {
// Hmm, something went awry
if ( data.error.code === 'badsyntax' ) {
$syntaxResult.attr(
'class', 'mw-abusefilter-examine-syntaxerror'
);
msg = 'abusefilter-examine-syntaxerror';
} else if ( data.error.code === 'nosuchrcid'
|| data.error.code === 'nosuchlogid'
) {
msg = 'abusefilter-examine-notfound';
} else if ( data.error.code === 'nopermission' ) {
return;
}
} else {
var exClass;
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 );
}
$syntaxResult
.text( mw.msg( msg ) )
.show();
};
$( function( $ ) {
$syntaxResult = $( '#mw-abusefilter-syntaxresult' );
$( '#mw-abusefilter-examine-test' ).click( that.examinerTestFilter );
} );
} ( jQuery, mediaWiki ) );