MediaWiki  master
EditRightConstraint.php
Go to the documentation of this file.
1 <?php
22 
24 use StatusValue;
25 
35 
37  private $performer;
38 
40  private $result;
41 
45  public function __construct(
47  ) {
48  $this->performer = $performer;
49  }
50 
51  public function checkConstraint(): string {
52  // Check isn't simple enough to just repeat when getting the status
53  if ( !$this->performer->isAllowed( 'edit' ) ) {
54  $this->result = self::CONSTRAINT_FAILED;
55  return self::CONSTRAINT_FAILED;
56  }
57 
58  $this->result = self::CONSTRAINT_PASSED;
59  return self::CONSTRAINT_PASSED;
60  }
61 
62  public function getLegacyStatus(): StatusValue {
63  $statusValue = StatusValue::newGood();
64 
65  if ( $this->result === self::CONSTRAINT_FAILED ) {
66  if ( !$this->performer->getUser()->isRegistered() ) {
67  $statusValue->setResult( false, self::AS_READ_ONLY_PAGE_ANON );
68  } else {
69  $statusValue->fatal( 'readonlytext' );
70  $statusValue->value = self::AS_READ_ONLY_PAGE_LOGGED;
71  }
72  }
73 
74  return $statusValue;
75  }
76 
77 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\Constraint\EditRightConstraint\$performer
Authority $performer
Definition: EditRightConstraint.php:37
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37
MediaWiki\EditPage\Constraint\EditRightConstraint\__construct
__construct(Authority $performer)
Definition: EditRightConstraint.php:45
MediaWiki\EditPage\Constraint\EditRightConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: EditRightConstraint.php:62
MediaWiki\EditPage\IEditObject\AS_READ_ONLY_PAGE_LOGGED
const AS_READ_ONLY_PAGE_LOGGED
Status: this logged in user is not allowed to edit this page.
Definition: IEditObject.php:53
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\EditPage\Constraint\EditRightConstraint\$result
string null $result
Definition: EditRightConstraint.php:40
MediaWiki\EditPage\Constraint\EditRightConstraint
Verify user permissions: Must have edit rights.
Definition: EditRightConstraint.php:34
MediaWiki\EditPage\Constraint\EditRightConstraint\checkConstraint
checkConstraint()
Definition: EditRightConstraint.php:51
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33