2012-10-26 00:23:17 +00:00
|
|
|
/**
|
|
|
|
* Check a filter against a change
|
|
|
|
*
|
|
|
|
* @author John Du Hart
|
|
|
|
* @author Marius Hoch <hoo@online.de>
|
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
( function( mw, $ ) {
|
|
|
|
'use strict';
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
// Syntax result div
|
|
|
|
// @type {jQuery}
|
|
|
|
var $syntaxResult;
|
|
|
|
|
|
|
|
/**
|
2013-04-02 19:44:01 +00:00
|
|
|
* Tests the filter against an rc event or abuse log entry.
|
|
|
|
*
|
|
|
|
* @context HTMLElement
|
|
|
|
* @param {jQuery.Event} e
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
|
|
|
function examinerTestFilter() {
|
2013-04-02 19:44:01 +00:00
|
|
|
/*jshint validthis:true */
|
2011-08-26 20:12:34 +00:00
|
|
|
var filter = $( '#wpTestFilter' ).val(),
|
2011-08-26 20:26:57 +00:00
|
|
|
examine = mw.config.get( 'abuseFilterExamine' ),
|
2012-10-26 00:23:17 +00:00
|
|
|
params = {
|
|
|
|
action: 'abusefiltercheckmatch',
|
|
|
|
filter: filter
|
2013-04-17 12:27:46 +00:00
|
|
|
},
|
|
|
|
api = new mw.Api();
|
2012-10-26 00:23:17 +00:00
|
|
|
|
2011-08-26 20:12:34 +00:00
|
|
|
$( this ).injectSpinner( 'filter-check' );
|
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
if ( examine.type === 'rc' ) {
|
2012-10-26 00:23:17 +00:00
|
|
|
params.rcid = examine.id;
|
2011-08-26 20:12:34 +00:00
|
|
|
} else {
|
2012-10-26 00:23:17 +00:00
|
|
|
params.logid = examine.id;
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
// Use post due to the rather large amount of data
|
|
|
|
api.post( params )
|
|
|
|
.done( examinerTestProcess )
|
|
|
|
.fail( examinerTestProcessFailure );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
/**
|
|
|
|
* Processes the results of the filter test in case of an error
|
|
|
|
*
|
|
|
|
* @param {string} error Error code returned from the AJAX request
|
|
|
|
*/
|
|
|
|
function examinerTestProcessFailure( error ) {
|
2011-08-26 20:12:34 +00:00
|
|
|
var msg;
|
|
|
|
$.removeSpinner( 'filter-check' );
|
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
if ( error === 'badsyntax' ) {
|
|
|
|
$syntaxResult.attr(
|
2013-05-24 14:45:35 +00:00
|
|
|
'class', 'mw-abusefilter-syntaxresult-error'
|
2012-10-26 00:23:17 +00:00
|
|
|
);
|
|
|
|
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';
|
2011-08-26 20:12:34 +00:00
|
|
|
} else {
|
2012-10-26 00:23:17 +00:00
|
|
|
msg = 'unknown-error';
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$syntaxResult
|
|
|
|
.text( mw.msg( msg ) )
|
|
|
|
.show();
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
$( document ).ready( function() {
|
2012-02-21 04:03:00 +00:00
|
|
|
$syntaxResult = $( '#mw-abusefilter-syntaxresult' );
|
2012-10-26 00:23:17 +00:00
|
|
|
$( '#mw-abusefilter-examine-test' ).click( examinerTestFilter );
|
2011-08-26 20:12:34 +00:00
|
|
|
} );
|
2012-10-26 00:23:17 +00:00
|
|
|
} ( mediaWiki, jQuery ) );
|