X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FConfiguredReadOnlyMode.php;h=f8ba5b1cafbe2c8b3c7955c556a3f762ad58ad82;hp=17c28ec388fd19d2711694a27b8406791a79c618;hb=9283760f340c6971d748fb574a35453fa7928807;hpb=4905504faded8f85a9b3d68b27da5c9e2f11bd06 diff --git a/includes/ConfiguredReadOnlyMode.php b/includes/ConfiguredReadOnlyMode.php index 17c28ec388..f8ba5b1caf 100644 --- a/includes/ConfiguredReadOnlyMode.php +++ b/includes/ConfiguredReadOnlyMode.php @@ -7,17 +7,28 @@ * @since 1.29 */ class ConfiguredReadOnlyMode { - /** @var Config */ - private $config; - - /** @var string|bool|null */ - private $fileReason; + /** @var string|boolean|null */ + private $reason; /** @var string|null */ - private $overrideReason; + private $reasonFile; - public function __construct( Config $config ) { - $this->config = $config; + /** + * @param string|bool|null $reason Current reason for read-only mode, if known. null means look + * in $reasonFile instead. + * @param string|null $reasonFile A file to look in for a reason, if $reason is null. If it + * exists and is non-empty, its contents are treated as the reason for read-only mode. + * Otherwise, the wiki is not read-only. + */ + public function __construct( $reason, $reasonFile = null ) { + if ( $reason instanceof Config ) { + // Before 1.34 we passed a whole Config object, which was overkill + wfDeprecated( __METHOD__ . ' with Config passed to constructor', '1.34' ); + $reason = $reason->get( 'ReadOnly' ); + $reasonFile = $reason->get( 'ReadOnlyFile' ); + } + $this->reason = $reason; + $this->reasonFile = $reasonFile; } /** @@ -35,23 +46,19 @@ class ConfiguredReadOnlyMode { * @return string|bool String when in read-only mode; false otherwise */ public function getReason() { - if ( $this->overrideReason !== null ) { - return $this->overrideReason; + if ( $this->reason !== null ) { + return $this->reason; } - $confReason = $this->config->get( 'ReadOnly' ); - if ( $confReason !== null ) { - return $confReason; + if ( $this->reasonFile === null ) { + return false; } - 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; - } + // Try the reason file + if ( is_file( $this->reasonFile ) && filesize( $this->reasonFile ) > 0 ) { + $this->reason = file_get_contents( $this->reasonFile ); } - return $this->fileReason; + // No need to try the reason file again + $this->reasonFile = null; + return $this->reason ?? false; } /** @@ -61,13 +68,6 @@ class ConfiguredReadOnlyMode { * @param string|null $msg */ public function setReason( $msg ) { - $this->overrideReason = $msg; - } - - /** - * Clear the cache of the read only file - */ - public function clearCache() { - $this->fileReason = null; + $this->reason = $msg; } }