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
|
|
|
|
2018-02-07 21:08:04 +00:00
|
|
|
( function ( mw, $ ) {
|
2012-10-26 00:23:17 +00:00
|
|
|
'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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2014-07-30 14:46:53 +00:00
|
|
|
* @param {Object} details Details about the error
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
2014-07-30 14:46:53 +00:00
|
|
|
function examinerTestProcessFailure( error, details ) {
|
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';
|
2014-07-30 14:46:53 +00:00
|
|
|
} else if ( error === 'http' ) {
|
|
|
|
msg = 'abusefilter-http-error';
|
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
|
2014-07-30 14:46:53 +00:00
|
|
|
.text( mw.msg( msg, details && details.exception ) )
|
2011-08-26 20:12:34 +00:00
|
|
|
.show();
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2018-02-07 21:08:04 +00:00
|
|
|
/**
|
|
|
|
* Tests the filter against an rc event or abuse log entry.
|
|
|
|
*
|
|
|
|
* @context HTMLElement
|
|
|
|
* @param {jQuery.Event} e
|
|
|
|
*/
|
|
|
|
function examinerTestFilter() {
|
|
|
|
var filter = $( '#wpTestFilter' ).val(),
|
|
|
|
examine = mw.config.get( 'abuseFilterExamine' ),
|
|
|
|
params = {
|
|
|
|
action: 'abusefiltercheckmatch',
|
|
|
|
filter: filter
|
|
|
|
},
|
|
|
|
api = new mw.Api();
|
|
|
|
|
2018-03-15 17:22:37 +00:00
|
|
|
$( this ).injectSpinner( { id: 'filter-check', size: 'large' } );
|
2018-02-07 21:08:04 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
$( 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
|
|
|
} );
|
2018-02-07 21:08:04 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|