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
|
|
|
|
2018-11-23 15:44:58 +00:00
|
|
|
( function () {
|
2012-10-26 00:23:17 +00:00
|
|
|
'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.
|
2020-06-06 15:16:41 +00:00
|
|
|
*
|
|
|
|
* @this HTMLElement
|
2018-10-03 12:02:00 +00:00
|
|
|
* @param {jQuery.Event} e The event fired when the function is called
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
|
|
|
function doExprSubmit() {
|
2019-08-17 16:53:13 +00:00
|
|
|
var expr = $( '#wpFilterRules' ).val(),
|
2013-04-17 12:27:46 +00:00
|
|
|
api = new mw.Api();
|
2018-03-10 03:21:04 +00:00
|
|
|
$( this ).injectSpinner( { id: 'abusefilter-expr', size: 'large' } );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2014-07-28 23:16:30 +00:00
|
|
|
api.post( {
|
2012-10-26 00:23:17 +00:00
|
|
|
action: 'abusefilterevalexpression',
|
2018-03-26 18:41:20 +00:00
|
|
|
expression: expr,
|
|
|
|
prettyprint: 1
|
2012-10-26 00:23:17 +00:00
|
|
|
} )
|
2018-11-19 14:39:43 +00:00
|
|
|
.fail( function showError( error, details ) {
|
2018-03-26 18:41:20 +00:00
|
|
|
// TODO This might use api.getErrorMessage()
|
|
|
|
var msg;
|
|
|
|
if ( error === 'http' ) {
|
|
|
|
msg = 'abusefilter-http-error';
|
|
|
|
} else if ( error === 'abusefilter-tools-syntax-error' ) {
|
|
|
|
msg = 'abusefilter-tools-syntax-error';
|
|
|
|
} else {
|
|
|
|
msg = 'unknown-error';
|
|
|
|
}
|
2018-02-07 21:08:04 +00:00
|
|
|
$.removeSpinner( 'abusefilter-expr' );
|
|
|
|
$( '#mw-abusefilter-expr-result' )
|
2018-03-26 18:41:20 +00:00
|
|
|
// Message keys are listed above
|
|
|
|
// eslint-disable-next-line mediawiki/msg-doc
|
|
|
|
.text( mw.msg( msg, details.exception ) )
|
2020-08-19 15:08:35 +00:00
|
|
|
.addClass( 'mw-abusefilter-tools-error' )
|
|
|
|
.show();
|
2018-02-07 21:08:04 +00:00
|
|
|
} )
|
2018-11-19 14:39:43 +00:00
|
|
|
.done( function showResult( data ) {
|
2018-02-07 21:08:04 +00:00
|
|
|
$.removeSpinner( 'abusefilter-expr' );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2018-02-07 21:08:04 +00:00
|
|
|
$( '#mw-abusefilter-expr-result' )
|
2018-03-26 18:41:20 +00:00
|
|
|
.text( data.abusefilterevalexpression.result )
|
2020-08-19 15:08:35 +00:00
|
|
|
.removeClass( 'mw-abusefilter-tools-error' )
|
|
|
|
.show();
|
2018-02-07 21:08:04 +00:00
|
|
|
} );
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes the result of the unblocking autopromotions for a user
|
|
|
|
*
|
2018-10-03 12:02:00 +00:00
|
|
|
* @param {Object} data The response of the API request
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
|
|
|
function processReautoconfirm( data ) {
|
|
|
|
mw.notify(
|
2018-10-03 15:55:06 +00:00
|
|
|
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
|
|
|
|
*
|
2018-10-03 12:02:00 +00:00
|
|
|
* @param {string} errorCode Identifier of the error
|
|
|
|
* @param {Object} data The response of the API request
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
2018-02-07 21:08:04 +00:00
|
|
|
/**
|
|
|
|
* Submits a call to reautoconfirm a user.
|
2020-06-06 15:16:41 +00:00
|
|
|
*
|
|
|
|
* @this HTMLElement
|
2018-10-03 12:02:00 +00:00
|
|
|
* @param {jQuery.Event} e The event fired when the function is called
|
|
|
|
* @return {boolean} False to prevent form submission
|
2018-02-07 21:08:04 +00:00
|
|
|
*/
|
|
|
|
function doReautoSubmit() {
|
2018-03-10 03:21:04 +00:00
|
|
|
var nameField = OO.ui.infuse( $( '#reautoconfirm-user' ) ),
|
|
|
|
name = nameField.getValue(),
|
2018-02-07 21:08:04 +00:00
|
|
|
api;
|
|
|
|
|
|
|
|
if ( name === '' ) {
|
2018-03-10 03:21:04 +00:00
|
|
|
return false;
|
2018-02-07 21:08:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 03:21:04 +00:00
|
|
|
$( this ).injectSpinner( { id: 'abusefilter-reautoconfirm', size: 'large' } );
|
2018-02-07 21:08:04 +00:00
|
|
|
|
|
|
|
api = new mw.Api();
|
|
|
|
api.post( {
|
|
|
|
action: 'abusefilterunblockautopromote',
|
|
|
|
user: name,
|
2019-09-22 00:49:21 +00:00
|
|
|
token: mw.user.tokens.get( 'csrfToken' )
|
2018-02-07 21:08:04 +00:00
|
|
|
} )
|
|
|
|
.done( processReautoconfirm )
|
|
|
|
.fail( processReautoconfirmFailure );
|
2018-03-10 03:21:04 +00:00
|
|
|
return false;
|
2018-02-07 21:08:04 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 17:36:42 +00:00
|
|
|
$( function initialize() {
|
|
|
|
$( '#mw-abusefilter-submitexpr' ).on( 'click', doExprSubmit );
|
2019-09-13 18:31:17 +00:00
|
|
|
if ( $( '#mw-abusefilter-reautoconfirmsubmit' ).length ) {
|
|
|
|
$( '#mw-abusefilter-reautoconfirmsubmit' ).on( 'click', doReautoSubmit );
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
} );
|
2018-11-23 15:44:58 +00:00
|
|
|
}() );
|