Remove use of implicitGroupBy() in ActiveUsersPager
[mediawiki.git] / includes / ReadOnlyMode.php
blob547c2d5efed1e1559525d7c5e5f60940c45ffa62
1 <?php
3 use Wikimedia\Rdbms\LoadBalancer;
5 /**
6 * A service class for fetching the wiki's current read-only mode.
7 * To obtain an instance, use MediaWikiServices::getReadOnlyMode().
9 * @since 1.29
11 class ReadOnlyMode {
12 /** @var ConfiguredReadOnlyMode */
13 private $configuredReadOnly;
15 /** @var LoadBalancer */
16 private $loadBalancer;
18 public function __construct( ConfiguredReadOnlyMode $cro, LoadBalancer $loadBalancer ) {
19 $this->configuredReadOnly = $cro;
20 $this->loadBalancer = $loadBalancer;
23 /**
24 * Check whether the wiki is in read-only mode.
26 * @return bool
28 public function isReadOnly() {
29 return $this->getReason() !== false;
32 /**
33 * Check if the site is in read-only mode and return the message if so
35 * This checks the configuration and registered DB load balancers for
36 * read-only mode. This may result in DB connection being made.
38 * @return string|bool String when in read-only mode; false otherwise
40 public function getReason() {
41 $reason = $this->configuredReadOnly->getReason();
42 if ( $reason !== false ) {
43 return $reason;
45 $reason = $this->loadBalancer->getReadOnlyReason();
46 if ( $reason !== false && $reason !== null ) {
47 return $reason;
49 return false;
52 /**
53 * Set the read-only mode, which will apply for the remainder of the
54 * request or until a service reset.
56 * @param string|null $msg
58 public function setReason( $msg ) {
59 $this->configuredReadOnly->setReason( $msg );
62 /**
63 * Clear the cache of the read only file
65 public function clearCache() {
66 $this->configuredReadOnly->clearCache();