Make wfReadOnly() a wrapper around wfReadOnlyReason()
authorKevin Israel <pleasestand@live.com>
Fri, 10 May 2013 07:37:04 +0000 (03:37 -0400)
committerTim Starling <tstarling@wikimedia.org>
Tue, 13 Aug 2013 04:42:24 +0000 (04:42 +0000)
This makes more sense than having wfReadOnlyReason() call
wfReadOnly() for its side effect of setting $wgReadOnly
to the contents of $wgReadOnlyFile if the file exists.

Change-Id: Ic723aed368915ac3757f3100ddbbeb3b5a4cdc15

includes/GlobalFunctions.php

index 4679941..be4ec3e 100644 (file)
@@ -1225,36 +1225,31 @@ function wfIncrStats( $key, $count = 1 ) {
 }
 
 /**
- * Check if the wiki read-only lock file is present. This can be used to lock
- * off editing functions, but doesn't guarantee that the database will not be
- * modified.
+ * Check whether the wiki is in read-only mode.
  *
  * @return bool
  */
 function wfReadOnly() {
-       global $wgReadOnlyFile, $wgReadOnly;
-
-       if ( !is_null( $wgReadOnly ) ) {
-               return (bool)$wgReadOnly;
-       }
-       if ( $wgReadOnlyFile == '' ) {
-               return false;
-       }
-       // Set $wgReadOnly for faster access next time
-       if ( is_file( $wgReadOnlyFile ) ) {
-               $wgReadOnly = file_get_contents( $wgReadOnlyFile );
-       } else {
-               $wgReadOnly = false;
-       }
-       return (bool)$wgReadOnly;
+       return wfReadOnlyReason() !== false;
 }
 
 /**
- * @return bool
+ * Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
+ *
+ * @return string|bool: String when in read-only mode; false otherwise
  */
 function wfReadOnlyReason() {
-       global $wgReadOnly;
-       wfReadOnly();
+       global $wgReadOnly, $wgReadOnlyFile;
+
+       if ( $wgReadOnly === null ) {
+               // Set $wgReadOnly for faster access next time
+               if ( is_file( $wgReadOnlyFile ) && filesize( $wgReadOnlyFile ) > 0 ) {
+                       $wgReadOnly = file_get_contents( $wgReadOnlyFile );
+               } else {
+                       $wgReadOnly = false;
+               }
+       }
+
        return $wgReadOnly;
 }