2019-07-31 13:52:09 +00:00
|
|
|
/* global ace */
|
2018-08-22 09:11:44 +00:00
|
|
|
ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'module', 'ace/lib/oop', 'ace/mode/text_highlight_rules' ], function ( require, exports ) {
|
2018-03-30 06:55:03 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var oop = require( 'ace/lib/oop' ),
|
|
|
|
TextHighlightRules = require( './text_highlight_rules' ).TextHighlightRules,
|
|
|
|
AFHighlightRules = function () {
|
2018-06-27 18:05:52 +00:00
|
|
|
var cfg = mw.config.get( 'aceConfig' ),
|
2018-03-30 06:55:03 +00:00
|
|
|
constants = ( 'true|false|null' ),
|
2019-01-02 10:30:38 +00:00
|
|
|
keywords = this.createKeywordMapper(
|
2018-03-30 06:55:03 +00:00
|
|
|
{
|
2018-06-27 18:05:52 +00:00
|
|
|
keyword: cfg.keywords,
|
|
|
|
'support.function': cfg.functions,
|
2019-01-02 10:30:38 +00:00
|
|
|
'constant.language': constants
|
|
|
|
},
|
2019-03-29 09:44:02 +00:00
|
|
|
// Null as default used in isKeywordOrVariable
|
|
|
|
null
|
2019-01-02 10:30:38 +00:00
|
|
|
),
|
|
|
|
variables = this.createKeywordMapper(
|
|
|
|
{
|
2018-06-27 18:05:52 +00:00
|
|
|
'variable.language': cfg.variables,
|
|
|
|
'invalid.deprecated': cfg.deprecated,
|
|
|
|
'invalid.illegal': cfg.disabled
|
2018-03-30 06:55:03 +00:00
|
|
|
},
|
2019-01-02 10:30:38 +00:00
|
|
|
'identifier',
|
|
|
|
true
|
2018-03-30 06:55:03 +00:00
|
|
|
),
|
2019-03-29 09:44:02 +00:00
|
|
|
isKeywordOrVariable = function ( value ) {
|
|
|
|
if ( keywords( value ) !== null ) {
|
|
|
|
return keywords( value );
|
|
|
|
} else {
|
|
|
|
return variables( value );
|
|
|
|
}
|
|
|
|
},
|
2018-08-23 10:23:16 +00:00
|
|
|
integer = '(?:(?:[1-9]\\d*)|(?:0))',
|
2018-03-30 06:55:03 +00:00
|
|
|
fraction = '(?:\\.\\d+)',
|
|
|
|
intPart = '(?:\\d+)',
|
|
|
|
pointFloat = '(?:(?:' + intPart + '?' + fraction + ')|(?:' + intPart + '\\.))',
|
2021-10-02 15:15:15 +00:00
|
|
|
floatNumber = '(?:' + pointFloat + ')';
|
2018-03-30 06:55:03 +00:00
|
|
|
|
|
|
|
this.$rules = {
|
2018-08-22 09:11:44 +00:00
|
|
|
start: [ {
|
2018-03-30 06:55:03 +00:00
|
|
|
token: 'comment',
|
|
|
|
regex: '\\/\\*',
|
|
|
|
next: 'comment'
|
|
|
|
}, {
|
2018-06-27 18:05:52 +00:00
|
|
|
token: 'string',
|
2021-10-02 15:15:15 +00:00
|
|
|
regex: '"',
|
|
|
|
next: 'doublequotestring'
|
2018-03-30 06:55:03 +00:00
|
|
|
}, {
|
2018-06-27 18:05:52 +00:00
|
|
|
token: 'string',
|
2021-10-02 15:15:15 +00:00
|
|
|
regex: "'",
|
|
|
|
next: 'singlequotestring'
|
2018-03-30 06:55:03 +00:00
|
|
|
}, {
|
2018-08-23 10:23:16 +00:00
|
|
|
token: 'constant.numeric',
|
2018-03-30 06:55:03 +00:00
|
|
|
regex: floatNumber
|
|
|
|
}, {
|
2018-08-23 10:23:16 +00:00
|
|
|
token: 'constant.numeric',
|
2018-03-30 06:55:03 +00:00
|
|
|
regex: integer + '\\b'
|
|
|
|
}, {
|
2019-03-29 09:44:02 +00:00
|
|
|
token: isKeywordOrVariable,
|
2018-06-27 18:05:52 +00:00
|
|
|
regex: '[a-zA-Z_][a-zA-Z0-9_]*\\b'
|
2018-03-30 06:55:03 +00:00
|
|
|
}, {
|
|
|
|
token: 'keyword.operator',
|
2018-06-27 18:05:52 +00:00
|
|
|
regex: cfg.operators
|
2018-03-30 06:55:03 +00:00
|
|
|
}, {
|
|
|
|
token: 'paren.lparen',
|
|
|
|
regex: '[\\[\\(]'
|
|
|
|
}, {
|
|
|
|
token: 'paren.rparen',
|
|
|
|
regex: '[\\]\\)]'
|
|
|
|
}, {
|
|
|
|
token: 'text',
|
|
|
|
regex: '\\s+|\\w+'
|
|
|
|
} ],
|
2021-10-02 15:15:15 +00:00
|
|
|
comment: [
|
|
|
|
{ token: 'comment', regex: '\\*\\/', next: 'start' },
|
|
|
|
{ defaultToken: 'comment' }
|
|
|
|
],
|
|
|
|
doublequotestring: [
|
|
|
|
{ token: 'constant.language.escape', regex: /\\["\\]/ },
|
|
|
|
{ token: 'string', regex: '"', next: 'start' },
|
|
|
|
{ defaultToken: 'string' }
|
|
|
|
],
|
|
|
|
singlequotestring: [
|
|
|
|
{ token: 'constant.language.escape', regex: /\\['\\]/ },
|
|
|
|
{ token: 'string', regex: "'", next: 'start' },
|
|
|
|
{ defaultToken: 'string' }
|
|
|
|
]
|
2018-03-30 06:55:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.normalizeRules();
|
|
|
|
};
|
|
|
|
|
|
|
|
oop.inherits( AFHighlightRules, TextHighlightRules );
|
|
|
|
|
|
|
|
exports.AFHighlightRules = AFHighlightRules;
|
|
|
|
} );
|
|
|
|
|
2020-12-08 17:10:00 +00:00
|
|
|
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 ) {
|
2018-03-30 06:55:03 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var oop = require( 'ace/lib/oop' ),
|
|
|
|
TextMode = require( './text' ).Mode,
|
2020-12-08 17:10:00 +00:00
|
|
|
WorkerClient = require( 'ace/worker/worker_client' ).WorkerClient,
|
2018-03-30 06:55:03 +00:00
|
|
|
AFHighlightRules = require( './abusefilter_highlight_rules' ).AFHighlightRules,
|
|
|
|
MatchingBraceOutdent = require( './matching_brace_outdent' ).MatchingBraceOutdent,
|
|
|
|
Mode = function () {
|
|
|
|
this.HighlightRules = AFHighlightRules;
|
|
|
|
this.$behaviour = this.$defaultBehaviour;
|
|
|
|
this.$outdent = new MatchingBraceOutdent();
|
|
|
|
};
|
|
|
|
oop.inherits( Mode, TextMode );
|
|
|
|
|
|
|
|
( function () {
|
|
|
|
this.blockComment = {
|
|
|
|
start: '/*',
|
|
|
|
end: '*/'
|
|
|
|
};
|
2018-08-22 09:11:44 +00:00
|
|
|
this.getNextLineIndent = function ( state, line ) {
|
2018-03-30 06:55:03 +00:00
|
|
|
var indent = this.$getIndent( line );
|
|
|
|
return indent;
|
|
|
|
};
|
|
|
|
this.checkOutdent = function ( state, line, input ) {
|
|
|
|
return this.$outdent.checkOutdent( line, input );
|
|
|
|
};
|
|
|
|
this.autoOutdent = function ( state, doc, row ) {
|
|
|
|
this.$outdent.autoOutdent( doc, row );
|
|
|
|
};
|
|
|
|
|
2020-12-08 17:10:00 +00:00
|
|
|
this.createWorker = function ( session ) {
|
2023-11-10 18:27:55 +00:00
|
|
|
var extPath = mw.config.get( 'wgExtensionAssetsPath' );
|
2020-12-08 17:10:00 +00:00
|
|
|
ace.config.set( 'workerPath', extPath + '/AbuseFilter/modules' );
|
2023-11-10 18:27:55 +00:00
|
|
|
var worker = new WorkerClient( [ 'ace' ], 'ace/mode/abusefilter_worker', 'AbuseFilterWorker' );
|
2020-12-08 17:10:00 +00:00
|
|
|
|
2023-11-10 18:27:55 +00:00
|
|
|
var apiPath = mw.config.get( 'wgServer' ) + new mw.Api().defaults.ajax.url;
|
2021-12-21 21:43:52 +00:00
|
|
|
if ( apiPath.slice( 0, 2 ) === '//' ) {
|
2021-01-11 12:33:11 +00:00
|
|
|
apiPath = window.location.protocol + apiPath;
|
|
|
|
}
|
|
|
|
worker.$worker.postMessage( { apipath: apiPath } );
|
2020-12-08 17:10:00 +00:00
|
|
|
|
|
|
|
worker.attachToDocument( session.getDocument() );
|
|
|
|
|
|
|
|
worker.on( 'annotate', function ( results ) {
|
|
|
|
session.setAnnotations( results.data );
|
|
|
|
} );
|
|
|
|
|
|
|
|
worker.on( 'terminate', function () {
|
|
|
|
session.clearAnnotations();
|
|
|
|
} );
|
|
|
|
|
|
|
|
return worker;
|
|
|
|
};
|
2018-03-30 06:55:03 +00:00
|
|
|
} )
|
|
|
|
.call( Mode.prototype );
|
|
|
|
|
|
|
|
exports.Mode = Mode;
|
|
|
|
} );
|