MediaWiki  master
ConfiguredReadOnlyMode.php
Go to the documentation of this file.
1 <?php
2 
11  private $reason;
12 
14  private $reasonFile;
15 
23  public function __construct( $reason, $reasonFile = null ) {
24  $this->reason = $reason;
25  $this->reasonFile = $reasonFile;
26  }
27 
33  public function isReadOnly() {
34  return $this->getReason() !== false;
35  }
36 
42  public function getReason() {
43  if ( $this->reason !== null ) {
44  return $this->reason;
45  }
46  if ( $this->reasonFile === null ) {
47  return false;
48  }
49  // Try the reason file
50  if ( is_file( $this->reasonFile ) && filesize( $this->reasonFile ) > 0 ) {
51  $this->reason = file_get_contents( $this->reasonFile );
52  }
53  // No need to try the reason file again
54  $this->reasonFile = null;
55  return $this->reason ?? false;
56  }
57 
64  public function setReason( $msg ) {
65  $this->reason = $msg;
66  }
67 }
ConfiguredReadOnlyMode\isReadOnly
isReadOnly()
Check whether the wiki is in read-only mode.
Definition: ConfiguredReadOnlyMode.php:33
ConfiguredReadOnlyMode\__construct
__construct( $reason, $reasonFile=null)
Definition: ConfiguredReadOnlyMode.php:23
ConfiguredReadOnlyMode
A read-only mode service which does not depend on LoadBalancer.
Definition: ConfiguredReadOnlyMode.php:9
ConfiguredReadOnlyMode\getReason
getReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
Definition: ConfiguredReadOnlyMode.php:42
ConfiguredReadOnlyMode\$reasonFile
string null $reasonFile
Definition: ConfiguredReadOnlyMode.php:14
ConfiguredReadOnlyMode\setReason
setReason( $msg)
Set the read-only mode, which will apply for the remainder of the request or until a service reset.
Definition: ConfiguredReadOnlyMode.php:64
ConfiguredReadOnlyMode\$reason
string bool null $reason
Definition: ConfiguredReadOnlyMode.php:11