mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Run real-time validation of rules with an Ace worker
The worker itself is essentially a wrapper around the
abusefilterchecksyntax API.
NOTE: As written in code comments, basically the whole
worker-abusefilter.js script consists of boilerplate code. You can
verify this by diffing this file and 6cb8a9cae1/modules/ace/worker-json.js
This means that there are only ~60 lines of code to review in that file.
Bug: T187686
Change-Id: I8950fcd5917ba226dda80b47b2bb713e685fad36
This commit is contained in:
parent
e1a7acf55f
commit
2a3b636a45
|
@ -479,7 +479,6 @@
|
|||
readOnly = mw.config.get( 'aceConfig' ).aceReadOnly;
|
||||
|
||||
filterEditor.setTheme( 'ace/theme/textmate' );
|
||||
filterEditor.session.setOption( 'useWorker', false );
|
||||
filterEditor.setReadOnly( readOnly );
|
||||
filterEditor.$blockScrolling = Infinity;
|
||||
|
||||
|
|
|
@ -90,11 +90,12 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
|
|||
exports.AFHighlightRules = AFHighlightRules;
|
||||
} );
|
||||
|
||||
ace.define( 'ace/mode/abusefilter', [ 'require', 'exports', 'module', 'ace/lib/oop', 'ace/mode/text', 'ace/mode/abusefilter_highlight_rules' ], function ( require, exports ) {
|
||||
ace.define( 'ace/mode/abusefilter', [ 'require', 'exports', 'module', 'ace/lib/oop', 'ace/mode/text', 'ace/mode/abusefilter_highlight_rules', 'ace/worker/worker_client' ], function ( require, exports ) {
|
||||
'use strict';
|
||||
|
||||
var oop = require( 'ace/lib/oop' ),
|
||||
TextMode = require( './text' ).Mode,
|
||||
WorkerClient = require( 'ace/worker/worker_client' ).WorkerClient,
|
||||
AFHighlightRules = require( './abusefilter_highlight_rules' ).AFHighlightRules,
|
||||
MatchingBraceOutdent = require( './matching_brace_outdent' ).MatchingBraceOutdent,
|
||||
Mode = function () {
|
||||
|
@ -120,7 +121,28 @@ ace.define( 'ace/mode/abusefilter', [ 'require', 'exports', 'module', 'ace/lib/o
|
|||
this.$outdent.autoOutdent( doc, row );
|
||||
};
|
||||
|
||||
this.$id = 'ace/mode/abusefilter';
|
||||
this.createWorker = function ( session ) {
|
||||
var extPath = mw.config.get( 'wgExtensionAssetsPath' ),
|
||||
worker;
|
||||
ace.config.set( 'workerPath', extPath + '/AbuseFilter/modules' );
|
||||
worker = new WorkerClient( [ 'ace' ], 'ace/mode/abusefilter_worker', 'AbuseFilterWorker' );
|
||||
|
||||
worker.$worker.postMessage( {
|
||||
apipath: mw.config.get( 'wgServer' ) + new mw.Api().defaults.ajax.url
|
||||
} );
|
||||
|
||||
worker.attachToDocument( session.getDocument() );
|
||||
|
||||
worker.on( 'annotate', function ( results ) {
|
||||
session.setAnnotations( results.data );
|
||||
} );
|
||||
|
||||
worker.on( 'terminate', function () {
|
||||
session.clearAnnotations();
|
||||
} );
|
||||
|
||||
return worker;
|
||||
};
|
||||
} )
|
||||
.call( Mode.prototype );
|
||||
|
||||
|
|
1502
modules/worker-abusefilter.js
Normal file
1502
modules/worker-abusefilter.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue