3 namespace Wikimedia\Rdbms
;
6 * Determine whether a site is currently in read-only mode.
8 * To obtain an instance, use \MediaWiki\MediaWikiServices::getReadOnlyMode().
13 /** @var ConfiguredReadOnlyMode */
14 private $configuredReadOnly;
16 /** @var ILBFactory */
20 * @internal For ServiceWiring only
21 * @param ConfiguredReadOnlyMode $cro
22 * @param ILBFactory $lbFactory
24 public function __construct( ConfiguredReadOnlyMode
$cro, ILBFactory
$lbFactory ) {
25 $this->configuredReadOnly
= $cro;
26 $this->lbFactory
= $lbFactory;
30 * Check whether the site is in read-only mode.
32 * @param string|false $domain Domain ID, or false for the current domain
35 public function isReadOnly( $domain = false ): bool {
36 return $this->getReason( $domain ) !== false;
40 * Check if the site is in read-only mode and return the message if so
42 * This checks both statically configured read-only mode, and (cached)
43 * whether the primary database host accepting writes.
45 * Calling this may result in database connection.
47 * @param string|false $domain Domain ID, or false for the current domain
48 * @return string|false String when in read-only mode; false otherwise
50 public function getReason( $domain = false ) {
51 $reason = $this->configuredReadOnly
->getReason();
52 if ( $reason !== false ) {
55 $reason = $this->lbFactory
->getMainLB( $domain )->getReadOnlyReason();
56 return $reason ??
false;
61 * @return string|false String when site is configured to be in read-only mode; false otherwise
63 public function getConfiguredReason() {
64 return $this->configuredReadOnly
->getReason();
68 * Check whether the site is configured to be in read-only mode.
73 public function isConfiguredReadOnly() {
74 return $this->configuredReadOnly
->getReason() !== false;
78 * Override the read-only mode, which will apply for the remainder of the
79 * request or until a service reset.
81 * @param string|false|null $msg
83 public function setReason( $msg ): void
{
84 $this->configuredReadOnly
->setReason( $msg );
90 * @deprecated since 1.41
92 class_alias( ReadOnlyMode
::class, 'ReadOnlyMode' );