MediaWiki REL1_35
BlockPermissionChecker.php
Go to the documentation of this file.
1<?php
2
22namespace MediaWiki\Block;
23
26use User;
27
42 private $target;
43
47 private $targetType = null;
48
52 private $performer;
53
58
59 public function __construct(
61 $target,
63 ) {
64 $this->permissionManager = $permissionManager;
65 list( $this->target, $this->targetType ) = AbstractBlock::parseTarget( $target );
66 $this->performer = $performer;
67 }
68
80 public function checkBlockPermissions() {
81 $block = $this->performer->getBlock();
82 if ( !$block ) {
83 // User is not blocked, process as normal
84 return true;
85 }
86
87 if ( !$block->isSitewide() ) {
88 // T208965: Partially blocked admins should have full access
89 return true;
90 }
91
92 if (
93 $this->target instanceof UserIdentity &&
94 $this->target->getId() === $this->performer->getId()
95 ) {
96 // Blocked admin is trying to alter their own block
97
98 // Self-blocked admins can always remove or alter their block
99 if ( $this->performer->blockedBy() === $this->performer->getName() ) {
100 return true;
101 }
102
103 // Users with 'unblockself' right can unblock themselves or alter their own block
104 if ( $this->permissionManager->userHasRight( $this->performer, 'unblockself' ) ) {
105 return true;
106 } else {
107 return 'ipbnounblockself';
108 }
109 }
110
111 if (
112 $this->target instanceof UserIdentity &&
113 $this->performer->blockedBy() === $this->target->getName()
114 ) {
115 // T150826: Blocked admins can always block the admin who blocked them
116 return true;
117 }
118
119 // User is blocked and no exception took effect
120 return 'ipbblocked';
121 }
122}
static parseTarget( $target)
From an existing block, get the target and the type of target.
checkBlockPermissions()
Checks block-related permissions (doesn't check any other permissions)
__construct(PermissionManager $permissionManager, $target, User $performer)
UserIdentity string $target
Block target.
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
Interface for objects representing user identity.