Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| AbuseFilterProtectedVariablesLookup | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAllProtectedVariables | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\AbuseFilter\Variables; |
| 4 | |
| 5 | use MediaWiki\Config\ServiceOptions; |
| 6 | use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner; |
| 7 | |
| 8 | /** |
| 9 | * This service is used to generate the list of variables which are protected variables. |
| 10 | */ |
| 11 | class AbuseFilterProtectedVariablesLookup { |
| 12 | public const SERVICE_NAME = 'AbuseFilterProtectedVariablesLookup'; |
| 13 | |
| 14 | public const CONSTRUCTOR_OPTIONS = [ |
| 15 | 'AbuseFilterProtectedVariables', |
| 16 | ]; |
| 17 | |
| 18 | public function __construct( |
| 19 | private readonly ServiceOptions $options, |
| 20 | private readonly AbuseFilterHookRunner $hookRunner |
| 21 | ) { |
| 22 | $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Returns an array of all variables which are considered protected variables, and therefore can only be used |
| 27 | * in protected filters. |
| 28 | * |
| 29 | * @return string[] |
| 30 | */ |
| 31 | public function getAllProtectedVariables(): array { |
| 32 | $protectedVariables = []; |
| 33 | $this->hookRunner->onAbuseFilterCustomProtectedVariables( $protectedVariables ); |
| 34 | return array_unique( array_merge( |
| 35 | $protectedVariables, $this->options->get( 'AbuseFilterProtectedVariables' ) |
| 36 | ) ); |
| 37 | } |
| 38 | } |