88 $this->blockStore = $blockStore;
89 $this->blockTargetFactory = $blockTargetFactory;
90 $this->userFactory = $userFactory;
91 $this->hookRunner =
new HookRunner( $hookContainer );
94 if ( $blockToRemove !==
null ) {
95 $this->blockToRemove = $blockToRemove;
96 $this->target = $blockToRemove->
getTarget();
98 $this->target = $target;
101 $this->target = $this->blockTargetFactory->newFromLegacyUnion( $target );
104 $this->blockPermissionChecker = $blockPermissionCheckerFactory
109 $this->performer = $performer;
110 $this->reason = $reason;
118 $status =
Status::newGood();
120 $this->block = $this->getBlockToRemove( $status );
121 if ( !$status->isOK() ) {
125 $blockPermissionCheckResult = $this->blockPermissionChecker->checkBlockPermissions( $this->target );
126 if ( $blockPermissionCheckResult !==
true ) {
127 return $status->fatal( $blockPermissionCheckResult );
130 $basePermissionCheckResult = $this->blockPermissionChecker->checkBasePermissions(
131 $this->block instanceof DatabaseBlock && $this->block->getHideName()
134 if ( $basePermissionCheckResult !==
true ) {
135 return $status->fatal( $basePermissionCheckResult );
138 if ( count( $this->tags ) !== 0 ) {
147 if ( !$status->isOK() ) {
161 $status =
Status::newGood();
163 $this->block ??= $this->getBlockToRemove( $status );
164 if ( !$status->isOK() ) {
168 if ( $this->block ===
null ) {
169 return $status->fatal(
'ipb_cant_unblock', $this->target );
176 return $status->fatal(
'ipb_blocked_as_range', $this->target, $this->block->getTargetName() );
179 $denyReason = [
'hookaborted' ];
180 $legacyUser = $this->userFactory->newFromAuthority( $this->performer );
181 if ( !$this->hookRunner->onUnblockUser( $this->block, $legacyUser, $denyReason ) ) {
182 foreach ( $denyReason as $key ) {
183 $status->fatal( $key );
188 $deleteBlockStatus = $this->blockStore->deleteBlock( $this->block );
189 if ( !$deleteBlockStatus ) {
190 return $status->fatal(
'ipb_cant_unblock', $this->block->getTargetName() );
193 $this->hookRunner->onUnblockUserComplete( $this->block, $legacyUser );
196 $user = $this->block->getTargetUserIdentity();
197 if ( $this->block->getHideName() && $user ) {
198 $id = $user->getId();
204 $status->setResult( $status->isOK(), $this->block );
211 private function log() {
212 $page = $this->block->getRedactedTarget()->getLogPage();
213 $logEntry =
new ManualLogEntry(
'block',
'unblock' );
215 $logEntry->setTarget( $page );
216 $logEntry->setComment( $this->reason );
217 $logEntry->setPerformer( $this->performer->getUser() );
218 $logEntry->addTags( $this->tags );
219 $logEntry->setRelations( [
'ipb_id' => $this->block->getId() ] );
221 $logEntry->addParameter(
'blockId', $this->block->getId() );
222 $logId = $logEntry->insert();
223 $logEntry->publish( $logId );
226 private function getBlockToRemove( Status $status ): ?DatabaseBlock {
227 if ( $this->blockToRemove !== null ) {
228 return $this->blockToRemove;
231 $activeBlocks = $this->blockStore->newListFromTarget( $this->target );
232 if ( !$activeBlocks ) {
233 $status->fatal(
'ipb_cant_unblock', $this->target );
237 if ( count( $activeBlocks ) > 1 ) {
238 $status->fatal(
'ipb_cant_unblock_multiple_blocks',
239 count( $activeBlocks ), Message::listParam(
241 static function ( $block ) {
242 return $block->
getId();
248 return $activeBlocks[0];
if(!defined('MW_SETUP_CALLBACK'))
Class for creating new log entries and inserting them into the database.
Backend functions for suppressing and unsuppressing all references to a given user,...
static unsuppressUserName( $name, $userId, ?IDatabase $dbw=null)