Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7494230
ConfigHelper.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ConfigHelper.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\Utilities
;
use
MessageGroup
;
/**
* 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
;
}
/**
* Helper to validate MessageGroup::getTranslatableLanguage against site configuration.
* @param MessageGroup $group The message group to check.
* @param string $languageCode Target language code.
* @param string|null &$reason Store the reason why the language is disabled, if applicable.
* @return bool True if the target language is disabled, false otherwise.
*/
public
function
isTargetLanguageDisabled
(
MessageGroup
$group
,
string
$languageCode
,
?
string
&
$reason
=
null
):
bool
{
$globalDisabledReason
=
null
;
$groupId
=
$group
->
getId
();
$checks
=
[
$groupId
,
strtok
(
$groupId
,
'-'
),
'*'
];
$disabledLanguages
=
$this
->
getDisabledTargetLanguages
();
foreach
(
$checks
as
$check
)
{
if
(
isset
(
$disabledLanguages
[
$check
][
$languageCode
]
)
)
{
$globalDisabledReason
=
$disabledLanguages
[
$check
][
$languageCode
];
break
;
}
}
$groupLanguages
=
$group
->
getTranslatableLanguages
();
$isLanguageDisabled
=
$groupLanguages
===
MessageGroup
::
DEFAULT_LANGUAGES
?
$globalDisabledReason
!==
null
:
!
array_key_exists
(
$languageCode
,
$groupLanguages
);
// Only set the reason if the language is actually disabled
if
(
$isLanguageDisabled
)
{
$reason
=
$globalDisabledReason
;
}
return
$isLanguageDisabled
;
}
public
function
isAuthorExcluded
(
string
$groupId
,
string
$languageCode
,
string
$username
):
bool
{
$hash
=
"$groupId;$languageCode;$username"
;
$authorExclusionList
=
$this
->
getTranslateAuthorExclusionList
();
$excluded
=
false
;
foreach
(
$authorExclusionList
as
$rule
)
{
[
$type
,
$regex
]
=
$rule
;
if
(
preg_match
(
$regex
,
$hash
)
)
{
if
(
$type
===
'include'
)
{
return
false
;
}
else
{
$excluded
=
true
;
}
}
}
return
$excluded
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 21:13 (1 w, 3 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
23/eb/04be695879e5107417fe463c1e80
Default Alt Text
ConfigHelper.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment