MediaWiki REL1_34
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}
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
A read-only mode service which does not depend on LoadBalancer.
getReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
__construct( $reason, $reasonFile=null)
setReason( $msg)
Set the read-only mode, which will apply for the remainder of the request or until a service reset.
isReadOnly()
Check whether the wiki is in read-only mode.
Interface for configuration instances.
Definition Config.php:28