MediaWiki  1.34.0
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  if ( $reason instanceof Config ) {
25  // Before 1.34 we passed a whole Config object, which was overkill
26  wfDeprecated( __METHOD__ . ' with Config passed to constructor', '1.34' );
27  $reason = $reason->get( 'ReadOnly' );
28  $reasonFile = $reason->get( 'ReadOnlyFile' );
29  }
30  $this->reason = $reason;
31  $this->reasonFile = $reasonFile;
32  }
33 
39  public function isReadOnly() {
40  return $this->getReason() !== false;
41  }
42 
48  public function getReason() {
49  if ( $this->reason !== null ) {
50  return $this->reason;
51  }
52  if ( $this->reasonFile === null ) {
53  return false;
54  }
55  // Try the reason file
56  if ( is_file( $this->reasonFile ) && filesize( $this->reasonFile ) > 0 ) {
57  $this->reason = file_get_contents( $this->reasonFile );
58  }
59  // No need to try the reason file again
60  $this->reasonFile = null;
61  return $this->reason ?? false;
62  }
63 
70  public function setReason( $msg ) {
71  $this->reason = $msg;
72  }
73 }
ConfiguredReadOnlyMode\$reason
string boolean null $reason
Definition: ConfiguredReadOnlyMode.php:11
ConfiguredReadOnlyMode\isReadOnly
isReadOnly()
Check whether the wiki is in read-only mode.
Definition: ConfiguredReadOnlyMode.php:39
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:48
ConfiguredReadOnlyMode\$reasonFile
string null $reasonFile
Definition: ConfiguredReadOnlyMode.php:14
Config
Interface for configuration instances.
Definition: Config.php:28
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1044
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:70