diff options
Diffstat (limited to 'MLEB/Translate/src/Utilities/ConfigHelper.php')
-rw-r--r-- | MLEB/Translate/src/Utilities/ConfigHelper.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/MLEB/Translate/src/Utilities/ConfigHelper.php b/MLEB/Translate/src/Utilities/ConfigHelper.php new file mode 100644 index 00000000..e028d38c --- /dev/null +++ b/MLEB/Translate/src/Utilities/ConfigHelper.php @@ -0,0 +1,53 @@ +<?php +declare( strict_types = 1 ); + +namespace MediaWiki\Extension\Translate\Utilities; + +/** + * A helper class added to work with configuration values of the Translate Extension + * + * Also used temporarily to simplify deprecation of old configuration variables. New + * variable names, if set, are given preference over the old ones. + * See: https://phabricator.wikimedia.org/T277965 + * + * @author Abijeet Patro. + * @license GPL-2.0-or-later + * @since 2021.06 + */ +class ConfigHelper { + /** @return bool|string */ + public function getValidationExclusionFile() { + global $wgTranslateValidationExclusionFile; + return $wgTranslateValidationExclusionFile; + } + + public function getTranslateAuthorExclusionList(): array { + global $wgTranslateAuthorExclusionList; + return $wgTranslateAuthorExclusionList; + } + + public function getDisabledTargetLanguages(): array { + global $wgTranslateDisabledTargetLanguages; + return $wgTranslateDisabledTargetLanguages; + } + + public function isAuthorExcluded( string $groupId, string $languageCode, string $username ): bool { + $hash = "$groupId;$languageCode;$username"; + $authorExclusionList = $this->getTranslateAuthorExclusionList(); + $excluded = false; + + foreach ( $authorExclusionList as $rule ) { + list( $type, $regex ) = $rule; + + if ( preg_match( $regex, $hash ) ) { + if ( $type === 'include' ) { + return false; + } else { + $excluded = true; + } + } + } + + return $excluded; + } +} |