diff --git a/modules/ext.abuseFilter.edit.js b/modules/ext.abuseFilter.edit.js index 4cd448cb0..b1532871b 100644 --- a/modules/ext.abuseFilter.edit.js +++ b/modules/ext.abuseFilter.edit.js @@ -79,8 +79,7 @@ * @param {Object} response Data returned from the AJAX request */ function processSyntaxResult( response ) { - var position, - data = response.abusefilterchecksyntax; + var data = response.abusefilterchecksyntax; if ( data.status === 'ok' ) { // Successful @@ -100,7 +99,7 @@ if ( useAce ) { filterEditor.focus(); // Convert index (used in textareas) in position {row, column} for ace - position = filterEditor.session.getDocument().indexToPosition( data.character ); + var position = filterEditor.session.getDocument().indexToPosition( data.character ); filterEditor.navigateTo( position.row, position.column ); filterEditor.scrollToRow( position.row ); } else { @@ -235,21 +234,23 @@ * @param {string} action The action the message refers to */ function previewMessage( action ) { - var api, - args = [ - '' + $( 'input[name=wpFilterDescription]' ).val() + '', - $( '#mw-abusefilter-edit-id' ).children().last().text() - ], - message = getCurrentMessage( action ), - // mw-abusefilter-warn-preview, mw-abusefilter-disallow-preview - $element = $( '#mw-abusefilter-' + action + '-preview' ), + // The following messages are generated here: + // * mw-abusefilter-warn-preview + // * mw-abusefilter-disallow-preview + var $element = $( '#mw-abusefilter-' + action + '-preview' ), previewButton = action === 'warn' ? toggleWarnPreviewButton : toggleDisallowPreviewButton; if ( $element.css( 'display' ) !== 'none' ) { $element.hide(); previewButton.setFlags( { destructive: false, progressive: true } ); } else { - api = new mw.Api(); + var api = new mw.Api(); + var args = [ + '' + $( 'input[name=wpFilterDescription]' ).val() + '', + $( '#mw-abusefilter-edit-id' ).children().last().text() + ]; + var message = getCurrentMessage( action ); + api.get( { action: 'query', meta: 'allmessages', @@ -297,13 +298,13 @@ * @param {jQuery.Event} e The event fired when the function is called */ function onFilterGroupChange() { - var $afWarnMessageExisting, $afDisallowMessageExisting, newVal; + var newVal; if ( !$( '#mw-abusefilter-action-checkbox-warn input' ).is( ':checked' ) && $( this ).val() in mw.config.get( 'wgAbuseFilterDefaultWarningMessage' ) ) { - $afWarnMessageExisting = $( '#mw-abusefilter-warn-message-existing select' ); + var $afWarnMessageExisting = $( '#mw-abusefilter-warn-message-existing select' ); newVal = mw.config.get( 'wgAbuseFilterDefaultWarningMessage' )[ $( this ).val() ]; if ( $afWarnMessageExisting.find( 'option[value=\'' + newVal + '\']' ).length ) { @@ -319,7 +320,7 @@ !$( '#mw-abusefilter-action-checkbox-disallow input' ).is( ':checked' ) && $( this ).val() in mw.config.get( 'wgAbuseFilterDefaultDisallowMessage' ) ) { - $afDisallowMessageExisting = $( '#mw-abusefilter-disallow-message-existing select' ); + var $afDisallowMessageExisting = $( '#mw-abusefilter-disallow-message-existing select' ); newVal = mw.config.get( 'wgAbuseFilterDefaultDisallowMessage' )[ $( this ).val() ]; if ( $afDisallowMessageExisting.find( 'option[value=\'' + newVal + '\']' ).length ) { @@ -370,11 +371,10 @@ * Warn if the user changed anything and tries to leave the window */ function setWarnOnLeave() { - var warnOnLeave, - $form = $( '#mw-abusefilter-editing-form' ), + var $form = $( '#mw-abusefilter-editing-form' ), origValues = $form.serialize(); - warnOnLeave = mw.confirmCloseWindow( { + var warnOnLeave = mw.confirmCloseWindow( { test: function () { return $form.serialize() !== origValues; }, @@ -396,10 +396,9 @@ // mw-abusefilter-throttle-parameters, mw-abusefilter-tag-parameters var $container = $( '#mw-abusefilter-' + action + '-parameters' ), // Character used to separate elements in the textarea. - separator = action === 'throttle' ? '\n' : ',', - selector, field, fieldOpts, hiddenField; + separator = action === 'throttle' ? '\n' : ','; - selector = new OO.ui.TagMultiselectWidget( { + var selector = new OO.ui.TagMultiselectWidget( { inputPosition: 'outline', allowArbitrary: true, allowEditTags: true, @@ -412,7 +411,7 @@ disabled: config.disabled } ); - fieldOpts = { + var fieldOpts = { label: $( $.parseHTML( config.label ) ), align: 'top' }; @@ -420,10 +419,10 @@ fieldOpts.help = new OO.ui.HtmlSnippet( config.help ); } - field = new OO.ui.FieldLayout( selector, fieldOpts ); + var field = new OO.ui.FieldLayout( selector, fieldOpts ); // mw-abusefilter-hidden-throttle-field, mw-abusefilter-hidden-tag-field - hiddenField = OO.ui.infuse( $( '#mw-abusefilter-hidden-' + action + '-field' ) ); + var hiddenField = OO.ui.infuse( $( '#mw-abusefilter-hidden-' + action + '-field' ) ); selector.on( 'change', function () { hiddenField.setValue( selector.getValue().join( separator ) ); } ); @@ -435,13 +434,11 @@ // On ready initialization $( function () { - var basePath, readOnly, - $exportBox = $( '#mw-abusefilter-export' ), + var $exportBox = $( '#mw-abusefilter-export' ), isFilterEditor = mw.config.get( 'isFilterEditor' ), tagConfig = mw.config.get( 'tagConfig' ), throttleConfig = mw.config.get( 'throttleConfig' ), - $switchEditorBtn = $( '#mw-abusefilter-switcheditor' ), - cbEnabled, cbDeleted; + $switchEditorBtn = $( '#mw-abusefilter-switcheditor' ); if ( isFilterEditor ) { // Configure the actual editing interface @@ -474,7 +471,7 @@ filterEditor.session.setMode( 'ace/mode/abusefilter' ); // Ace setup from codeEditor extension - basePath = mw.config.get( 'wgExtensionAssetsPath', '' ); + var 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 @@ -484,7 +481,7 @@ ace.config.set( 'basePath', basePath + '/CodeEditor/modules/ace' ); // Settings for Ace editor box - readOnly = mw.config.get( 'aceConfig' ).aceReadOnly; + var readOnly = mw.config.get( 'aceConfig' ).aceReadOnly; filterEditor.setTheme( 'ace/theme/textmate' ); filterEditor.setReadOnly( readOnly ); @@ -552,8 +549,8 @@ $( '#wpFilterGlobal' ).on( 'change', toggleCustomMessages ); toggleCustomMessages(); - cbEnabled = OO.ui.infuse( $( '#wpFilterEnabled' ) ); - cbDeleted = OO.ui.infuse( $( '#wpFilterDeleted' ) ); + var cbEnabled = OO.ui.infuse( $( '#wpFilterEnabled' ) ); + var cbDeleted = OO.ui.infuse( $( '#wpFilterDeleted' ) ); OO.ui.infuse( $( '#wpFilterDeletedLabel' ) ); cbEnabled.on( 'change', function () { diff --git a/modules/ext.abuseFilter.examine.js b/modules/ext.abuseFilter.examine.js index 20e71ef6d..683aafa20 100644 --- a/modules/ext.abuseFilter.examine.js +++ b/modules/ext.abuseFilter.examine.js @@ -17,9 +17,9 @@ * @param {Object} data The response of the API request */ function examinerTestProcess( data ) { - var msg, exClass; $.removeSpinner( 'filter-check' ); + var msg, exClass; if ( data.abusefiltercheckmatch.result ) { exClass = 'mw-abusefilter-examine-match'; msg = 'abusefilter-examine-match'; @@ -42,9 +42,9 @@ * @param {Object} details Details about the error */ function examinerTestProcessFailure( error, details ) { - var msg; $.removeSpinner( 'filter-check' ); + var msg; if ( error === 'badsyntax' ) { $syntaxResult.attr( 'class', 'mw-abusefilter-syntaxresult-error' diff --git a/modules/mode-abusefilter.js b/modules/mode-abusefilter.js index 6f5745fe1..7e735d813 100644 --- a/modules/mode-abusefilter.js +++ b/modules/mode-abusefilter.js @@ -129,13 +129,11 @@ ace.define( 'ace/mode/abusefilter', [ 'require', 'exports', 'module', 'ace/lib/o }; this.createWorker = function ( session ) { - var extPath = mw.config.get( 'wgExtensionAssetsPath' ), - worker, - apiPath; + var extPath = mw.config.get( 'wgExtensionAssetsPath' ); ace.config.set( 'workerPath', extPath + '/AbuseFilter/modules' ); - worker = new WorkerClient( [ 'ace' ], 'ace/mode/abusefilter_worker', 'AbuseFilterWorker' ); + var worker = new WorkerClient( [ 'ace' ], 'ace/mode/abusefilter_worker', 'AbuseFilterWorker' ); - apiPath = mw.config.get( 'wgServer' ) + new mw.Api().defaults.ajax.url; + var apiPath = mw.config.get( 'wgServer' ) + new mw.Api().defaults.ajax.url; if ( apiPath.slice( 0, 2 ) === '//' ) { apiPath = window.location.protocol + apiPath; } diff --git a/modules/worker-abusefilter.js b/modules/worker-abusefilter.js index 7ea2459b5..6897d7258 100644 --- a/modules/worker-abusefilter.js +++ b/modules/worker-abusefilter.js @@ -1437,17 +1437,16 @@ ace.define( 'ace/mode/abusefilter_worker', [ 'require', 'exports', 'module', 'ac 'use strict'; var oop = require( 'ace/lib/oop' ), - Mirror = require( 'ace/worker/mirror' ).Mirror, - AbuseFilterWorker, parseCode; + Mirror = require( 'ace/worker/mirror' ).Mirror; - AbuseFilterWorker = exports.AbuseFilterWorker = function ( sender ) { + var AbuseFilterWorker = exports.AbuseFilterWorker = function ( sender ) { Mirror.call( this, sender ); // How many seconds after the change to wait before running the validation this.setTimeout( 1000 ); }; oop.inherits( AbuseFilterWorker, Mirror ); - parseCode = function ( code ) { + var parseCode = function ( code ) { var xhr, data; if ( !self.mwapipath ) { @@ -1479,17 +1478,16 @@ ace.define( 'ace/mode/abusefilter_worker', [ 'require', 'exports', 'module', 'ac ( function () { this.onUpdate = function () { - var results = parseCode( this.doc.getValue() ), - errors = [], - warning, - position; + var results = parseCode( this.doc.getValue() ); if ( results === true ) { // API error or something similar. this.sender.emit( 'annotate', [] ); return; } - for ( warning in results.warnings || {} ) { + var position; + var errors = []; + for ( var warning in results.warnings || {} ) { position = this.doc.indexToPosition( results.warnings[ warning ].character ); errors.push( { row: position.row,