X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FReadOnlyMode.php;h=547c2d5efed1e1559525d7c5e5f60940c45ffa62;hb=70d1bc00919efb1cbfd00e85bbf65b8e947cbdb6;hp=044e3f51a8382552c6af309e7441688967079aad;hpb=820f46964f7968a8f534a678dc528348445b666d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ReadOnlyMode.php b/includes/ReadOnlyMode.php index 044e3f51a8..547c2d5efe 100644 --- a/includes/ReadOnlyMode.php +++ b/includes/ReadOnlyMode.php @@ -9,7 +9,10 @@ use Wikimedia\Rdbms\LoadBalancer; * @since 1.29 */ class ReadOnlyMode { + /** @var ConfiguredReadOnlyMode */ private $configuredReadOnly; + + /** @var LoadBalancer */ private $loadBalancer; public function __construct( ConfiguredReadOnlyMode $cro, LoadBalancer $loadBalancer ) { @@ -49,6 +52,8 @@ class ReadOnlyMode { /** * Set the read-only mode, which will apply for the remainder of the * request or until a service reset. + * + * @param string|null $msg */ public function setReason( $msg ) { $this->configuredReadOnly->setReason( $msg ); @@ -61,68 +66,3 @@ class ReadOnlyMode { $this->configuredReadOnly->clearCache(); } } - -/** - * A read-only mode service which does not depend on LoadBalancer. - * To obtain an instance, use MediaWikiServices::getConfiguredReadOnlyMode(). - * - * @since 1.29 - */ -class ConfiguredReadOnlyMode { - private $config; - private $fileReason; - private $overrideReason; - - public function __construct( Config $config ) { - $this->config = $config; - } - - /** - * Check whether the wiki is in read-only mode. - * - * @return bool - */ - public function isReadOnly() { - return $this->getReason() !== false; - } - - /** - * Get the value of $wgReadOnly or the contents of $wgReadOnlyFile. - * - * @return string|bool String when in read-only mode; false otherwise - */ - public function getReason() { - if ( $this->overrideReason !== null ) { - return $this->overrideReason; - } - $confReason = $this->config->get( 'ReadOnly' ); - if ( $confReason !== null ) { - return $confReason; - } - if ( $this->fileReason === null ) { - // Cache for faster access next time - $readOnlyFile = $this->config->get( 'ReadOnlyFile' ); - if ( is_file( $readOnlyFile ) && filesize( $readOnlyFile ) > 0 ) { - $this->fileReason = file_get_contents( $readOnlyFile ); - } else { - $this->fileReason = false; - } - } - return $this->fileReason; - } - - /** - * Set the read-only mode, which will apply for the remainder of the - * request or until a service reset. - */ - public function setReason( $msg ) { - $this->overrideReason = $msg; - } - - /** - * Clear the cache of the read only file - */ - public function clearCache() { - $this->fileReason = null; - } -}