Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ConfigHelper | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
getValidationExclusionFile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTranslateAuthorExclusionList | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDisabledTargetLanguages | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isAuthorExcluded | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\Utilities; |
5 | |
6 | /** |
7 | * A helper class added to work with configuration values of the Translate Extension |
8 | * |
9 | * Also used temporarily to simplify deprecation of old configuration variables. New |
10 | * variable names, if set, are given preference over the old ones. |
11 | * See: https://phabricator.wikimedia.org/T277965 |
12 | * |
13 | * @author Abijeet Patro. |
14 | * @license GPL-2.0-or-later |
15 | * @since 2021.06 |
16 | */ |
17 | class ConfigHelper { |
18 | /** @return bool|string */ |
19 | public function getValidationExclusionFile() { |
20 | global $wgTranslateValidationExclusionFile; |
21 | return $wgTranslateValidationExclusionFile; |
22 | } |
23 | |
24 | public function getTranslateAuthorExclusionList(): array { |
25 | global $wgTranslateAuthorExclusionList; |
26 | return $wgTranslateAuthorExclusionList; |
27 | } |
28 | |
29 | public function getDisabledTargetLanguages(): array { |
30 | global $wgTranslateDisabledTargetLanguages; |
31 | return $wgTranslateDisabledTargetLanguages; |
32 | } |
33 | |
34 | public function isAuthorExcluded( string $groupId, string $languageCode, string $username ): bool { |
35 | $hash = "$groupId;$languageCode;$username"; |
36 | $authorExclusionList = $this->getTranslateAuthorExclusionList(); |
37 | $excluded = false; |
38 | |
39 | foreach ( $authorExclusionList as $rule ) { |
40 | [ $type, $regex ] = $rule; |
41 | |
42 | if ( preg_match( $regex, $hash ) ) { |
43 | if ( $type === 'include' ) { |
44 | return false; |
45 | } else { |
46 | $excluded = true; |
47 | } |
48 | } |
49 | } |
50 | |
51 | return $excluded; |
52 | } |
53 | } |