MediaWiki master
ReadOnlyConstraint.php
Go to the documentation of this file.
1<?php
22
23use StatusValue;
25
34
35 private ReadOnlyMode $readOnlyMode;
36 private string $result;
37
38 public function __construct( ReadOnlyMode $readOnlyMode ) {
39 $this->readOnlyMode = $readOnlyMode;
40 }
41
42 public function checkConstraint(): string {
43 $this->result = $this->readOnlyMode->isReadOnly() ?
44 self::CONSTRAINT_FAILED :
45 self::CONSTRAINT_PASSED;
46 return $this->result;
47 }
48
49 public function getLegacyStatus(): StatusValue {
50 $statusValue = StatusValue::newGood();
51
52 if ( $this->result === self::CONSTRAINT_FAILED ) {
53 // Saved that this is read only in case getLegacyStatus is called
54 // after the read only ends, because it still caused the failure
55 $statusValue->fatal( 'readonlytext' );
56 $statusValue->value = self::AS_READ_ONLY_PAGE;
57 }
58
59 return $statusValue;
60 }
61
62}
getLegacyStatus()
Get the legacy status for failure (or success)
Generic operation result class Has warning/error list, boolean status and arbitrary value.
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.