Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserBlockCommandFactory
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 newBlockUser
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
2
 newUnblockUser
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 */
21
22namespace MediaWiki\Block;
23
24use MediaWiki\Config\ServiceOptions;
25use MediaWiki\HookContainer\HookContainer;
26use MediaWiki\Permissions\Authority;
27use MediaWiki\Title\TitleFactory;
28use MediaWiki\User\UserEditTracker;
29use MediaWiki\User\UserFactory;
30use MediaWiki\User\UserIdentity;
31use Psr\Log\LoggerInterface;
32
33class UserBlockCommandFactory implements BlockUserFactory, UnblockUserFactory {
34    /**
35     * @var BlockPermissionCheckerFactory
36     */
37    private $blockPermissionCheckerFactory;
38
39    /** @var BlockUtils */
40    private $blockUtils;
41
42    /** @var HookContainer */
43    private $hookContainer;
44
45    /** @var BlockRestrictionStore */
46    private $blockRestrictionStore;
47
48    /** @var ServiceOptions */
49    private $options;
50
51    /** @var DatabaseBlockStore */
52    private $blockStore;
53
54    /** @var UserFactory */
55    private $userFactory;
56
57    /** @var UserEditTracker */
58    private $userEditTracker;
59
60    /** @var LoggerInterface */
61    private $logger;
62
63    /** @var TitleFactory */
64    private $titleFactory;
65
66    /** @var BlockActionInfo */
67    private $blockActionInfo;
68
69    /**
70     * @internal Use only in ServiceWiring
71     */
72    public const CONSTRUCTOR_OPTIONS = BlockUser::CONSTRUCTOR_OPTIONS;
73
74    /**
75     * @param ServiceOptions $options
76     * @param HookContainer $hookContainer
77     * @param BlockPermissionCheckerFactory $blockPermissionCheckerFactory
78     * @param BlockUtils $blockUtils
79     * @param DatabaseBlockStore $blockStore
80     * @param BlockRestrictionStore $blockRestrictionStore
81     * @param UserFactory $userFactory
82     * @param UserEditTracker $userEditTracker
83     * @param LoggerInterface $logger
84     * @param TitleFactory $titleFactory
85     * @param BlockActionInfo $blockActionInfo
86     */
87    public function __construct(
88        ServiceOptions $options,
89        HookContainer $hookContainer,
90        BlockPermissionCheckerFactory $blockPermissionCheckerFactory,
91        BlockUtils $blockUtils,
92        DatabaseBlockStore $blockStore,
93        BlockRestrictionStore $blockRestrictionStore,
94        UserFactory $userFactory,
95        UserEditTracker $userEditTracker,
96        LoggerInterface $logger,
97        TitleFactory $titleFactory,
98        BlockActionInfo $blockActionInfo
99    ) {
100        $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
101
102        $this->options = $options;
103        $this->hookContainer = $hookContainer;
104        $this->blockPermissionCheckerFactory = $blockPermissionCheckerFactory;
105        $this->blockUtils = $blockUtils;
106        $this->blockStore = $blockStore;
107        $this->blockRestrictionStore = $blockRestrictionStore;
108        $this->userFactory = $userFactory;
109        $this->userEditTracker = $userEditTracker;
110        $this->logger = $logger;
111        $this->titleFactory = $titleFactory;
112        $this->blockActionInfo = $blockActionInfo;
113    }
114
115    /**
116     * Create BlockUser
117     *
118     * @param string|UserIdentity $target Target of the block
119     * @param Authority $performer Performer of the block
120     * @param string $expiry Expiry of the block (timestamp or 'infinity')
121     * @param string $reason Reason of the block
122     * @param array $blockOptions
123     * @param array $blockRestrictions
124     * @param array|null $tags Tags that should be assigned to the log entry
125     *
126     * @return BlockUser
127     */
128    public function newBlockUser(
129        $target,
130        Authority $performer,
131        string $expiry,
132        string $reason = '',
133        array $blockOptions = [],
134        array $blockRestrictions = [],
135        $tags = []
136    ): BlockUser {
137        return new BlockUser(
138            $this->options,
139            $this->blockRestrictionStore,
140            $this->blockPermissionCheckerFactory,
141            $this->blockUtils,
142            $this->blockActionInfo,
143            $this->hookContainer,
144            $this->blockStore,
145            $this->userFactory,
146            $this->userEditTracker,
147            $this->logger,
148            $this->titleFactory,
149            $target,
150            $performer,
151            $expiry,
152            $reason,
153            $blockOptions,
154            $blockRestrictions,
155            $tags ?? []
156        );
157    }
158
159    /**
160     * @param UserIdentity|string $target
161     * @param Authority $performer
162     * @param string $reason
163     * @param string[] $tags
164     *
165     * @return UnblockUser
166     */
167    public function newUnblockUser(
168        $target,
169        Authority $performer,
170        string $reason,
171        array $tags = []
172    ): UnblockUser {
173        return new UnblockUser(
174            $this->blockPermissionCheckerFactory,
175            $this->blockStore,
176            $this->blockUtils,
177            $this->userFactory,
178            $this->hookContainer,
179            $target,
180            $performer,
181            $reason,
182            $tags
183        );
184    }
185}