Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4163454
ReadOnlyMode.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ReadOnlyMode.php
View Options
<?php
namespace
Wikimedia\Rdbms
;
/**
* Determine whether a site is currently in read-only mode.
*
* To obtain an instance, use \MediaWiki\MediaWikiServices::getReadOnlyMode().
*
* @since 1.29
*/
class
ReadOnlyMode
{
/** @var ConfiguredReadOnlyMode */
private
$configuredReadOnly
;
/** @var ILBFactory */
private
$lbFactory
;
/**
* @internal For ServiceWiring only
* @param ConfiguredReadOnlyMode $cro
* @param ILBFactory $lbFactory
*/
public
function
__construct
(
ConfiguredReadOnlyMode
$cro
,
ILBFactory
$lbFactory
)
{
$this
->
configuredReadOnly
=
$cro
;
$this
->
lbFactory
=
$lbFactory
;
}
/**
* Check whether the site is in read-only mode.
*
* @param string|false $domain Domain ID, or false for the current domain
* @return bool
*/
public
function
isReadOnly
(
$domain
=
false
):
bool
{
return
$this
->
getReason
(
$domain
)
!==
false
;
}
/**
* Check if the site is in read-only mode and return the message if so
*
* This checks both statically configured read-only mode, and (cached)
* whether the primary database host accepting writes.
*
* Calling this may result in database connection.
*
* This method accepts virtual domains
* ({@see \MediaWiki\MainConfigSchema::VirtualDomainsMapping}).
*
* @param string|false $domain Domain ID, or false for the current domain
* @return string|false String when in read-only mode; false otherwise
*/
public
function
getReason
(
$domain
=
false
)
{
$reason
=
$this
->
configuredReadOnly
->
getReason
();
if
(
$reason
!==
false
)
{
return
$reason
;
}
$reason
=
$this
->
lbFactory
->
getLoadBalancer
(
$domain
)->
getReadOnlyReason
();
return
$reason
??
false
;
}
/**
* @since 1.41
* @return string|false String when site is configured to be in read-only mode; false otherwise
*/
public
function
getConfiguredReason
()
{
return
$this
->
configuredReadOnly
->
getReason
();
}
/**
* Check whether the site is configured to be in read-only mode.
*
* @since 1.41
* @return bool
*/
public
function
isConfiguredReadOnly
()
{
return
$this
->
configuredReadOnly
->
getReason
()
!==
false
;
}
/**
* Override the read-only mode, which will apply for the remainder of the
* request or until a service reset.
*
* @param string|false|null $msg
*/
public
function
setReason
(
$msg
):
void
{
$this
->
configuredReadOnly
->
setReason
(
$msg
);
}
}
/** @deprecated class alias since 1.41 */
class_alias
(
ReadOnlyMode
::
class
,
'ReadOnlyMode'
);
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 20 2026, 02:04 (10 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
ff/e3/e3bea2760492df5f91376f393354
Default Alt Text
ReadOnlyMode.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment