mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Implement a tree-caching abuse filter parser
This filter is fully functional. The old filter is still enabled by default for a transitional period in case the new one suddenly has issues. Change-Id: I4aea5f00c62420108030e60e79d5bf34e913e95d
This commit is contained in:
parent
959077f03f
commit
aa399da279
1014
AbuseFilter.parser.new.php
Normal file
1014
AbuseFilter.parser.new.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -613,6 +613,16 @@ class AbuseFilterParser {
|
|||
'funcSetVar',
|
||||
);
|
||||
|
||||
public static $mKeywords = array(
|
||||
'in' => 'keywordIn',
|
||||
'like' => 'keywordLike',
|
||||
'matches' => 'keywordLike',
|
||||
'contains' => 'keywordContains',
|
||||
'rlike' => 'keywordRegex',
|
||||
'irlike' => 'keywordRegexInsensitive',
|
||||
'regex' => 'keywordRegex'
|
||||
);
|
||||
|
||||
public static $funcCache = array();
|
||||
|
||||
/**
|
||||
|
@ -1124,17 +1134,10 @@ class AbuseFilterParser {
|
|||
protected function doLevelSpecialWords( &$result ) {
|
||||
$this->doLevelUnarys( $result );
|
||||
$keyword = strtolower( $this->mCur->value );
|
||||
$specwords = array(
|
||||
'in' => 'keywordIn',
|
||||
'like' => 'keywordLike',
|
||||
'matches' => 'keywordLike',
|
||||
'contains' => 'keywordContains',
|
||||
'rlike' => 'keywordRegex',
|
||||
'irlike' => 'keywordRegexInsensitive',
|
||||
'regex' => 'keywordRegex'
|
||||
);
|
||||
if ( $this->mCur->type == AFPToken::TKEYWORD && in_array( $keyword, array_keys( $specwords ) ) ) {
|
||||
$func = $specwords[$keyword];
|
||||
if ( $this->mCur->type == AFPToken::TKEYWORD
|
||||
&& in_array( $keyword, array_keys( self::$mKeywords ) )
|
||||
) {
|
||||
$func = self::$mKeywords[$keyword];
|
||||
$this->move();
|
||||
$r2 = new AFPData();
|
||||
$this->doLevelUnarys( $r2 );
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
"AutoloadClasses": {
|
||||
"AbuseFilter": "AbuseFilter.class.php",
|
||||
"AbuseFilterParser": "AbuseFilter.parser.php",
|
||||
"AbuseFilterCachingParser": "AbuseFilter.parser.new.php",
|
||||
"AbuseFilterTokenizer": "AbuseFilterTokenizer.php",
|
||||
"AbuseFilterHooks": "AbuseFilter.hooks.php",
|
||||
"AbuseFilterPreAuthenticationProvider": "AbuseFilterPreAuthenticationProvider.php",
|
||||
|
@ -101,6 +102,8 @@
|
|||
"AFPException": "AbuseFilter.parser.php",
|
||||
"AFPParserState": "AbuseFilter.parser.php",
|
||||
"AFPToken": "AbuseFilter.parser.php",
|
||||
"AFPTreeNode": "AbuseFilter.parser.new.php",
|
||||
"AFPTreeParser": "AbuseFilter.parser.new.php",
|
||||
"AFPUserVisibleException": "AbuseFilter.parser.php",
|
||||
"ApiQueryAbuseLog": "api/ApiQueryAbuseLog.php",
|
||||
"ApiQueryAbuseFilters": "api/ApiQueryAbuseFilters.php",
|
||||
|
|
1
tests/parserTests/almost-empty.r
Normal file
1
tests/parserTests/almost-empty.r
Normal file
|
@ -0,0 +1 @@
|
|||
NOT_MATCH
|
1
tests/parserTests/almost-empty.t
Normal file
1
tests/parserTests/almost-empty.t
Normal file
|
@ -0,0 +1 @@
|
|||
;;;;
|
1
tests/parserTests/empty.r
Normal file
1
tests/parserTests/empty.r
Normal file
|
@ -0,0 +1 @@
|
|||
NOT_MATCH
|
0
tests/parserTests/empty.t
Normal file
0
tests/parserTests/empty.t
Normal file
|
@ -37,6 +37,20 @@ class AbuseFilterParserTest extends MediaWikiTestCase {
|
|||
return $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return [AbuseFilterParser]
|
||||
*/
|
||||
static function getParsers() {
|
||||
static $parsers = null;
|
||||
if ( !$parsers ) {
|
||||
$parsers = [
|
||||
new AbuseFilterParser(),
|
||||
new AbuseFilterCachingParser()
|
||||
];
|
||||
}
|
||||
return $parsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider readTests
|
||||
*/
|
||||
|
@ -46,9 +60,10 @@ class AbuseFilterParserTest extends MediaWikiTestCase {
|
|||
$this->markTestSkipped( 'Parser test ' . $testName . ' requires the AntiSpoof extension' );
|
||||
}
|
||||
|
||||
$parser = self::getParser();
|
||||
$actual = $parser->parse( $rule );
|
||||
$this->assertEquals( $expected, $actual, 'Running parser test ' . $testName );
|
||||
foreach ( self::getParsers() as $parser ) {
|
||||
$actual = $parser->parse( $rule );
|
||||
$this->assertEquals( $expected, $actual, 'Running parser test ' . $testName );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue