2019-10-24 03:14:31 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\User;
|
|
|
|
|
|
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
2021-07-31 06:31:11 +00:00
|
|
|
use MediaWiki\JobQueue\JobQueueGroupFactory;
|
2021-01-05 23:08:09 +00:00
|
|
|
use MediaWiki\Permissions\GroupPermissionsLookup;
|
2022-04-11 01:26:51 +00:00
|
|
|
use MediaWiki\User\TempUser\TempUserConfig;
|
2020-06-04 16:41:12 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2019-10-24 03:14:31 +00:00
|
|
|
use Wikimedia\Rdbms\ILBFactory;
|
2023-09-08 11:58:27 +00:00
|
|
|
use Wikimedia\Rdbms\ReadOnlyMode;
|
2019-10-24 03:14:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory service for UserGroupManager instances. This allows UserGroupManager to be created for
|
|
|
|
|
* cross-wiki access.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.35
|
|
|
|
|
*/
|
|
|
|
|
class UserGroupManagerFactory {
|
2023-09-28 15:25:12 +00:00
|
|
|
private ServiceOptions $options;
|
|
|
|
|
private ReadOnlyMode $readOnlyMode;
|
|
|
|
|
private ILBFactory $dbLoadBalancerFactory;
|
|
|
|
|
private UserEditTracker $userEditTracker;
|
|
|
|
|
private GroupPermissionsLookup $groupPermissionLookup;
|
|
|
|
|
private JobQueueGroupFactory $jobQueueGroupFactory;
|
|
|
|
|
private LoggerInterface $logger;
|
2020-06-04 16:41:12 +00:00
|
|
|
|
2019-10-24 03:14:31 +00:00
|
|
|
/** @var callable[] */
|
|
|
|
|
private $clearCacheCallbacks;
|
|
|
|
|
|
2023-09-28 15:25:12 +00:00
|
|
|
private HookContainer $hookContainer;
|
|
|
|
|
private TempUserConfig $tempUserConfig;
|
2022-04-11 01:26:51 +00:00
|
|
|
|
2023-10-18 03:47:02 +00:00
|
|
|
/**
|
|
|
|
|
* @var UserGroupManager[] User group manager instances indexed by wiki
|
|
|
|
|
*/
|
|
|
|
|
private $instances = [];
|
|
|
|
|
|
2019-10-24 03:14:31 +00:00
|
|
|
/**
|
|
|
|
|
* @param ServiceOptions $options
|
2023-09-08 11:58:27 +00:00
|
|
|
* @param ReadOnlyMode $readOnlyMode
|
2019-10-24 03:14:31 +00:00
|
|
|
* @param ILBFactory $dbLoadBalancerFactory
|
|
|
|
|
* @param HookContainer $hookContainer
|
2020-06-04 16:41:12 +00:00
|
|
|
* @param UserEditTracker $userEditTracker
|
2021-01-05 23:08:09 +00:00
|
|
|
* @param GroupPermissionsLookup $groupPermissionsLookup
|
2021-07-31 06:31:11 +00:00
|
|
|
* @param JobQueueGroupFactory $jobQueueGroupFactory
|
2020-06-04 16:41:12 +00:00
|
|
|
* @param LoggerInterface $logger
|
2022-04-11 01:26:51 +00:00
|
|
|
* @param TempUserConfig $tempUserConfig Assumed to be the same across all domains.
|
2019-10-24 03:14:31 +00:00
|
|
|
* @param callable[] $clearCacheCallbacks
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
ServiceOptions $options,
|
2023-09-08 11:58:27 +00:00
|
|
|
ReadOnlyMode $readOnlyMode,
|
2019-10-24 03:14:31 +00:00
|
|
|
ILBFactory $dbLoadBalancerFactory,
|
|
|
|
|
HookContainer $hookContainer,
|
2020-06-04 16:41:12 +00:00
|
|
|
UserEditTracker $userEditTracker,
|
2021-01-05 23:08:09 +00:00
|
|
|
GroupPermissionsLookup $groupPermissionsLookup,
|
2021-07-31 06:31:11 +00:00
|
|
|
JobQueueGroupFactory $jobQueueGroupFactory,
|
2020-06-04 16:41:12 +00:00
|
|
|
LoggerInterface $logger,
|
2022-04-11 01:26:51 +00:00
|
|
|
TempUserConfig $tempUserConfig,
|
2019-10-24 03:14:31 +00:00
|
|
|
array $clearCacheCallbacks = []
|
|
|
|
|
) {
|
|
|
|
|
$this->options = $options;
|
2023-09-08 11:58:27 +00:00
|
|
|
$this->readOnlyMode = $readOnlyMode;
|
2019-10-24 03:14:31 +00:00
|
|
|
$this->dbLoadBalancerFactory = $dbLoadBalancerFactory;
|
|
|
|
|
$this->hookContainer = $hookContainer;
|
2020-06-04 16:41:12 +00:00
|
|
|
$this->userEditTracker = $userEditTracker;
|
2021-01-05 23:08:09 +00:00
|
|
|
$this->groupPermissionLookup = $groupPermissionsLookup;
|
2021-07-31 06:31:11 +00:00
|
|
|
$this->jobQueueGroupFactory = $jobQueueGroupFactory;
|
2020-06-04 16:41:12 +00:00
|
|
|
$this->logger = $logger;
|
2022-04-11 01:26:51 +00:00
|
|
|
$this->tempUserConfig = $tempUserConfig;
|
2019-10-24 03:14:31 +00:00
|
|
|
$this->clearCacheCallbacks = $clearCacheCallbacks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-05-25 18:46:36 +00:00
|
|
|
* @param string|false $wikiId
|
2019-10-24 03:14:31 +00:00
|
|
|
* @return UserGroupManager
|
|
|
|
|
*/
|
2023-05-25 18:46:36 +00:00
|
|
|
public function getUserGroupManager( $wikiId = UserIdentity::LOCAL ): UserGroupManager {
|
|
|
|
|
if ( is_string( $wikiId ) && $this->dbLoadBalancerFactory->getLocalDomainID() === $wikiId ) {
|
|
|
|
|
$wikiId = UserIdentity::LOCAL;
|
|
|
|
|
}
|
2023-10-18 03:47:02 +00:00
|
|
|
$key = (string)$wikiId;
|
|
|
|
|
if ( !isset( $this->instances[$key] ) ) {
|
|
|
|
|
$this->instances[$key] = new UserGroupManager(
|
|
|
|
|
$this->options,
|
|
|
|
|
$this->readOnlyMode,
|
|
|
|
|
$this->dbLoadBalancerFactory,
|
|
|
|
|
$this->hookContainer,
|
|
|
|
|
$this->userEditTracker,
|
|
|
|
|
$this->groupPermissionLookup,
|
|
|
|
|
$this->jobQueueGroupFactory->makeJobQueueGroup( $wikiId ),
|
|
|
|
|
$this->logger,
|
|
|
|
|
$this->tempUserConfig,
|
|
|
|
|
$this->clearCacheCallbacks,
|
|
|
|
|
$wikiId
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return $this->instances[$key];
|
2019-10-24 03:14:31 +00:00
|
|
|
}
|
|
|
|
|
}
|