MediaWiki 1.43.1
BlockPermissionChecker.php
Go to the documentation of this file.
1<?php
2
22namespace MediaWiki\Block;
23
28
42 private $target;
43
47 private $performer;
48
52 public const CONSTRUCTOR_OPTIONS = [
54 ];
55
56 private ServiceOptions $options;
57
64 public function __construct(
65 ServiceOptions $options,
66 BlockUtils $blockUtils,
67 $target,
68 Authority $performer
69 ) {
70 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
71 $this->options = $options;
72 [ $this->target, ] = $blockUtils->parseBlockTarget( $target );
73 $this->performer = $performer;
74 }
75
83 public function checkBasePermissions( $checkHideuser = false ) {
84 if ( !$this->performer->isAllowed( 'block' ) ) {
85 return 'badaccess-group0';
86 }
87
88 if (
89 $checkHideuser &&
90 !$this->performer->isAllowed( 'hideuser' )
91 ) {
92 return 'unblock-hideuser';
93 }
94
95 return true;
96 }
97
109 public function checkBlockPermissions() {
110 $block = $this->performer->getBlock(); // TODO: pass disposition parameter
111 if ( !$block ) {
112 // User is not blocked, process as normal
113 return true;
114 }
115
116 if ( !$block->isSitewide() ) {
117 // T208965: Partially blocked admins should have full access
118 return true;
119 }
120
121 $performerIdentity = $this->performer->getUser();
122
123 if (
124 $this->target instanceof UserIdentity &&
125 $this->target->getId() === $performerIdentity->getId()
126 ) {
127 // Blocked admin is trying to alter their own block
128
129 // Self-blocked admins can always remove or alter their block
130 if ( $block->getBlocker() && $performerIdentity->equals( $block->getBlocker() ) ) {
131 return true;
132 }
133
134 // Users with 'unblockself' right can unblock themselves or alter their own block
135 if ( $this->performer->isAllowed( 'unblockself' ) ) {
136 return true;
137 } else {
138 return 'ipbnounblockself';
139 }
140 }
141
142 if (
143 $this->target instanceof UserIdentity &&
144 $block->getBlocker() &&
145 $this->target->equals( $block->getBlocker() )
146 ) {
147 // T150826: Blocked admins can always block the admin who blocked them
148 return true;
149 }
150
151 // User is blocked and no exception took effect
152 return 'ipbblocked';
153 }
154
161 public function checkEmailPermissions() {
162 return $this->options->get( MainConfigNames::EnableUserEmail ) &&
163 $this->performer->isAllowed( 'blockemail' );
164 }
165}
__construct(ServiceOptions $options, BlockUtils $blockUtils, $target, Authority $performer)
checkEmailPermissions()
Check permission to block emailing.
checkBlockPermissions()
Checks block-related permissions (doesn't check any other permissions)
checkBasePermissions( $checkHideuser=false)
Check the base permission that applies to either block or unblock.
Backend class for blocking utils.
parseBlockTarget( $target)
From string specification or UserIdentity, get the block target and the type of target.
A class for passing options to services.
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
A class containing constants representing the names of configuration variables.
const EnableUserEmail
Name constant for the EnableUserEmail setting, for use with Config::get()
This interface represents the authority associated with the current execution context,...
Definition Authority.php:37
Interface for objects representing user identity.
equals(?UserIdentity $user)
getId( $wikiId=self::LOCAL)