Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
ConfigHelper.php
1<?php
2declare( strict_types = 1 );
3
5
7
21 public function getValidationExclusionFile() {
22 global $wgTranslateValidationExclusionFile;
23 return $wgTranslateValidationExclusionFile;
24 }
25
26 public function getTranslateAuthorExclusionList(): array {
27 global $wgTranslateAuthorExclusionList;
28 return $wgTranslateAuthorExclusionList;
29 }
30
31 public function getDisabledTargetLanguages(): array {
32 global $wgTranslateDisabledTargetLanguages;
33 return $wgTranslateDisabledTargetLanguages;
34 }
35
43 public function isTargetLanguageDisabled(
44 MessageGroup $group,
45 string $languageCode,
46 ?string &$reason = null
47 ): bool {
48 $globalDisabledReason = null;
49 $groupId = $group->getId();
50 $checks = [
51 $groupId,
52 strtok( $groupId, '-' ),
53 '*'
54 ];
55
56 $disabledLanguages = $this->getDisabledTargetLanguages();
57 foreach ( $checks as $check ) {
58 if ( isset( $disabledLanguages[$check][$languageCode] ) ) {
59 $globalDisabledReason = $disabledLanguages[$check][$languageCode];
60 break;
61 }
62 }
63
64 $groupLanguages = $group->getTranslatableLanguages();
65
66 $isLanguageDisabled = $groupLanguages === MessageGroup::DEFAULT_LANGUAGES
67 ? $globalDisabledReason !== null
68 : !array_key_exists( $languageCode, $groupLanguages );
69
70 // Only set the reason if the language is actually disabled
71 if ( $isLanguageDisabled ) {
72 $reason = $globalDisabledReason;
73 }
74
75 return $isLanguageDisabled;
76 }
77
78 public function isAuthorExcluded( string $groupId, string $languageCode, string $username ): bool {
79 $hash = "$groupId;$languageCode;$username";
80 $authorExclusionList = $this->getTranslateAuthorExclusionList();
81 $excluded = false;
82
83 foreach ( $authorExclusionList as $rule ) {
84 [ $type, $regex ] = $rule;
85
86 if ( preg_match( $regex, $hash ) ) {
87 if ( $type === 'include' ) {
88 return false;
89 } else {
90 $excluded = true;
91 }
92 }
93 }
94
95 return $excluded;
96 }
97}
A helper class added to work with configuration values of the Translate Extension.
isTargetLanguageDisabled(MessageGroup $group, string $languageCode, ?string &$reason=null)
Helper to validate MessageGroup::getTranslatableLanguage against site configuration.
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:29
Interface for message groups.
getTranslatableLanguages()
Get all the translatable languages for a group, considering the inclusion and exclusion list.
getId()
Returns the unique identifier for this group.