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
41 public function __construct( ReadOnlyMode $readOnlyMode ) {
42 $this->readOnlyMode = $readOnlyMode;
43 }
44
45 public function checkConstraint(): string {
46 $this->result = $this->readOnlyMode->isReadOnly() ?
47 self::CONSTRAINT_FAILED :
48 self::CONSTRAINT_PASSED;
49 return $this->result;
50 }
51
52 public function getLegacyStatus(): StatusValue {
53 $statusValue = StatusValue::newGood();
54
55 if ( $this->result === self::CONSTRAINT_FAILED ) {
56 // Saved that this is read only in case getLegacyStatus is called
57 // after the read only ends, because it still caused the failure
58 $statusValue->fatal( 'readonlytext' );
59 $statusValue->value = self::AS_READ_ONLY_PAGE;
60 }
61
62 return $statusValue;
63 }
64
65}
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.