MediaWiki
master
Toggle main menu visibility
RestrictedUserGroupConfigReader.php
Go to the documentation of this file.
1
<?php
2
/*
3
* @license GPL-2.0-or-later
4
* @file
5
*/
6
7
namespace
MediaWiki\User;
8
9
use MediaWiki\Config\ServiceOptions;
10
use MediaWiki\MainConfigNames;
11
use MediaWiki\WikiMap\WikiMap;
12
18
class
RestrictedUserGroupConfigReader
{
19
21
public
const
CONSTRUCTOR_OPTIONS
= [
22
MainConfigNames::RestrictedGroups
,
23
];
24
29
public
const
SCOPE_LOCAL
=
'local'
;
30
31
public
function
__construct
(
32
private
readonly
ServiceOptions
$options,
33
private
readonly
UserRequirementsConditionValidator
$userRequirementsConditionValidator,
34
) {
35
}
36
46
public
function
getConfig
(
false
|
string
$wiki =
false
,
string
$scope = self::SCOPE_LOCAL ): array {
47
$isLocal = $wiki === false || $wiki ===
WikiMap
::getCurrentWikiId();
48
if
( $isLocal ) {
49
$rawConfig = $this->getConfigForLocalWiki();
50
}
else
{
51
$rawConfig = $this->getConfigForRemoteWiki( $wiki );
52
}
53
54
$result = [];
55
foreach
( $rawConfig as $groupName => $spec ) {
56
if
( isset( $spec[
'scope'
] ) && !in_array( $scope, $spec[
'scope'
],
true
) ) {
57
continue
;
58
}
59
$result[$groupName] =
UserGroupRestrictions::newFromSpecValidated
(
60
$spec,
61
$this->userRequirementsConditionValidator
62
);
63
}
64
return
$result;
65
}
66
67
private
function
getConfigForLocalWiki(): array {
68
$this->
options
->
assertRequiredOptions
( self::
CONSTRUCTOR_OPTIONS
);
69
return
$this->
options
->get(
MainConfigNames::RestrictedGroups
);
70
}
71
72
private
function
getConfigForRemoteWiki(
string
$wiki ): array {
73
global
$wgConf
;
74
'@phan-var \MediaWiki\Config\SiteConfiguration $wgConf'
;
75
76
return
$wgConf
->get(
'wgRestrictedGroups'
, $wiki ) ?? [];
77
}
78
}
$wgConf
$wgConf
$wgConf hold the site configuration.
Definition
Setup.php:137
MediaWiki\Config\ServiceOptions
A class for passing options to services.
Definition
ServiceOptions.php:27
MediaWiki\Config\ServiceOptions\assertRequiredOptions
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
Definition
ServiceOptions.php:70
MediaWiki\JobQueue\JobQueueGroupFactory\CONSTRUCTOR_OPTIONS
const CONSTRUCTOR_OPTIONS
Definition
JobQueueGroupFactory.php:28
MediaWiki\MainConfigNames\RestrictedGroups
const RestrictedGroups
Name constant for the RestrictedGroups setting, for use with Config\get().
Definition
MainConfigNames.php:2839
MediaWiki\User\RestrictedUserGroupConfigReader
A helper class to read the restricted user groups configuration for a given wiki.
Definition
RestrictedUserGroupConfigReader.php:18
MediaWiki\User\RestrictedUserGroupConfigReader\getConfig
getConfig(false|string $wiki=false, string $scope=self::SCOPE_LOCAL)
Reads the restricted group configuration for the specified wiki, either from the ServiceOptions provi...
Definition
RestrictedUserGroupConfigReader.php:46
MediaWiki\User\RestrictedUserGroupConfigReader\SCOPE_LOCAL
const SCOPE_LOCAL
Scope value representing user groups as supported by MediaWiki core.
Definition
RestrictedUserGroupConfigReader.php:29
MediaWiki\User\RestrictedUserGroupConfigReader\__construct
__construct(private readonly ServiceOptions $options, private readonly UserRequirementsConditionValidator $userRequirementsConditionValidator,)
Definition
RestrictedUserGroupConfigReader.php:31
MediaWiki\User\RestrictedUserGroupConfigReader\CONSTRUCTOR_OPTIONS
const CONSTRUCTOR_OPTIONS
Definition
RestrictedUserGroupConfigReader.php:21
MediaWiki\User\UserGroupRestrictions\newFromSpecValidated
static newFromSpecValidated(array $spec, UserRequirementsConditionValidator $validator)
Creates a new object representing user group restriction, but first, it validates the conditions.
Definition
UserGroupRestrictions.php:50
MediaWiki\User\UserRequirementsConditionValidator
Definition
UserRequirementsConditionValidator.php:11
MediaWiki\WikiMap\WikiMap
Tools for dealing with other locally-hosted wikis.
Definition
WikiMap.php:19
Wikimedia\Rdbms\SelectQueryBuilder\options
options(array $options)
Manually set multiple options in the $options array to be passed to IReadableDatabase\select().
Definition
SelectQueryBuilder.php:714
includes
User
RestrictedUserGroupConfigReader.php
Generated on
for MediaWiki by
1.18.0