Make DB handles inherit configured read-only mode
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 8f2d43b..cda3154 100644 (file)
@@ -1355,24 +1355,14 @@ function wfReadOnlyReason() {
                return $readOnly;
        }
 
-       static $autoReadOnly = null;
-       if ( $autoReadOnly === null ) {
+       static $lbReadOnly = null;
+       if ( $lbReadOnly === null ) {
                // Callers use this method to be aware that data presented to a user
                // may be very stale and thus allowing submissions can be problematic.
-               try {
-                       if ( wfGetLB()->getLaggedSlaveMode() ) {
-                               $autoReadOnly = 'The database has been automatically locked ' .
-                                       'while the slave database servers catch up to the master';
-                       } else {
-                               $autoReadOnly = false;
-                       }
-               } catch ( DBConnectionError $e ) {
-                       $autoReadOnly = 'The database has been automatically locked ' .
-                               'until the slave database servers become available';
-               }
+               $lbReadOnly = wfGetLB()->getReadOnlyReason();
        }
 
-       return $autoReadOnly;
+       return $lbReadOnly;
 }
 
 /**
@@ -3558,11 +3548,10 @@ function wfGetPrecompiledData( $name ) {
  * @return string
  */
 function wfMemcKey( /*...*/ ) {
-       global $wgCachePrefix;
-       $prefix = $wgCachePrefix === false ? wfWikiID() : $wgCachePrefix;
-       $args = func_get_args();
-       $key = $prefix . ':' . implode( ':', $args );
-       return strtr( $key, ' ', '_' );
+       return call_user_func_array(
+               array( ObjectCache::getLocalClusterInstance(), 'makeKey' ),
+               func_get_args()
+       );
 }
 
 /**
@@ -3577,13 +3566,11 @@ function wfMemcKey( /*...*/ ) {
  */
 function wfForeignMemcKey( $db, $prefix /*...*/ ) {
        $args = array_slice( func_get_args(), 2 );
-       if ( $prefix ) {
-               // Match wfWikiID() logic
-               $key = "$db-$prefix:" . implode( ':', $args );
-       } else {
-               $key = $db . ':' . implode( ':', $args );
-       }
-       return strtr( $key, ' ', '_' );
+       $keyspace = $prefix ? "$db-$prefix" : $db;
+       return call_user_func_array(
+               array( ObjectCache::getLocalClusterInstance(), 'makeKeyInternal' ),
+               array( $keyspace, $args )
+       );
 }
 
 /**
@@ -3598,9 +3585,10 @@ function wfForeignMemcKey( $db, $prefix /*...*/ ) {
  * @return string
  */
 function wfGlobalCacheKey( /*...*/ ) {
-       $args = func_get_args();
-       $key = 'global:' . implode( ':', $args );
-       return strtr( $key, ' ', '_' );
+       return call_user_func_array(
+               array( ObjectCache::getLocalClusterInstance(), 'makeGlobalKey' ),
+               func_get_args()
+       );
 }
 
 /**
@@ -3940,12 +3928,13 @@ function wfTransactionalTimeLimit() {
  * Converts shorthand byte notation to integer form
  *
  * @param string $string
+ * @param int $default Returned if $string is empty
  * @return int
  */
-function wfShorthandToInteger( $string = '' ) {
+function wfShorthandToInteger( $string = '', $default = -1 ) {
        $string = trim( $string );
        if ( $string === '' ) {
-               return -1;
+               return $default;
        }
        $last = $string[strlen( $string ) - 1];
        $val = intval( $string );