mediawiki-extensions-AbuseF.../modules/ext.abuseFilter.examine.js
Tim Starling 44c29b8c4f * (bug 34538) Fixed compatibility with $wgResourceLoaderExperimentalAsyncLoading in some extensions.
* Tested AbuseFilter.
* Did not test ArticleCreationWorkflow, Configure, ContributionTracking, FlaggedRevs, FundraiserPortal, InlineCategorizer, MarkAsHelpful, Math/Mathjax.
* Fixed a typo in a comment in LiveTranslate.
* Did not review extensions alphabetically after MoodBar.
2012-02-21 04:03:00 +00:00

91 lines
1.9 KiB
JavaScript

/**
* Filter checking for examine
*/
new ( function( $, mw ) {
/**
* Reference to this
*/
var that = this;
/**
* Syntax result div
*
* @type {jQuery}
*/
var $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 );