3 use Wikimedia\Rdbms\LoadBalancer
;
6 * A service class for fetching the wiki's current read-only mode.
7 * To obtain an instance, use MediaWikiServices::getReadOnlyMode().
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;
24 * Check whether the wiki is in read-only mode.
28 public function isReadOnly() {
29 return $this->getReason() !== false;
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 ) {
45 $reason = $this->loadBalancer
->getReadOnlyReason();
46 if ( $reason !== false && $reason !== null ) {
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 );
63 * Clear the cache of the read only file
65 public function clearCache() {
66 $this->configuredReadOnly
->clearCache();