diff options
Diffstat (limited to 'MLEB/Translate/src/Validation/ValidationRunner.php')
-rw-r--r-- | MLEB/Translate/src/Validation/ValidationRunner.php | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/MLEB/Translate/src/Validation/ValidationRunner.php b/MLEB/Translate/src/Validation/ValidationRunner.php index b5b345bc..5e6c41da 100644 --- a/MLEB/Translate/src/Validation/ValidationRunner.php +++ b/MLEB/Translate/src/Validation/ValidationRunner.php @@ -14,6 +14,7 @@ namespace MediaWiki\Extension\Translate\Validation; use Exception; use FormatJson; use InvalidArgumentException; +use MediaWiki\Extension\Translate\Services; use MediaWiki\Extension\Translate\TranslatorInterface\Insertable\InsertablesSuggester; use PHPVariableLoader; use RuntimeException; @@ -105,7 +106,8 @@ class ValidationRunner { 'instance' => $validator, 'insertable' => $isInsertable, 'enforce' => $validatorConfig['enforce'] ?? false, - 'keymatch' => $validatorConfig['keymatch'] ?? false, + 'include' => $validatorConfig['keymatch'] ?? $validatorConfig['include'] ?? false, + 'exclude' => $validatorConfig['exclude'] ?? false ]; } @@ -116,7 +118,7 @@ class ValidationRunner { */ public function getValidators(): array { return array_map( - function ( $validator ) { + static function ( $validator ) { return $validator['instance']; }, $this->validators @@ -202,19 +204,25 @@ class ValidationRunner { /** @internal Should only be used by tests and inside this class. */ public static function reloadIgnorePatterns(): void { - global $wgTranslateCheckBlacklist; + $validationExclusionFile = Services::getInstance()->getConfigHelper()->getValidationExclusionFile(); - if ( $wgTranslateCheckBlacklist === false ) { + if ( $validationExclusionFile === false ) { self::$ignorePatterns = []; return; } $list = PHPVariableLoader::loadVariableFromPHPFile( - $wgTranslateCheckBlacklist, - 'checkBlacklist' + $validationExclusionFile, + 'validationExclusionList' ); $keys = [ 'group', 'check', 'subcheck', 'code', 'message' ]; + if ( $list && !is_array( $list ) ) { + throw new InvalidArgumentException( + "validationExclusionList defined in $validationExclusionFile must be an array" + ); + } + foreach ( $list as $key => $pattern ) { foreach ( $keys as $checkKey ) { if ( !isset( $pattern[$checkKey] ) ) { @@ -287,8 +295,7 @@ class ValidationRunner { /** * Check if key matches validator's key patterns. - * - * Only relevant if the 'keymatch' option is specified in the validator. + * Only relevant if the 'include' or 'exclude' option is specified in the validator. * * @param string $key * @param string[] $keyMatches @@ -352,8 +359,13 @@ class ValidationRunner { } try { - $keyMatches = $validatorData['keymatch']; - if ( $keyMatches !== false && !$this->doesKeyMatch( $message->key(), $keyMatches ) ) { + $includedKeys = $validatorData['include']; + if ( $includedKeys !== false && !$this->doesKeyMatch( $message->key(), $includedKeys ) ) { + return; + } + + $excludedKeys = $validatorData['exclude']; + if ( $excludedKeys !== false && $this->doesKeyMatch( $message->key(), $excludedKeys ) ) { return; } @@ -371,5 +383,3 @@ class ValidationRunner { } } } - -class_alias( ValidationRunner::class, '\MediaWiki\Extensions\Translate\ValidationRunner' ); |