2012-10-26 00:23:17 +00:00
|
|
|
/**
|
|
|
|
* AbuseFilter editing JavaScript
|
|
|
|
*
|
|
|
|
* @author John Du Hart
|
|
|
|
* @author Marius Hoch <hoo@online.de>
|
|
|
|
*/
|
2018-03-30 06:55:03 +00:00
|
|
|
/* global ace */
|
2012-10-26 00:23:17 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
( function ( mw, $, OO ) {
|
2012-10-26 00:23:17 +00:00
|
|
|
'use strict';
|
2012-09-02 11:07:02 +00:00
|
|
|
|
2018-03-30 06:55:03 +00:00
|
|
|
// Filter editor for JS and jQuery handling
|
2012-09-02 11:07:02 +00:00
|
|
|
// @var {jQuery}
|
2018-03-30 06:55:03 +00:00
|
|
|
var $filterBox,
|
|
|
|
// Filter editor for Ace specific functions
|
|
|
|
filterEditor,
|
|
|
|
// Hidden textarea for submitting form
|
|
|
|
// @var {jQuery}
|
|
|
|
$plainTextBox,
|
|
|
|
// Bool to determine what editor to use
|
2018-03-23 09:13:41 +00:00
|
|
|
useAce = false,
|
|
|
|
// Infused OOUI elements
|
|
|
|
togglePreviewButton,
|
|
|
|
messageExisting,
|
|
|
|
messageOther;
|
2012-10-26 00:23:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the currently selected warning message
|
|
|
|
*
|
2018-02-07 21:08:04 +00:00
|
|
|
* @return {string} current warning message
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
|
|
|
function getCurrentWarningMessage() {
|
2018-03-23 09:13:41 +00:00
|
|
|
var message = messageExisting.getValue();
|
2012-10-26 00:23:17 +00:00
|
|
|
|
|
|
|
if ( message === 'other' ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
message = messageOther.getValue();
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
return message;
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
/**
|
|
|
|
* Things always needed after syntax checks
|
|
|
|
*
|
|
|
|
* @param {string} resultText
|
|
|
|
* @param {string} className Class to add
|
|
|
|
* @param {bool} syntaxOk Is the syntax ok?
|
|
|
|
*/
|
|
|
|
function processSyntaxResultAlways( resultText, className, syntaxOk ) {
|
2011-08-26 20:12:34 +00:00
|
|
|
$.removeSpinner( 'abusefilter-syntaxcheck' );
|
2017-08-09 16:54:42 +00:00
|
|
|
$( '#mw-abusefilter-syntaxcheck' ).prop( 'disabled', false );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
$( '#mw-abusefilter-syntaxresult' )
|
2011-08-26 20:12:34 +00:00
|
|
|
.show()
|
2017-07-14 17:47:20 +00:00
|
|
|
.attr( 'class', className )
|
2012-10-26 00:23:17 +00:00
|
|
|
.text( resultText )
|
|
|
|
.data( 'syntaxOk', syntaxOk );
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2018-03-30 06:55:03 +00:00
|
|
|
/**
|
|
|
|
* Switch between Ace Editor and classic textarea
|
|
|
|
*/
|
|
|
|
function switchEditor() {
|
|
|
|
if ( useAce ) {
|
|
|
|
useAce = false;
|
|
|
|
$filterBox.hide();
|
|
|
|
$plainTextBox.show();
|
|
|
|
} else {
|
|
|
|
useAce = true;
|
|
|
|
filterEditor.session.setValue( $plainTextBox.val() );
|
|
|
|
$filterBox.show();
|
|
|
|
$plainTextBox.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
/**
|
|
|
|
* Takes the data retrieved in doSyntaxCheck and processes it
|
|
|
|
*
|
|
|
|
* @param {Object} data Data returned from the AJAX request
|
|
|
|
*/
|
|
|
|
function processSyntaxResult( data ) {
|
2018-03-30 06:55:03 +00:00
|
|
|
var position;
|
2012-10-26 00:23:17 +00:00
|
|
|
data = data.abusefilterchecksyntax;
|
2011-09-30 00:48:00 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
if ( data.status === 'ok' ) {
|
2011-08-26 20:12:34 +00:00
|
|
|
// Successful
|
2012-10-26 00:23:17 +00:00
|
|
|
processSyntaxResultAlways(
|
|
|
|
mw.msg( 'abusefilter-edit-syntaxok' ),
|
|
|
|
'mw-abusefilter-syntaxresult-ok',
|
|
|
|
true
|
|
|
|
);
|
2011-08-26 20:12:34 +00:00
|
|
|
} else {
|
2012-10-26 00:23:17 +00:00
|
|
|
// Set a custom error message as we're aware of the actual problem
|
|
|
|
processSyntaxResultAlways(
|
|
|
|
mw.message( 'abusefilter-edit-syntaxerr', data.message ).toString(),
|
|
|
|
'mw-abusefilter-syntaxresult-error',
|
|
|
|
false
|
|
|
|
);
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2018-03-30 06:55:03 +00:00
|
|
|
if ( useAce ) {
|
|
|
|
filterEditor.focus();
|
2018-04-12 10:03:52 +00:00
|
|
|
// Convert index (used in textareas) in position {row, column} for ace
|
|
|
|
position = filterEditor.session.getDocument().indexToPosition( data.character );
|
2018-03-30 06:55:03 +00:00
|
|
|
filterEditor.navigateTo( position.row, position.column );
|
|
|
|
filterEditor.scrollToRow( position.row );
|
|
|
|
} else {
|
|
|
|
$plainTextBox
|
|
|
|
.focus()
|
|
|
|
.textSelection( 'setSelection', { start: data.character } );
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Acts on errors after doSyntaxCheck
|
2014-07-30 14:46:53 +00:00
|
|
|
*
|
|
|
|
* @param {string} error Error code returned from the AJAX request
|
|
|
|
* @param {Object} details Details about the error
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
2014-07-30 14:46:53 +00:00
|
|
|
function processSyntaxResultFailure( error, details ) {
|
|
|
|
var msg = error === 'http' ? 'abusefilter-http-error' : 'unknown-error';
|
2012-10-26 00:23:17 +00:00
|
|
|
processSyntaxResultAlways(
|
2014-07-30 14:46:53 +00:00
|
|
|
mw.msg( msg, details && details.exception ),
|
2012-10-26 00:23:17 +00:00
|
|
|
'mw-abusefilter-syntaxresult-error',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2018-02-07 21:08:04 +00:00
|
|
|
/**
|
|
|
|
* Sends the current filter text to be checked for syntax issues.
|
|
|
|
*
|
|
|
|
* @context HTMLElement
|
|
|
|
* @param {jQuery.Event} e
|
|
|
|
*/
|
|
|
|
function doSyntaxCheck() {
|
2018-03-30 06:55:03 +00:00
|
|
|
var filter = $plainTextBox.val(),
|
2018-02-07 21:08:04 +00:00
|
|
|
api = new mw.Api();
|
|
|
|
|
|
|
|
$( this )
|
|
|
|
.prop( 'disabled', true )
|
2018-03-16 08:42:42 +00:00
|
|
|
.injectSpinner( { id: 'abusefilter-syntaxcheck', size: 'large' } );
|
2018-02-07 21:08:04 +00:00
|
|
|
|
|
|
|
api.post( {
|
|
|
|
action: 'abusefilterchecksyntax',
|
|
|
|
filter: filter
|
|
|
|
} )
|
|
|
|
.done( processSyntaxResult )
|
|
|
|
.fail( processSyntaxResultFailure );
|
|
|
|
}
|
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
/**
|
|
|
|
* Adds text to the filter textarea
|
|
|
|
* Fired by a change event from the #wpFilterBuilder dropdown
|
|
|
|
*/
|
|
|
|
function addText() {
|
2011-08-26 20:12:34 +00:00
|
|
|
var $filterBuilder = $( '#wpFilterBuilder' );
|
2012-09-02 11:07:02 +00:00
|
|
|
|
|
|
|
if ( $filterBuilder.prop( 'selectedIndex' ) === 0 ) {
|
2011-08-26 20:12:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-30 06:55:03 +00:00
|
|
|
if ( useAce ) {
|
|
|
|
filterEditor.insert( $filterBuilder.val() + ' ' );
|
|
|
|
$plainTextBox.val( filterEditor.getSession().getValue() );
|
|
|
|
} else {
|
|
|
|
$plainTextBox.textSelection(
|
|
|
|
'encapsulateSelection', { pre: $filterBuilder.val() + ' ' }
|
|
|
|
);
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
$filterBuilder.prop( 'selectedIndex', 0 );
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
/**
|
2013-04-02 19:44:01 +00:00
|
|
|
* Fetches a filter from the API and inserts it into the filter box.
|
|
|
|
*
|
|
|
|
* @context HTMLElement
|
|
|
|
* @param {jQuery.Event} e
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
|
|
|
function fetchFilter() {
|
2018-03-15 17:22:37 +00:00
|
|
|
var filterId = $.trim( $( '#mw-abusefilter-load-filter input' ).val() ),
|
2013-04-17 12:27:46 +00:00
|
|
|
api;
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
if ( filterId === '' ) {
|
2011-08-26 20:12:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-16 08:42:42 +00:00
|
|
|
$( this ).injectSpinner( { id: 'fetch-spinner', size: 'large' } );
|
2012-10-26 00:23:17 +00:00
|
|
|
|
|
|
|
// We just ignore errors or unexisting filters over here
|
2013-04-17 12:27:46 +00:00
|
|
|
api = new mw.Api();
|
2012-10-26 00:23:17 +00:00
|
|
|
api.get( {
|
|
|
|
action: 'query',
|
|
|
|
list: 'abusefilters',
|
|
|
|
abfprop: 'pattern',
|
|
|
|
abfstartid: filterId,
|
|
|
|
abfendid: filterId,
|
|
|
|
abflimit: 1
|
|
|
|
} )
|
2018-02-07 21:08:04 +00:00
|
|
|
.always( function () {
|
|
|
|
$.removeSpinner( 'fetch-spinner' );
|
|
|
|
} )
|
|
|
|
.done( function ( data ) {
|
|
|
|
if ( data.query.abusefilters[ 0 ] !== undefined ) {
|
2018-03-30 06:55:03 +00:00
|
|
|
if ( useAce ) {
|
|
|
|
filterEditor.setValue( data.query.abusefilters[ 0 ].pattern );
|
|
|
|
}
|
|
|
|
$plainTextBox.val( data.query.abusefilters[ 0 ].pattern );
|
2018-02-07 21:08:04 +00:00
|
|
|
}
|
|
|
|
} );
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
/**
|
|
|
|
* Cycles through all action checkboxes and hides parameter divs
|
|
|
|
* that don't have checked boxes
|
|
|
|
*/
|
|
|
|
function hideDeselectedActions() {
|
2018-03-23 09:13:41 +00:00
|
|
|
$( '.mw-abusefilter-action-checkbox input' ).each( function () {
|
2011-09-30 00:48:00 +00:00
|
|
|
// mw-abusefilter-action-checkbox-{$action}
|
2018-03-23 09:13:41 +00:00
|
|
|
var action = this.parentNode.id.substr( 31 ),
|
2012-09-02 11:07:02 +00:00
|
|
|
$params = $( '#mw-abusefilter-' + action + '-parameters' );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
|
|
|
if ( $params.length ) {
|
|
|
|
if ( this.checked ) {
|
|
|
|
$params.show();
|
|
|
|
} else {
|
|
|
|
$params.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
/**
|
2016-12-26 10:34:16 +00:00
|
|
|
* Fetches the selected warning message for previewing
|
|
|
|
*/
|
2012-10-26 00:23:17 +00:00
|
|
|
function previewWarnMessage() {
|
2016-12-26 10:34:16 +00:00
|
|
|
var api = new mw.Api(),
|
|
|
|
args = [
|
2018-03-10 12:18:49 +00:00
|
|
|
'<nowiki>' + $( 'input[name=wpFilterDescription]' ).val() + '</nowiki>',
|
2016-12-26 10:34:16 +00:00
|
|
|
$( '#mw-abusefilter-edit-id' ).children().last().text()
|
|
|
|
],
|
2018-03-23 09:13:41 +00:00
|
|
|
message = getCurrentWarningMessage(),
|
|
|
|
isVisible = $( '#mw-abusefilter-warn-preview' ).is( ':visible' );
|
|
|
|
|
|
|
|
if ( !isVisible ) {
|
|
|
|
api.get( {
|
|
|
|
action: 'query',
|
|
|
|
meta: 'allmessages',
|
|
|
|
ammessages: message,
|
|
|
|
amargs: args.join( '|' )
|
|
|
|
} )
|
|
|
|
.done( function ( data ) {
|
|
|
|
api.parse( data.query.allmessages[ 0 ][ '*' ], {
|
|
|
|
disablelimitreport: '',
|
|
|
|
preview: '',
|
|
|
|
prop: 'text',
|
|
|
|
title: 'MediaWiki:' + message
|
|
|
|
} )
|
|
|
|
.done( function ( html ) {
|
|
|
|
$( '#mw-abusefilter-warn-preview' ).show().html( html );
|
|
|
|
togglePreviewButton.setFlags( { destructive: true, progressive: false } );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
$( '#mw-abusefilter-warn-preview' ).hide();
|
|
|
|
togglePreviewButton.setFlags( { destructive: false, progressive: true } );
|
|
|
|
}
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirects the browser to the warning message for editing
|
|
|
|
*/
|
|
|
|
function editWarnMessage() {
|
2011-08-26 20:12:34 +00:00
|
|
|
var message = getCurrentWarningMessage();
|
|
|
|
|
2018-02-07 21:08:04 +00:00
|
|
|
window.location = mw.config.get( 'wgScript' ) +
|
|
|
|
'?title=MediaWiki:' + mw.util.wikiUrlencode( message ) +
|
|
|
|
'&action=edit&preload=MediaWiki:abusefilter-warning';
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-23 09:13:41 +00:00
|
|
|
* Called if the filter group (#mw-abusefilter-edit-group-input select) is changed.
|
2013-04-02 19:44:01 +00:00
|
|
|
*
|
|
|
|
* @context HTMLELement
|
|
|
|
* @param {jQuery.Event} e
|
2012-10-26 00:23:17 +00:00
|
|
|
*/
|
|
|
|
function onFilterGroupChange() {
|
2018-03-23 09:13:41 +00:00
|
|
|
var $afWarnMessageExisting, newVal;
|
2012-10-26 00:23:17 +00:00
|
|
|
|
|
|
|
if ( !$( '#mw-abusefilter-action-warn-checkbox' ).is( ':checked' ) ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$afWarnMessageExisting = $( '#mw-abusefilter-warn-message-existing select' );
|
2018-02-07 21:08:04 +00:00
|
|
|
newVal = mw.config.get( 'wgAbuseFilterDefaultWarningMessage' )[ $( this ).val() ];
|
2012-10-26 00:23:17 +00:00
|
|
|
|
2013-04-17 12:27:46 +00:00
|
|
|
if ( $afWarnMessageExisting.find( 'option[value=\'' + newVal + '\']' ).length ) {
|
2012-10-26 00:23:17 +00:00
|
|
|
$afWarnMessageExisting.val( newVal );
|
2018-03-23 09:13:41 +00:00
|
|
|
messageOther.setValue( '' );
|
2012-10-26 00:23:17 +00:00
|
|
|
} else {
|
|
|
|
$afWarnMessageExisting.val( 'other' );
|
2018-03-23 09:13:41 +00:00
|
|
|
messageOther.setValue( newVal );
|
2012-10-26 00:23:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2013-06-26 21:57:20 +00:00
|
|
|
/**
|
|
|
|
* Remove the options for warning messages if the filter is set to global
|
|
|
|
*/
|
|
|
|
function toggleCustomMessages() {
|
|
|
|
// Use the table over here as hideDeselectedActions might alter the visibility of the div
|
|
|
|
var $warnOptions = $( '#mw-abusefilter-warn-parameters > table' );
|
|
|
|
|
|
|
|
if ( $( '#wpFilterGlobal' ).is( ':checked' ) ) {
|
|
|
|
// It's a global filter, so use the default message and hide the option from the user
|
2018-03-23 09:13:41 +00:00
|
|
|
messageExisting.setValue( 'abusefilter-warning' );
|
2013-06-26 21:57:20 +00:00
|
|
|
|
|
|
|
$warnOptions.hide();
|
|
|
|
} else {
|
|
|
|
$warnOptions.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 13:22:11 +00:00
|
|
|
/**
|
|
|
|
* Called if the user presses a key in the load filter field
|
|
|
|
*
|
|
|
|
* @context HTMLELement
|
|
|
|
* @param {jQuery.Event} e
|
|
|
|
*/
|
|
|
|
function onFilterKeypress( e ) {
|
|
|
|
if ( e.type === 'keypress' && e.which === 13 ) {
|
|
|
|
e.preventDefault();
|
|
|
|
$( '#mw-abusefilter-load' ).click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
// On ready initialization
|
2018-02-07 21:08:04 +00:00
|
|
|
$( document ).ready( function () {
|
2018-03-30 06:55:03 +00:00
|
|
|
var basePath, readOnly,
|
2018-03-23 09:13:41 +00:00
|
|
|
$exportBox = $( '#mw-abusefilter-export' ),
|
|
|
|
isFilterEditor = mw.config.get( 'isFilterEditor' ),
|
|
|
|
tagConfig = mw.config.get( 'tagConfig' ),
|
|
|
|
$tagContainer, tagUsed, tagDisabled, tagSelector, tagField, cbEnabled, cbDeleted;
|
|
|
|
|
|
|
|
if ( isFilterEditor ) {
|
|
|
|
// Configure the actual editing interface
|
|
|
|
if ( tagConfig ) {
|
|
|
|
// Build the tag selector
|
|
|
|
$tagContainer = $( '#mw-abusefilter-tag-parameters' );
|
|
|
|
tagUsed = tagConfig.tagUsed;
|
|
|
|
tagDisabled = tagConfig.tagDisabled.length !== 0;
|
|
|
|
// Input field for tags
|
|
|
|
tagSelector =
|
|
|
|
new OO.ui.TagMultiselectWidget( {
|
|
|
|
inputPosition: 'outline',
|
|
|
|
allowArbitrary: true,
|
|
|
|
allowEditTags: true,
|
|
|
|
selected: tagUsed,
|
|
|
|
placeholder: tagConfig.tagPlaceholder,
|
|
|
|
disabled: tagDisabled
|
|
|
|
} );
|
|
|
|
tagField =
|
|
|
|
new OO.ui.FieldLayout(
|
|
|
|
tagSelector,
|
|
|
|
{
|
|
|
|
label: $( $.parseHTML( tagConfig.tagLabel ) ),
|
|
|
|
align: 'top'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
tagSelector.on( 'change', function () {
|
|
|
|
$( '#mw-abusefilter-hidden-tags input' ).val( tagSelector.getValue() );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '#mw-abusefilter-hidden-tags' ).hide();
|
|
|
|
$tagContainer.append( tagField.$element );
|
|
|
|
}
|
|
|
|
|
|
|
|
togglePreviewButton = OO.ui.infuse( $( '#mw-abusefilter-warn-preview-button' ) );
|
|
|
|
messageExisting = OO.ui.infuse( $( '#mw-abusefilter-warn-message-existing' ) );
|
|
|
|
messageOther = OO.ui.infuse( $( '#mw-abusefilter-warn-message-other' ) );
|
|
|
|
}
|
2018-03-30 06:55:03 +00:00
|
|
|
|
|
|
|
$plainTextBox = $( '#' + mw.config.get( 'abuseFilterBoxName' ) );
|
|
|
|
|
|
|
|
if ( $( '#wpAceFilterEditor' ).length ) {
|
|
|
|
// CodeEditor is installed.
|
|
|
|
mw.loader.using( [ 'ext.abuseFilter.ace' ] ).then( function () {
|
|
|
|
$filterBox = $( '#wpAceFilterEditor' );
|
|
|
|
|
|
|
|
filterEditor = ace.edit( 'wpAceFilterEditor' );
|
|
|
|
filterEditor.session.setMode( 'ace/mode/abusefilter' );
|
|
|
|
|
|
|
|
// Ace setup from codeEditor extension
|
|
|
|
basePath = mw.config.get( 'wgExtensionAssetsPath', '' );
|
|
|
|
if ( basePath.slice( 0, 2 ) === '//' ) {
|
|
|
|
// ACE uses web workers, which have importScripts, which don't like relative links.
|
|
|
|
// This is a problem only when the assets are on another server, so this rewrite should suffice
|
|
|
|
// Protocol relative
|
|
|
|
basePath = window.location.protocol + basePath;
|
|
|
|
}
|
|
|
|
ace.config.set( 'basePath', basePath + '/CodeEditor/modules/ace' );
|
|
|
|
|
|
|
|
// Settings for Ace editor box
|
|
|
|
readOnly = mw.config.get( 'aceConfig' ).aceReadOnly;
|
|
|
|
|
|
|
|
filterEditor.setTheme( 'ace/theme/textmate' );
|
|
|
|
filterEditor.session.setOption( 'useWorker', false );
|
|
|
|
filterEditor.setReadOnly( readOnly );
|
|
|
|
filterEditor.$blockScrolling = Infinity;
|
|
|
|
|
2018-04-16 15:01:35 +00:00
|
|
|
// Display Ace editor
|
|
|
|
switchEditor();
|
2018-03-30 06:55:03 +00:00
|
|
|
|
|
|
|
// Hide the syntax ok message when the text changes and sync dummy box
|
|
|
|
$filterBox.keyup( function () {
|
|
|
|
var $el = $( '#mw-abusefilter-syntaxresult' );
|
|
|
|
|
|
|
|
if ( $el.data( 'syntaxOk' ) ) {
|
|
|
|
$el.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
$plainTextBox.val( filterEditor.getSession().getValue() );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '#mw-abusefilter-switcheditor' ).click( switchEditor );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2011-08-26 20:12:34 +00:00
|
|
|
// Hide the syntax ok message when the text changes
|
2018-03-30 06:55:03 +00:00
|
|
|
$plainTextBox.keyup( function () {
|
2011-08-26 20:12:34 +00:00
|
|
|
var $el = $( '#mw-abusefilter-syntaxresult' );
|
2012-09-02 11:07:02 +00:00
|
|
|
|
2011-08-26 20:12:34 +00:00
|
|
|
if ( $el.data( 'syntaxOk' ) ) {
|
|
|
|
$el.hide();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
$( '#mw-abusefilter-load' ).click( fetchFilter );
|
2013-07-17 13:22:11 +00:00
|
|
|
$( '#mw-abusefilter-load-filter' ).keypress( onFilterKeypress );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
if ( isFilterEditor ) {
|
|
|
|
// Add logic for flags and consequences
|
|
|
|
$( '#mw-abusefilter-warn-preview-button' ).click( previewWarnMessage );
|
|
|
|
$( '#mw-abusefilter-warn-edit-button' ).click( editWarnMessage );
|
|
|
|
$( '.mw-abusefilter-action-checkbox input' ).click( hideDeselectedActions );
|
|
|
|
hideDeselectedActions();
|
|
|
|
|
|
|
|
$( '#wpFilterGlobal' ).change( toggleCustomMessages );
|
|
|
|
toggleCustomMessages();
|
|
|
|
|
|
|
|
cbEnabled = OO.ui.infuse( $( '#wpFilterEnabled' ) );
|
|
|
|
cbDeleted = OO.ui.infuse( $( '#wpFilterDeleted' ) );
|
|
|
|
OO.ui.infuse( $( '#wpFilterDeletedLabel' ) );
|
|
|
|
cbEnabled.on( 'change',
|
|
|
|
function () {
|
|
|
|
cbDeleted.setDisabled( cbEnabled.isSelected() );
|
|
|
|
if ( cbEnabled.isSelected() ) {
|
|
|
|
cbDeleted.setSelected( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2013-06-26 21:57:20 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
cbDeleted.on( 'change',
|
|
|
|
function () {
|
|
|
|
if ( cbDeleted.isSelected() ) {
|
|
|
|
cbEnabled.setSelected( false );
|
|
|
|
}
|
2018-05-02 16:59:55 +00:00
|
|
|
}
|
2018-03-23 09:13:41 +00:00
|
|
|
);
|
2018-05-02 16:59:55 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$( '#mw-abusefilter-edit-group-input select' ).change( onFilterGroupChange );
|
|
|
|
|
|
|
|
$( '#mw-abusefilter-export-link' ).click(
|
|
|
|
function ( e ) {
|
|
|
|
e.preventDefault();
|
|
|
|
$exportBox.toggle();
|
2018-05-02 16:59:55 +00:00
|
|
|
}
|
2018-03-23 09:13:41 +00:00
|
|
|
);
|
|
|
|
}
|
2018-05-02 16:59:55 +00:00
|
|
|
|
2012-10-26 00:23:17 +00:00
|
|
|
$( '#mw-abusefilter-syntaxcheck' ).click( doSyntaxCheck );
|
|
|
|
$( '#wpFilterBuilder' ).change( addText );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
|
|
|
} );
|
2018-03-23 09:13:41 +00:00
|
|
|
}( mediaWiki, jQuery, OO ) );
|