MediaWiki  master
CreationPermissionConstraint.php
Go to the documentation of this file.
1 <?php
22 
25 use StatusValue;
26 
35 
37  private $performer;
38 
40  private $title;
41 
43  private $result;
44 
49  public function __construct(
50  Authority $performer,
51  Title $title
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 }
if(!defined('MW_SETUP_CALLBACK'))
Definition: WebStart.php:88
Verify be able to create the page in question if it is a new page.
getLegacyStatus()
Get the legacy status for failure (or success)
Represents a title within MediaWiki.
Definition: Title.php:76
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:46
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
Interface for all constraints that can prevent edits.
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37