mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 15:30:42 +00:00
Merge "Improve Ace syntax highlight"
This commit is contained in:
commit
81a4fdc964
|
@ -2104,17 +2104,26 @@ class AbuseFilter {
|
|||
public static function getAceConfig( $canEdit ) {
|
||||
$values = self::getBuilderValues();
|
||||
$deprecatedVars = self::getDeprecatedVariables();
|
||||
$builderVariables = implode( '|',
|
||||
array_keys( array_merge( $values['vars'], $deprecatedVars ) ) );
|
||||
|
||||
$builderVariables = implode( '|', array_keys( $values['vars'] ) );
|
||||
$builderFunctions = implode( '|', array_keys( AbuseFilterParser::$mFunctions ) );
|
||||
// AbuseFilterTokenizer::$keywords also includes constants (true, false and null),
|
||||
// but Ace redefines these constants afterwards so this will not be an issue
|
||||
$builderKeywords = implode( '|', AbuseFilterTokenizer::$keywords );
|
||||
// Extract operators from tokenizer like we do in AbuseFilterParserTest
|
||||
$operators = implode( '|', array_map( function ( $op ) {
|
||||
return preg_quote( $op, '/' );
|
||||
}, AbuseFilterTokenizer::$operators ) );
|
||||
$deprecatedVariables = implode( '|', array_keys( $deprecatedVars ) );
|
||||
$disabledVariables = implode( '|', array_keys( self::$disabledVars ) );
|
||||
|
||||
return [
|
||||
'variables' => $builderVariables,
|
||||
'functions' => $builderFunctions,
|
||||
'keywords' => $builderKeywords,
|
||||
'operators' => $operators,
|
||||
'deprecated' => $deprecatedVariables,
|
||||
'disabled' => $disabledVariables,
|
||||
'aceReadOnly' => !$canEdit
|
||||
];
|
||||
}
|
||||
|
|
|
@ -152,3 +152,14 @@ ul li.mw-abusefilter-changeslist-match {
|
|||
.mw-abusefilter-history-buttons {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Ace highlight customisation */
|
||||
|
||||
span.ace_invalid.ace_deprecated {
|
||||
color: #fe6767;
|
||||
background-color: initial;
|
||||
}
|
||||
|
||||
span.ace_support.ace_function {
|
||||
color: #495dd0;
|
||||
}
|
||||
|
|
|
@ -6,18 +6,16 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
|
|||
TextHighlightRules = require( './text_highlight_rules' ).TextHighlightRules,
|
||||
AFHighlightRules = function () {
|
||||
|
||||
var keywords = ( mw.config.get( 'aceConfig' ).keywords ),
|
||||
var cfg = mw.config.get( 'aceConfig' ),
|
||||
constants = ( 'true|false|null' ),
|
||||
functions = ( mw.config.get( 'aceConfig' ).functions ),
|
||||
variables = ( mw.config.get( 'aceConfig' ).variables ),
|
||||
deprecated = ( '' ), // Template for deprecated vars, already registered within ace settings.
|
||||
keywordMapper = this.createKeywordMapper(
|
||||
{
|
||||
keyword: keywords,
|
||||
'support.function': functions,
|
||||
keyword: cfg.keywords,
|
||||
'support.function': cfg.functions,
|
||||
'constant.language': constants,
|
||||
'variable.language': variables,
|
||||
'keyword.deprecated': deprecated
|
||||
'variable.language': cfg.variables,
|
||||
'invalid.deprecated': cfg.deprecated,
|
||||
'invalid.illegal': cfg.disabled
|
||||
},
|
||||
'identifier'
|
||||
),
|
||||
|
@ -27,7 +25,9 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
|
|||
fraction = '(?:\\.\\d+)',
|
||||
intPart = '(?:\\d+)',
|
||||
pointFloat = '(?:(?:' + intPart + '?' + fraction + ')|(?:' + intPart + '\\.))',
|
||||
floatNumber = '(?:' + pointFloat + ')';
|
||||
floatNumber = '(?:' + pointFloat + ')',
|
||||
singleQuoteString = '\'(?:[^\\\\]|\\\\.)*?\'',
|
||||
doubleQuoteString = '"(?:[^\\\\]|\\\\.)*?"';
|
||||
|
||||
this.$rules = {
|
||||
start: [ {
|
||||
|
@ -35,11 +35,11 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
|
|||
regex: '\\/\\*',
|
||||
next: 'comment'
|
||||
}, {
|
||||
token: 'string', // " string
|
||||
regex: '"(?:[^\\\\]|\\\\.)*?"'
|
||||
token: 'string',
|
||||
regex: doubleQuoteString
|
||||
}, {
|
||||
token: 'string', // ' string
|
||||
regex: '\'(?:[^\\\\]|\\\\.)*?\''
|
||||
token: 'string',
|
||||
regex: singleQuoteString
|
||||
}, {
|
||||
token: 'constant.numeric', // float
|
||||
regex: floatNumber
|
||||
|
@ -48,10 +48,10 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
|
|||
regex: integer + '\\b'
|
||||
}, {
|
||||
token: keywordMapper,
|
||||
regex: '[a-zA-Z_$][a-zA-Z0-9_$]*\\b'
|
||||
regex: '[a-zA-Z_][a-zA-Z0-9_]*\\b'
|
||||
}, {
|
||||
token: 'keyword.operator',
|
||||
regex: '\\+|\\-|\\*\\*|\\*|\\/|%|\\^|&|\\||<|>|<=|=>|==|!=|===|!==|:=|=|!'
|
||||
regex: cfg.operators
|
||||
}, {
|
||||
token: 'paren.lparen',
|
||||
regex: '[\\[\\(]'
|
||||
|
|
Loading…
Reference in a new issue