MediaWiki REL1_30
ConfiguredReadOnlyMode.php
Go to the documentation of this file.
1<?php
2
11 private $config;
12
14 private $fileReason;
15
18
19 public function __construct( Config $config ) {
20 $this->config = $config;
21 }
22
28 public function isReadOnly() {
29 return $this->getReason() !== false;
30 }
31
37 public function getReason() {
38 if ( $this->overrideReason !== null ) {
40 }
41 $confReason = $this->config->get( 'ReadOnly' );
42 if ( $confReason !== null ) {
43 return $confReason;
44 }
45 if ( $this->fileReason === null ) {
46 // Cache for faster access next time
47 $readOnlyFile = $this->config->get( 'ReadOnlyFile' );
48 if ( is_file( $readOnlyFile ) && filesize( $readOnlyFile ) > 0 ) {
49 $this->fileReason = file_get_contents( $readOnlyFile );
50 } else {
51 $this->fileReason = false;
52 }
53 }
54 return $this->fileReason;
55 }
56
63 public function setReason( $msg ) {
64 $this->overrideReason = $msg;
65 }
66
70 public function clearCache() {
71 $this->fileReason = null;
72 }
73}
A read-only mode service which does not depend on LoadBalancer.
getReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
setReason( $msg)
Set the read-only mode, which will apply for the remainder of the request or until a service reset.
clearCache()
Clear the cache of the read only file.
isReadOnly()
Check whether the wiki is in read-only mode.
Interface for configuration instances.
Definition Config.php:28