2012-10-26 00:23:17 +00:00
|
|
|
/**
|
|
|
|
* JavaScript for AbuseFilter tools
|
|
|
|
*
|
|
|
|
* @author John Du Hart
|
|
|
|
* @author Marius Hoch <hoo@online.de>
|
|
|
|
*/
|
2012-09-02 11:07:02 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
( function( mw, $ ) {
|
|
|
|
'use strict';
|
2012-09-02 11:07:02 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
/**
|
2013-04-02 19:44:01 +00:00
|
|
|
* Submits the expression to be evaluated.
|
|
|
|
* @context HTMLElement
|
|
|
|
* @param {jQuery.Event} e
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
|
|
|
function doExprSubmit() {
|
2013-04-02 19:44:01 +00:00
|
|
|
/*jshint validthis:true */
|
2013-04-17 12:27:46 +00:00
|
|
|
var expr = $( '#wpTestExpr' ).val(),
|
|
|
|
api = new mw.Api();
|
2011-08-26 20:12:34 +00:00
|
|
|
$( this ).injectSpinner( 'abusefilter-expr' );
|
|
|
|
|
2014-07-28 23:16:30 +00:00
|
|
|
api.post( {
|
2012-10-26 00:23:17 +00:00
|
|
|
action: 'abusefilterevalexpression',
|
|
|
|
expression: expr
|
|
|
|
} )
|
2014-07-30 14:46:53 +00:00
|
|
|
.fail( function( error, details ) {
|
|
|
|
var msg = error === 'http' ? 'abusefilter-http-error' : 'unknown-error';
|
2012-10-26 00:23:17 +00:00
|
|
|
$.removeSpinner( 'abusefilter-expr' );
|
|
|
|
$( '#mw-abusefilter-expr-result' )
|
2014-07-30 14:46:53 +00:00
|
|
|
.text( mw.msg( msg, details.exception ) );
|
2012-10-26 00:23:17 +00:00
|
|
|
} )
|
|
|
|
.done( function( data ) {
|
|
|
|
$.removeSpinner( 'abusefilter-expr' );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
$( '#mw-abusefilter-expr-result' )
|
|
|
|
.text( data.abusefilterevalexpression.result );
|
|
|
|
} );
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
/**
|
2013-04-02 19:44:01 +00:00
|
|
|
* Submits a call to reautoconfirm a user.
|
|
|
|
* @context HTMLElement
|
|
|
|
* @param {jQuery.Event} e
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
|
|
|
function doReautoSubmit() {
|
2013-04-02 19:44:01 +00:00
|
|
|
/*jshint validthis:true */
|
2013-04-17 12:27:46 +00:00
|
|
|
var name = $( '#reautoconfirm-user' ).val(),
|
|
|
|
api;
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
if ( name === '' ) {
|
2011-08-26 20:12:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$( this ).injectSpinner( 'abusefilter-reautoconfirm' );
|
2012-10-26 00:23:17 +00:00
|
|
|
|
2013-04-17 12:27:46 +00:00
|
|
|
api = new mw.Api();
|
2012-10-26 00:23:17 +00:00
|
|
|
api.post( {
|
|
|
|
action: 'abusefilterunblockautopromote',
|
|
|
|
user: name,
|
|
|
|
token: mw.user.tokens.get( 'editToken' )
|
|
|
|
} )
|
|
|
|
.done( processReautoconfirm )
|
|
|
|
.fail( processReautoconfirmFailure );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes the result of the unblocking autopromotions for a user
|
|
|
|
*
|
|
|
|
* @param {Object} data
|
|
|
|
*/
|
|
|
|
function processReautoconfirm( data ) {
|
|
|
|
mw.notify(
|
|
|
|
mw.message( 'abusefilter-reautoconfirm-done', data.abusefilterunblockautopromote.user ).toString()
|
2011-08-26 20:12:34 +00:00
|
|
|
);
|
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
$.removeSpinner( 'abusefilter-reautoconfirm' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes the result of the unblocking autopromotions for a user in case of an error
|
|
|
|
*
|
|
|
|
* @param {string} errorCode
|
|
|
|
* @param {Object} data
|
|
|
|
*/
|
|
|
|
function processReautoconfirmFailure( errorCode, data ) {
|
2011-08-26 20:12:34 +00:00
|
|
|
var msg;
|
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
switch ( errorCode ) {
|
|
|
|
case 'permissiondenied':
|
|
|
|
msg = mw.msg( 'abusefilter-reautoconfirm-notallowed' );
|
|
|
|
break;
|
2014-07-30 14:46:53 +00:00
|
|
|
case 'http':
|
|
|
|
msg = mw.msg( 'abusefilter-http-error', data && data.exception );
|
|
|
|
break;
|
2012-10-26 00:23:17 +00:00
|
|
|
case 'notsuspended':
|
|
|
|
msg = data.error.info;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
msg = mw.msg( 'unknown-error' );
|
|
|
|
break;
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
2012-10-26 00:23:17 +00:00
|
|
|
mw.notify( msg );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
|
|
|
$.removeSpinner( 'abusefilter-reautoconfirm' );
|
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() {
|
|
|
|
$( '#mw-abusefilter-submitexpr' ).click( doExprSubmit );
|
|
|
|
$( '#mw-abusefilter-reautoconfirmsubmit' ).click( doReautoSubmit );
|
2011-08-26 20:12:34 +00:00
|
|
|
} );
|
2012-10-26 00:23:17 +00:00
|
|
|
} ( mediaWiki, jQuery ) );
|