MediaWiki  master
ReadOnlyConstraint.php
Go to the documentation of this file.
1 <?php
22 
23 use StatusValue;
25 
34 
36  private $readOnlyMode;
37 
39  private $result;
40 
44  public function __construct( ReadOnlyMode $readOnlyMode ) {
45  $this->readOnlyMode = $readOnlyMode;
46  }
47 
48  public function checkConstraint(): string {
49  $this->result = $this->readOnlyMode->isReadOnly() ?
50  self::CONSTRAINT_FAILED :
51  self::CONSTRAINT_PASSED;
52  return $this->result;
53  }
54 
55  public function getLegacyStatus(): StatusValue {
56  $statusValue = StatusValue::newGood();
57 
58  if ( $this->result === self::CONSTRAINT_FAILED ) {
59  // Saved that this is read only in case getLegacyStatus is called
60  // after the read only ends, because it still caused the failure
61  $statusValue->fatal( 'readonlytext' );
62  $statusValue->value = self::AS_READ_ONLY_PAGE;
63  }
64 
65  return $statusValue;
66  }
67 
68 }
Verify site is not in read only mode.
getLegacyStatus()
Get the legacy status for failure (or success)
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.
Determine whether a site is currently in read-only mode.
Interface for all constraints that can prevent edits.