X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/ConfiguredReadOnlyMode.php diff --git a/includes/ConfiguredReadOnlyMode.php b/includes/ConfiguredReadOnlyMode.php new file mode 100644 index 00000000..af7c7cbd --- /dev/null +++ b/includes/ConfiguredReadOnlyMode.php @@ -0,0 +1,73 @@ +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. + * + * @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; + } +}