Debian Codegraph @

includes/block/UserBlockCommandFactory.php

raw symbols SCIP
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
22 namespace MediaWiki\Block;
23
24 use MediaWiki\Config\ServiceOptions;
25 use MediaWiki\HookContainer\HookContainer;
26 use MediaWiki\Permissions\Authority;
27 use MediaWiki\Title\TitleFactory;
28 use MediaWiki\User\UserEditTracker;
29 use MediaWiki\User\UserFactory;
30 use MediaWiki\User\UserIdentity;
31 use Psr\Log\LoggerInterface;
32
33 class UserBlockCommandFactory implements BlockUserFactory, UnblockUserFactory {
34 private BlockPermissionCheckerFactory $blockPermissionCheckerFactory;
35 private BlockUtils $blockUtils;
36 private HookContainer $hookContainer;
37 private BlockRestrictionStore $blockRestrictionStore;
38 private ServiceOptions $options;
39 private DatabaseBlockStore $blockStore;
40 private UserFactory $userFactory;
41 private UserEditTracker $userEditTracker;
42 private LoggerInterface $logger;
43 private TitleFactory $titleFactory;
44 private BlockActionInfo $blockActionInfo;
45
46 /**
47 * @internal Use only in ServiceWiring
48 */
49 public const CONSTRUCTOR_OPTIONS = BlockUser::CONSTRUCTOR_OPTIONS;
50
51 public function __construct(
52 ServiceOptions $options,
53 HookContainer $hookContainer,
54 BlockPermissionCheckerFactory $blockPermissionCheckerFactory,
55 BlockUtils $blockUtils,
56 DatabaseBlockStore $blockStore,
57 BlockRestrictionStore $blockRestrictionStore,
58 UserFactory $userFactory,
59 UserEditTracker $userEditTracker,
60 LoggerInterface $logger,
61 TitleFactory $titleFactory,
62 BlockActionInfo $blockActionInfo
63 ) {
64 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
65
66 $this->options = $options;
67 $this->hookContainer = $hookContainer;
68 $this->blockPermissionCheckerFactory = $blockPermissionCheckerFactory;
69 $this->blockUtils = $blockUtils;
70 $this->blockStore = $blockStore;
71 $this->blockRestrictionStore = $blockRestrictionStore;
72 $this->userFactory = $userFactory;
73 $this->userEditTracker = $userEditTracker;
74 $this->logger = $logger;
75 $this->titleFactory = $titleFactory;
76 $this->blockActionInfo = $blockActionInfo;
77 }
78
79 /**
80 * Create BlockUser
81 *
82 * @param string|UserIdentity $target Target of the block
83 * @param Authority $performer Performer of the block
84 * @param string $expiry Expiry of the block (timestamp or 'infinity')
85 * @param string $reason Reason of the block
86 * @param array $blockOptions
87 * @param array $blockRestrictions
88 * @param array|null $tags Tags that should be assigned to the log entry
89 *
90 * @return BlockUser
91 */
92 public function newBlockUser(
93 $target,
94 Authority $performer,
95 string $expiry,
96 string $reason = '',
97 array $blockOptions = [],
98 array $blockRestrictions = [],
99 $tags = []
100 ): BlockUser {
101 return new BlockUser(
102 $this->options,
103 $this->blockRestrictionStore,
104 $this->blockPermissionCheckerFactory,
105 $this->blockUtils,
106 $this->blockActionInfo,
107 $this->hookContainer,
108 $this->blockStore,
109 $this->userFactory,
110 $this->userEditTracker,
111 $this->logger,
112 $this->titleFactory,
113 $target,
114 $performer,
115 $expiry,
116 $reason,
117 $blockOptions,
118 $blockRestrictions,
119 $tags ?? []
120 );
121 }
122
123 /**
124 * @param UserIdentity|string $target
125 * @param Authority $performer
126 * @param string $reason
127 * @param string[] $tags
128 *
129 * @return UnblockUser
130 */
131 public function newUnblockUser(
132 $target,
133 Authority $performer,
134 string $reason,
135 array $tags = []
136 ): UnblockUser {
137 return new UnblockUser(
138 $this->blockPermissionCheckerFactory,
139 $this->blockStore,
140 $this->blockUtils,
141 $this->userFactory,
142 $this->hookContainer,
143 $target,
144 $performer,
145 $reason,
146 $tags
147 );
148 }
149 }