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