* @param string $file Filename
* @param array $context Additional logging context data
* @throws MWException
- * @deprecated since 1.25 Use MediaWiki\Logger\LegacyLogger::emit or UDPTransport
+ * @deprecated since 1.25 Use \\MediaWiki\\Logger\\LegacyLogger::emit or UDPTransport
*/
function wfErrorLog( $text, $file, array $context = array() ) {
wfDeprecated( __METHOD__, '1.25' );
}
/**
- * Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
+ * Check if the site is in read-only mode and return the message if so
+ *
+ * This checks wfConfiguredReadOnlyReason() and the main load balancer
+ * for slave lag. This may result in DB_SLAVE connection being made.
*
* @return string|bool String when in read-only mode; false otherwise
*/
function wfReadOnlyReason() {
- global $wgReadOnly, $wgReadOnlyFile;
+ $readOnly = wfConfiguredReadOnlyReason();
+ if ( $readOnly !== false ) {
+ return $readOnly;
+ }
- 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;
- }
+ static $autoReadOnly = null;
+ if ( $autoReadOnly === 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 ( $wgReadOnly === false && wfGetLB()->getLaggedSlaveMode() ) {
- $wgReadOnly = 'The database has been automatically locked ' .
+ 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 ) {
- $wgReadOnly = 'The database has been automatically locked ' .
+ $autoReadOnly = 'The database has been automatically locked ' .
'until the slave database servers become available';
}
}
+ return $autoReadOnly;
+}
+
+/**
+ * Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
+ *
+ * @return string|bool String when in read-only mode; false otherwise
+ * @since 1.27
+ */
+function wfConfiguredReadOnlyReason() {
+ 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;
}
* @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::getMainClusterInstance(), 'makeKey' ),
+ func_get_args()
+ );
}
/**
*/
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::getMainClusterInstance(), 'makeKeyInternal' ),
+ array( $keyspace, $args )
+ );
}
/**
* @return string
*/
function wfGlobalCacheKey( /*...*/ ) {
- $args = func_get_args();
- $key = 'global:' . implode( ':', $args );
- return strtr( $key, ' ', '_' );
+ return call_user_func_array(
+ array( ObjectCache::getMainClusterInstance(), 'makeGlobalKey' ),
+ func_get_args()
+ );
}
/**
return $bits;
}
-/**
- * @see $wgDataCenterRoles
- * @return string The current cluster ID
- * @since 1.27
- */
-function wfDataCenter() {
- global $wgDataCenterId;
-
- return $wgDataCenterId;
-}
-
-/**
- * @see $wgDataCenterRoles
- * @return string The current cluster role; one of (master/slave)
- * @since 1.27
- */
-function wfDataCenterRole() {
- global $wgDataCenterId, $wgDataCenterRoles;
-
- return $wgDataCenterRoles[$wgDataCenterId];
-}
-
/**
* Get a Database object.
*
/**
* Get the path to a specified script file, respecting file
- * extensions; this is a wrapper around $wgScriptExtension etc.
+ * extensions; this is a wrapper around $wgScriptPath etc.
* except for 'index' and 'load' which use $wgScript/$wgLoadScript
*
* @param string $script Script filename, sans extension
* @return string
*/
function wfScript( $script = 'index' ) {
- global $wgScriptPath, $wgScriptExtension, $wgScript, $wgLoadScript;
+ global $wgScriptPath, $wgScript, $wgLoadScript;
if ( $script === 'index' ) {
return $wgScript;
} elseif ( $script === 'load' ) {
return $wgLoadScript;
} else {
- return "{$wgScriptPath}/{$script}{$wgScriptExtension}";
+ return "{$wgScriptPath}/{$script}.php";
}
}