MediaWiki  master
ReadOnlyConstraint.php
Go to the documentation of this file.
1 <?php
22 
23 use ReadOnlyMode;
24 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 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\Constraint\ReadOnlyConstraint\$readOnlyMode
ReadOnlyMode $readOnlyMode
Definition: ReadOnlyConstraint.php:36
MediaWiki\EditPage\Constraint\ReadOnlyConstraint
Verify site is not in read only mode.
Definition: ReadOnlyConstraint.php:33
ReadOnlyMode
A service class for fetching the wiki's current read-only mode.
Definition: ReadOnlyMode.php:11
MediaWiki\EditPage\Constraint\ReadOnlyConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: ReadOnlyConstraint.php:55
MediaWiki\EditPage\Constraint\ReadOnlyConstraint\__construct
__construct(ReadOnlyMode $readOnlyMode)
Definition: ReadOnlyConstraint.php:44
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\EditPage\IEditObject\AS_READ_ONLY_PAGE
const AS_READ_ONLY_PAGE
Status: wiki is in readonly mode (wfReadOnly() == true)
Definition: IEditObject.php:56
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\EditPage\Constraint\ReadOnlyConstraint\$result
string null $result
Definition: ReadOnlyConstraint.php:39
MediaWiki\EditPage\Constraint\ReadOnlyConstraint\checkConstraint
checkConstraint()
Definition: ReadOnlyConstraint.php:48
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33