* MessageCache::singleton() calls wfGetMessageCacheStorage() directly instead of using $messageMemc, just in case this would be called before that variable is set
* Per TimStarling: also removed deprecated methods in MessageCache class: addMessages() and related, [get|set|enable|disable]Transform(), loadAllMessages(), loadMessageFile() and some others. Same for the legacyData stuff in LocalisationCache that was only used by MessageCache::addMessages() and related.
* Converted remaining extensions
$wgMemc, $messageMemc, $parserMemc
Object caches
-
-$wgMessageCache
- Message cache, to manage interface messages
* @return Return the text of this revision
*/
public function getContent() {
- global $wgUser, $wgContLang, $wgMessageCache;
+ global $wgUser, $wgContLang;
wfProfileIn( __METHOD__ );
# and return the message value for x.
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
# If this is a system message, get the default text.
- list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
+ list( $message, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
$text = wfMsgGetKey( $message, false, $lang, false );
if ( wfEmptyMsg( $message, $text ) )
}
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
- global $wgMessageCache;
-
if ( $this->getID() == 0 ) {
$text = false;
} else {
$text = $this->getRawText();
}
- $wgMessageCache->replace( $this->mTitle->getDBkey(), $text );
+ MessageCache::singleton()->replace( $this->mTitle->getDBkey(), $text );
}
}
* @param $user User object: User doing the edit
*/
public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true, User $user = null ) {
- global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgEnableParserCache;
+ global $wgDeferredUpdateList, $wgUser, $wgEnableParserCache;
wfProfileIn( __METHOD__ );
}
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
- $wgMessageCache->replace( $shortTitle, $text );
+ MessageCache::singleton()->replace( $shortTitle, $text );
}
wfProfileOut( __METHOD__ );
* Clears caches when article is deleted
*/
public static function onArticleDelete( $title ) {
- global $wgMessageCache;
-
# Update existence markers on article/talk tabs...
if ( $title->isTalkPage() ) {
$other = $title->getSubjectPage();
# Messages
if ( $title->getNamespace() == NS_MEDIAWIKI ) {
- $wgMessageCache->replace( $title->getDBkey(), false );
+ MessageCache::singleton()->replace( $title->getDBkey(), false );
}
# Images
* @private
*/
function getContent( $def_text = '' ) {
- global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache;
+ global $wgOut, $wgRequest, $wgParser, $wgContLang;
wfProfileIn( __METHOD__ );
# Get variables from query string :P
if ( !$this->mTitle->exists() ) {
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
# If this is a system message, get the default text.
- list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
+ list( $message, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
$text = wfMsgGetKey( $message, false, $lang, false );
if( wfEmptyMsg( $message, $text ) )
$text = $this->getPreloadedText( $preload );
* @return string
*/
function getPreviewText() {
- global $wgOut, $wgUser, $wgParser, $wgMessageCache;
+ global $wgOut, $wgUser, $wgParser;
wfProfileIn( __METHOD__ );
// Parse mediawiki messages with correct target language
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
- list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle->getText() );
+ list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $this->mTitle->getText() );
$obj = wfGetLangObj( $lang );
$parserOptions->setTargetLanguage( $obj );
}
* @return string
*/
function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) {
- global $wgMessageCache;
-
wfRunHooks( 'NormalizeMessageKey', array( &$key, &$useDB, &$langCode, &$transform ) );
- if ( !is_object( $wgMessageCache ) ) {
- throw new MWException( 'Trying to get message before message cache is initialised' );
- }
-
- $message = $wgMessageCache->get( $key, $useDB, $langCode );
+ $cache = MessageCache::singleton();
+ $message = $cache->get( $key, $useDB, $langCode );
if( $message === false ) {
$message = '<' . htmlspecialchars( $key ) . '>';
} elseif ( $transform ) {
- $message = $wgMessageCache->transform( $message );
+ $message = $cache->transform( $message );
}
return $message;
}
$string = $m[1];
}
} elseif ( in_array( 'parsemag', $options, true ) ) {
- global $wgMessageCache;
- if ( isset( $wgMessageCache ) ) {
- $string = $wgMessageCache->transform( $string,
+ $string = MessageCache::singleton()->transform( $string,
!$forContent, $langCodeObj );
- }
}
if ( in_array( 'escape', $options, true ) ) {
* @return Boolean True if the message *doesn't* exist.
*/
function wfEmptyMsg( $key ) {
- global $wgMessageCache;
- return $wgMessageCache->get( $key, /*useDB*/true, /*content*/false ) === false;
+ return MessageCache::singleton()->get( $key, /*useDB*/true, /*content*/false ) === false;
}
/**
*/
var $recachedLangs = array();
- /**
- * Data added by extensions using the deprecated $wgMessageCache->addMessages()
- * interface.
- */
- var $legacyData = array();
-
/**
* All item keys
*/
* Get a subitem, for instance a single message for a given language.
*/
public function getSubitem( $code, $key, $subkey ) {
- if ( isset( $this->legacyData[$code][$key][$subkey] ) ) {
- return $this->legacyData[$code][$key][$subkey];
- }
if ( !isset( $this->loadedSubitems[$code][$key][$subkey] )
&& !isset( $this->loadedItems[$code][$key] ) )
{
unset( $this->loadedItems[$code] );
unset( $this->loadedSubitems[$code] );
unset( $this->initialisedLangs[$code] );
- // We don't unload legacyData because there's no way to get it back
- // again, it's not really a cache
foreach ( $this->shallowFallbacks as $shallowCode => $fbCode ) {
if ( $fbCode === $code ) {
$this->unload( $shallowCode );
}
}
- /**
- * Add messages to the cache, from an extension that has not yet been
- * migrated to $wgExtensionMessages or the LocalisationCacheRecache hook.
- * Called by deprecated function $wgMessageCache->addMessages().
- */
- public function addLegacyMessages( $messages ) {
- foreach ( $messages as $lang => $langMessages ) {
- if ( isset( $this->legacyData[$lang]['messages'] ) ) {
- $this->legacyData[$lang]['messages'] =
- $langMessages + $this->legacyData[$lang]['messages'];
- } else {
- $this->legacyData[$lang]['messages'] = $langMessages;
- }
- }
- }
-
/**
* Disable the storage backend
*/
* @return Wikitext with {{-constructs replaced with their values.
*/
protected function transformText( $string ) {
- global $wgMessageCache;
- return $wgMessageCache->transform( $string, $this->interface, $this->language );
+ return MessageCache::singleton()->transform( $string, $this->interface, $this->language );
}
/**
*/
protected function fetchMessage() {
if ( !isset( $this->message ) ) {
- global $wgMessageCache;
+ $cache = MessageCache::singleton();
if ( is_array($this->key) ) {
foreach ( $this->key as $key ) {
- $message = $wgMessageCache->get( $key, $this->useDatabase, $this->language );
+ $message = $cache->get( $key, $this->useDatabase, $this->language );
if ( $message !== false && $message !== '' ) {
break;
}
}
$this->message = $message;
} else {
- $this->message = $wgMessageCache->get( $this->key, $this->useDatabase, $this->language );
+ $this->message = $cache->get( $this->key, $this->useDatabase, $this->language );
}
}
return $this->message;
*/
protected static $mAdaptiveInclusionThreshold = 0.05;
+ /**
+ * Singleton instance
+ */
+ private static $instance;
+
+ /**
+ * Get the signleton instance of this class
+ *
+ * @since 1.18
+ * @return MessageCache object
+ */
+ public static function singleton() {
+ if ( is_null( self::$instance ) ) {
+ global $wgUseDatabaseMessages, $wgMsgCacheExpiry;
+ self::$instance = new self( wfGetMessageCacheStorage(), $wgUseDatabaseMessages, $wgMsgCacheExpiry );
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Destroy the signleton instance
+ *
+ * @since 1.18
+ */
+ public static function destroyInstance() {
+ self::$instance = null;
+ }
+
function __construct( $memCached, $useDB, $expiry ) {
if ( !$memCached ) {
$memCached = wfGetCache( CACHE_NONE );
function disable() { $this->mDisable = true; }
function enable() { $this->mDisable = false; }
- /** @deprecated */
- function disableTransform(){
- wfDeprecated( __METHOD__ );
- }
- function enableTransform() {
- wfDeprecated( __METHOD__ );
- }
- function setTransform( $x ) {
- wfDeprecated( __METHOD__ );
- }
- function getTransform() {
- wfDeprecated( __METHOD__ );
- return false;
- }
-
/**
* Clear all stored messages. Mainly used after a mass rebuild.
*/
$this->mLoadedLanguages = array();
}
- /**
- * Add a message to the cache
- * @deprecated Use $wgExtensionMessagesFiles
- *
- * @param $key Mixed
- * @param $value Mixed
- * @param $lang String: the messages language, English by default
- */
- function addMessage( $key, $value, $lang = 'en' ) {
- wfDeprecated( __METHOD__ );
- $lc = Language::getLocalisationCache();
- $lc->addLegacyMessages( array( $lang => array( $key => $value ) ) );
- }
-
- /**
- * Add an associative array of message to the cache
- * @deprecated Use $wgExtensionMessagesFiles
- *
- * @param $messages Array: an associative array of key => values to be added
- * @param $lang String: the messages language, English by default
- */
- function addMessages( $messages, $lang = 'en' ) {
- wfDeprecated( __METHOD__ );
- $lc = Language::getLocalisationCache();
- $lc->addLegacyMessages( array( $lang => $messages ) );
- }
-
- /**
- * Add a 2-D array of messages by lang. Useful for extensions.
- * @deprecated Use $wgExtensionMessagesFiles
- *
- * @param $messages Array: the array to be added
- */
- function addMessagesByLang( $messages ) {
- wfDeprecated( __METHOD__ );
- $lc = Language::getLocalisationCache();
- $lc->addLegacyMessages( $messages );
- }
-
- /**
- * Set a hook for addMessagesByLang()
- */
- function setExtensionMessagesHook( $callback ) {
- $this->mAddMessagesHook = $callback;
- }
-
- /**
- * @deprecated
- */
- function loadAllMessages( $lang = false ) {
- }
-
- /**
- * @deprecated
- */
- function loadMessagesFile( $filename, $langcode = false ) {
- }
-
public function figureMessage( $key ) {
global $wgLanguageCode;
$pieces = explode( '/', $key );
}
public static function logMessages() {
- global $wgMessageCache, $wgAdaptiveMessageCache;
- if ( !$wgAdaptiveMessageCache || !$wgMessageCache instanceof MessageCache ) {
+ global $wgAdaptiveMessageCache;
+ if ( !$wgAdaptiveMessageCache || !self::$instance instanceof MessageCache ) {
return;
}
$index = substr( wfTimestampNow(), 0, 8 );
if ( !isset( $data[$index] ) ) $data[$index] = array();
- foreach ( $wgMessageCache->mRequestedMessages as $message => $_ ) {
+ foreach ( self::$instance->mRequestedMessages as $message => $_ ) {
if ( !isset( $data[$index][$message] ) ) $data[$index][$message] = 0;
$data[$index][$message]++;
}
$wgOut = new StubObject( 'wgOut', 'OutputPage' );
$wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
-$wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
- array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry ) );
-
if ( !is_object( $wgAuth ) ) {
$wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
$u->doUpdate();
}
# Update message cache for interface messages
- global $wgMessageCache;
if ( $this->getNamespace() == NS_MEDIAWIKI ) {
# @bug 17860: old article can be deleted, if this the case,
# delete it from message cache
if ( $this->getArticleID() === 0 ) {
- $wgMessageCache->replace( $this->getDBkey(), false );
+ MessageCache::singleton()->replace( $this->getDBkey(), false );
} else {
$oldarticle = new Article( $this );
- $wgMessageCache->replace( $this->getDBkey(), $oldarticle->getContent() );
+ MessageCache::singleton()->replace( $this->getDBkey(), $oldarticle->getContent() );
}
}
if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
$newarticle = new Article( $nt );
- $wgMessageCache->replace( $nt->getDBkey(), $newarticle->getContent() );
+ MessageCache::singleton()->replace( $nt->getDBkey(), $newarticle->getContent() );
}
global $wgUser;
}
function getHTML() {
- global $wgLang, $wgMessageCache, $wgUseFileCache, $wgShowDBErrorBacktrace;
+ global $wgLang, $wgUseFileCache, $wgShowDBErrorBacktrace;
$sorry = 'Sorry! This site is experiencing technical difficulties.';
$again = 'Try waiting a few minutes and reloading.';
}
# No database access
- if ( is_object( $wgMessageCache ) ) {
- $wgMessageCache->disable();
- }
+ MessageCache::singleton()->disable();
if ( trim( $this->error ) == '' ) {
$this->error = $this->db->getProperty( 'mServer' );
$args = array_slice( func_get_args(), 2 );
$message = wfMsgGetKey( $part1, true, $parser->getOptions()->getUserLang(), false );
$message = wfMsgReplaceArgs( $message, $args );
- $message = $parser->replaceVariables( $message ); // like $wgMessageCache->transform()
+ $message = $parser->replaceVariables( $message ); // like MessageCache::transform()
return $message;
} else {
return array( 'found' => false );
*
*/
function parseCachedTable( $code, $subpage = '', $recursive = true ) {
- global $wgMessageCache;
static $parsed = array();
- if ( !is_object( $wgMessageCache ) ) {
- return array();
- }
-
$key = 'Conversiontable/' . $code;
if ( $subpage ) {
$key .= '/' . $subpage;
}
if ( strpos( $code, '/' ) === false ) {
- $txt = $wgMessageCache->get( 'Conversiontable', true, $code );
+ $txt = MessageCache::singleton()->get( 'Conversiontable', true, $code );
if ( $txt === false ) {
# FIXME: this method doesn't seem to be expecting
# this possible outcome...
static function setUp() {
global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
$wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
- $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
$wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
- $wgThumbnailScriptPath, $wgScriptPath,
+ $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
$wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
$wgScript = '/index.php';
$wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
$wgRequest = new WebRequest;
- $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
- array( $messageMemc, $wgUseDatabaseMessages,
- $wgMsgCacheExpiry ) );
if ( $wgStyleDirectory === false ) {
$wgStyleDirectory = "$IP/skins";
}
# Reinitialise the LocalisationCache to match the database state
Language::getLocalisationCache()->unloadAll();
- # Make a new message cache
- global $wgMessageCache, $wgMemc;
- $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
+ # Clear the message cache
+ MessageCache::singleton()->clear();
$this->uploadDir = $this->setupUploadDir();
$user = User::createNew( 'WikiSysop' );
EOF;
}
-global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
-global $wgMessageCache, $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgMemc;
+global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgUseDatabaseMessages, $wgMemc;
$wgMainCacheType = CACHE_NONE;
$wgMessageCacheType = CACHE_NONE;
$wgParserCacheType = CACHE_NONE;
$wgUseDatabaseMessages = false; # Set for future resets
$wgMemc = new FakeMemCachedClient;
-# The message cache was already created in Setup.php
-$wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
- array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry ) );
+/** @todo Check if this is really needed */
+MessageCache::destroyInstance();
class MessageTest extends MediaWikiTestCase {
function setUp() {
- global $wgLanguageCode, $wgLang, $wgContLang, $wgMessageCache;
+ global $wgLanguageCode, $wgLang, $wgContLang;
$wgLanguageCode = 'en'; # For mainpage to be 'Main Page'
//Note that a Stub Object is not enough for this test
$wgContLang = $wgLang = Language::factory( $wgLanguageCode );
- $wgMessageCache = new MessageCache( false, false, 3600 );
+ MessageCache::singleton()->disable();
}
function testExists() {
protected $altUserName;
function setUp() {
- global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang, $wgMessageCache;
+ global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
if(!$wgMemc) {
$wgMemc = new FakeMemCachedClient;
}
- $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
$wgContLang = $wgLang = Language::factory( 'en' );
$this->userName = "Useruser";
//PHPUnit + MediaWikiTestCase functions
function setUp() {
- global $wgContLang, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgNamespaceProtection, $wgNamespaceAliases, $IP, $messageMemc;
+ global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases, $IP;
$wgContLang = Language::factory( 'en' );
//Setup CLI arguments
$tmpGlobals['wgEnableParserCache'] = false;
$tmpGlobals['wgDeferredUpdateList'] = array();
$tmpGlobals['wgMemc'] = &wfGetMainCache();
- $messageMemc = &wfGetMessageCacheStorage();
+ $tmpGlobals['messageMemc'] = &wfGetMessageCacheStorage();
$tmpGlobals['parserMemc'] = &wfGetParserCacheStorage();
// $tmpGlobals['wgContLang'] = new StubContLang;
$tmpGlobals['wgParser'] = new StubObject( 'wgParser', $GLOBALS['wgParserConf']['class'], array( $GLOBALS['wgParserConf'] ) );
$tmpGlobals['wgRequest'] = new WebRequest;
- $tmpGlobals['wgMessageCache'] = new StubObject( 'wgMessageCache', 'MessageCache',
- array( $messageMemc, $wgUseDatabaseMessages,
- $wgMsgCacheExpiry ) );
if ( $GLOBALS['wgStyleDirectory'] === false ) {
$tmpGlobals['wgStyleDirectory'] = "$IP/skins";
}
# Reinitialise the LocalisationCache to match the database state
Language::getLocalisationCache()->unloadAll();
- # Make a new message cache
- global $wgMessageCache, $wgMemc;
- $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
+ # Clear the message cache
+ MessageCache::singleton()->clear();
$this->uploadDir = $this->setupUploadDir();
function setUp() {
global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
$wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
- $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
$wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
- $wgThumbnailScriptPath, $wgScriptPath,
+ $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
$wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
$wgScript = '/index.php';
$wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
$wgRequest = new WebRequest;
- $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
- array( $messageMemc, $wgUseDatabaseMessages,
- $wgMsgCacheExpiry ) );
if ( $wgStyleDirectory === false ) {
$wgStyleDirectory = "$IP/skins";
}