MediaWiki  master
UserBlockConstraint.php
Go to the documentation of this file.
1 <?php
22 
25 use StatusValue;
26 use User;
27 
37 
40 
42  private $title;
43 
45  private $user;
46 
48  private $result;
49 
55  public function __construct(
58  User $user
59  ) {
60  $this->permissionManager = $permissionManager;
61  $this->title = $title;
62  $this->user = $user;
63  }
64 
65  public function checkConstraint(): string {
66  // Check isn't simple enough to just repeat when getting the status
67  if ( $this->permissionManager->isBlockedFrom( $this->user, $this->title ) ) {
68  $this->result = self::CONSTRAINT_FAILED;
69  return self::CONSTRAINT_FAILED;
70  }
71 
72  $this->result = self::CONSTRAINT_PASSED;
73  return self::CONSTRAINT_PASSED;
74  }
75 
76  public function getLegacyStatus(): StatusValue {
77  $statusValue = StatusValue::newGood();
78 
79  if ( $this->result === self::CONSTRAINT_FAILED ) {
80  $statusValue->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
81  }
82 
83  return $statusValue;
84  }
85 
86 }
MediaWiki\EditPage\Constraint\UserBlockConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: UserBlockConstraint.php:76
MediaWiki\EditPage\Constraint\UserBlockConstraint\__construct
__construct(PermissionManager $permissionManager, LinkTarget $title, User $user)
Definition: UserBlockConstraint.php:55
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\Constraint\UserBlockConstraint\$user
User $user
Definition: UserBlockConstraint.php:45
MediaWiki\EditPage\Constraint\UserBlockConstraint
Verify user permissions: Must not be blocked from the page.
Definition: UserBlockConstraint.php:36
MediaWiki\EditPage\Constraint\UserBlockConstraint\$title
LinkTarget $title
Definition: UserBlockConstraint.php:42
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:52
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\EditPage\Constraint\UserBlockConstraint\checkConstraint
checkConstraint()
Definition: UserBlockConstraint.php:65
MediaWiki\EditPage\Constraint\UserBlockConstraint\$result
string null $result
Definition: UserBlockConstraint.php:48
MediaWiki\EditPage\Constraint\UserBlockConstraint\$permissionManager
PermissionManager $permissionManager
Definition: UserBlockConstraint.php:39
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:67
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33