MediaWiki master
RestrictedUserGroupConfigReader.php
Go to the documentation of this file.
1<?php
2/*
3 * @license GPL-2.0-or-later
4 * @file
5 */
6
7namespace MediaWiki\User;
8
12
19
21 public const CONSTRUCTOR_OPTIONS = [
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 }
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 hold the site configuration.
Definition Setup.php:137
A class for passing options to services.
A class containing constants representing the names of configuration variables.
const RestrictedGroups
Name constant for the RestrictedGroups setting, for use with Config::get()
A helper class to read the restricted user groups configuration for a given wiki.
getConfig(false|string $wiki=false, string $scope=self::SCOPE_LOCAL)
Reads the restricted group configuration for the specified wiki, either from the ServiceOptions provi...
const SCOPE_LOCAL
Scope value representing user groups as supported by MediaWiki core.
__construct(private readonly ServiceOptions $options, private readonly UserRequirementsConditionValidator $userRequirementsConditionValidator,)
static newFromSpecValidated(array $spec, UserRequirementsConditionValidator $validator)
Creates a new object representing user group restriction, but first, it validates the conditions.
Tools for dealing with other locally-hosted wikis.
Definition WikiMap.php:19