MediaWiki  master
CreationPermissionConstraint.php
Go to the documentation of this file.
1 <?php
22 
24 use StatusValue;
25 use Title;
26 
35 
37  private $performer;
38 
40  private $title;
41 
43  private $result;
44 
49  public function __construct(
52  ) {
53  $this->performer = $performer;
54  $this->title = $title;
55  }
56 
57  public function checkConstraint(): string {
58  // Check isn't simple enough to just repeat when getting the status
59  if ( !$this->performer->authorizeWrite( 'create', $this->title ) ) {
60  $this->result = self::CONSTRAINT_FAILED;
61  return self::CONSTRAINT_FAILED;
62  }
63 
64  $this->result = self::CONSTRAINT_PASSED;
65  return self::CONSTRAINT_PASSED;
66  }
67 
68  public function getLegacyStatus(): StatusValue {
69  $statusValue = StatusValue::newGood();
70 
71  if ( $this->result === self::CONSTRAINT_FAILED ) {
72  $statusValue->fatal( 'nocreatetext' );
73  $statusValue->value = self::AS_NO_CREATE_PERMISSION;
74  }
75 
76  return $statusValue;
77  }
78 
79 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\Constraint\CreationPermissionConstraint\__construct
__construct(Authority $performer, Title $title)
Definition: CreationPermissionConstraint.php:49
MediaWiki\EditPage\IEditObject\AS_NO_CREATE_PERMISSION
const AS_NO_CREATE_PERMISSION
Status: user tried to create this page, but is not allowed to do that.
Definition: IEditObject.php:65
MediaWiki\EditPage\Constraint\CreationPermissionConstraint\checkConstraint
checkConstraint()
Definition: CreationPermissionConstraint.php:57
MediaWiki\EditPage\Constraint\CreationPermissionConstraint
Verify be able to create the page in question if it is a new page.
Definition: CreationPermissionConstraint.php:34
MediaWiki\EditPage\Constraint\CreationPermissionConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: CreationPermissionConstraint.php:68
MediaWiki\EditPage\Constraint\CreationPermissionConstraint\$title
Title $title
Definition: CreationPermissionConstraint.php:40
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
Title
Represents a title within MediaWiki.
Definition: Title.php:47
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\EditPage\Constraint\CreationPermissionConstraint\$performer
Authority $performer
Definition: CreationPermissionConstraint.php:37
MediaWiki\EditPage\Constraint\CreationPermissionConstraint\$result
string null $result
Definition: CreationPermissionConstraint.php:43
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33