r81027 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81026‎ | r81027 | r81028 >
Date:15:42, 26 January 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* Replaced $wgMessageCache by MessageCache::singleton(); since we only use one instance of this class (as for ParserCache, LinkCache)
* 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
Modified paths:
  • /trunk/extensions/ErrorHandler/ErrorHandler.php (modified) (history)
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)
  • /trunk/phase3/docs/globals.txt (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/LocalisationCache.php (modified) (history)
  • /trunk/phase3/includes/Message.php (modified) (history)
  • /trunk/phase3/includes/MessageCache.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTest.inc (modified) (history)
  • /trunk/phase3/tests/phpunit/bootstrap.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/MessageTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/TitlePermissionTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/suites/UploadFromUrlTestSuite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/globals.txt
@@ -68,6 +68,3 @@
6969
7070 $wgMemc, $messageMemc, $parserMemc
7171 Object caches
72 -
73 -$wgMessageCache
74 - Message cache, to manage interface messages
Index: trunk/phase3/tests/phpunit/bootstrap.php
@@ -28,14 +28,12 @@
2929 EOF;
3030 }
3131
32 -global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
33 -global $wgMessageCache, $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgMemc;
 32+global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgUseDatabaseMessages, $wgMemc;
3433 $wgMainCacheType = CACHE_NONE;
3534 $wgMessageCacheType = CACHE_NONE;
3635 $wgParserCacheType = CACHE_NONE;
3736 $wgUseDatabaseMessages = false; # Set for future resets
3837 $wgMemc = new FakeMemCachedClient;
3938
40 -# The message cache was already created in Setup.php
41 -$wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
42 - array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry ) );
 39+/** @todo Check if this is really needed */
 40+MessageCache::destroyInstance();
Index: trunk/phase3/tests/phpunit/includes/MessageTest.php
@@ -3,12 +3,12 @@
44 class MessageTest extends MediaWikiTestCase {
55
66 function setUp() {
7 - global $wgLanguageCode, $wgLang, $wgContLang, $wgMessageCache;
 7+ global $wgLanguageCode, $wgLang, $wgContLang;
88
99 $wgLanguageCode = 'en'; # For mainpage to be 'Main Page'
1010 //Note that a Stub Object is not enough for this test
1111 $wgContLang = $wgLang = Language::factory( $wgLanguageCode );
12 - $wgMessageCache = new MessageCache( false, false, 3600 );
 12+ MessageCache::singleton()->disable();
1313 }
1414
1515 function testExists() {
Index: trunk/phase3/tests/phpunit/includes/TitlePermissionTest.php
@@ -13,12 +13,11 @@
1414 protected $altUserName;
1515
1616 function setUp() {
17 - global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang, $wgMessageCache;
 17+ global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
1818
1919 if(!$wgMemc) {
2020 $wgMemc = new FakeMemCachedClient;
2121 }
22 - $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
2322 $wgContLang = $wgLang = Language::factory( 'en' );
2423
2524 $this->userName = "Useruser";
Index: trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
@@ -24,7 +24,7 @@
2525 //PHPUnit + MediaWikiTestCase functions
2626
2727 function setUp() {
28 - global $wgContLang, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgNamespaceProtection, $wgNamespaceAliases, $IP, $messageMemc;
 28+ global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases, $IP;
2929 $wgContLang = Language::factory( 'en' );
3030
3131 //Setup CLI arguments
@@ -58,7 +58,7 @@
5959 $tmpGlobals['wgEnableParserCache'] = false;
6060 $tmpGlobals['wgDeferredUpdateList'] = array();
6161 $tmpGlobals['wgMemc'] = &wfGetMainCache();
62 - $messageMemc = &wfGetMessageCacheStorage();
 62+ $tmpGlobals['messageMemc'] = &wfGetMessageCacheStorage();
6363 $tmpGlobals['parserMemc'] = &wfGetParserCacheStorage();
6464
6565 // $tmpGlobals['wgContLang'] = new StubContLang;
@@ -68,9 +68,6 @@
6969 $tmpGlobals['wgParser'] = new StubObject( 'wgParser', $GLOBALS['wgParserConf']['class'], array( $GLOBALS['wgParserConf'] ) );
7070 $tmpGlobals['wgRequest'] = new WebRequest;
7171
72 - $tmpGlobals['wgMessageCache'] = new StubObject( 'wgMessageCache', 'MessageCache',
73 - array( $messageMemc, $wgUseDatabaseMessages,
74 - $wgMsgCacheExpiry ) );
7572 if ( $GLOBALS['wgStyleDirectory'] === false ) {
7673 $tmpGlobals['wgStyleDirectory'] = "$IP/skins";
7774 }
@@ -150,9 +147,8 @@
151148 # Reinitialise the LocalisationCache to match the database state
152149 Language::getLocalisationCache()->unloadAll();
153150
154 - # Make a new message cache
155 - global $wgMessageCache, $wgMemc;
156 - $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
 151+ # Clear the message cache
 152+ MessageCache::singleton()->clear();
157153
158154 $this->uploadDir = $this->setupUploadDir();
159155
Index: trunk/phase3/tests/phpunit/suites/UploadFromUrlTestSuite.php
@@ -16,9 +16,8 @@
1717 function setUp() {
1818 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
1919 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
20 - $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
2120 $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
22 - $wgThumbnailScriptPath, $wgScriptPath,
 21+ $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
2322 $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
2423
2524 $wgScript = '/index.php';
@@ -54,9 +53,6 @@
5554 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
5655 $wgRequest = new WebRequest;
5756
58 - $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
59 - array( $messageMemc, $wgUseDatabaseMessages,
60 - $wgMsgCacheExpiry ) );
6157 if ( $wgStyleDirectory === false ) {
6258 $wgStyleDirectory = "$IP/skins";
6359 }
Index: trunk/phase3/tests/parser/parserTest.inc
@@ -134,9 +134,8 @@
135135 static function setUp() {
136136 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
137137 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
138 - $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
139138 $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
140 - $wgThumbnailScriptPath, $wgScriptPath,
 139+ $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
141140 $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
142141
143142 $wgScript = '/index.php';
@@ -172,9 +171,6 @@
173172 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
174173 $wgRequest = new WebRequest;
175174
176 - $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
177 - array( $messageMemc, $wgUseDatabaseMessages,
178 - $wgMsgCacheExpiry ) );
179175 if ( $wgStyleDirectory === false ) {
180176 $wgStyleDirectory = "$IP/skins";
181177 }
@@ -821,9 +817,8 @@
822818 # Reinitialise the LocalisationCache to match the database state
823819 Language::getLocalisationCache()->unloadAll();
824820
825 - # Make a new message cache
826 - global $wgMessageCache, $wgMemc;
827 - $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
 821+ # Clear the message cache
 822+ MessageCache::singleton()->clear();
828823
829824 $this->uploadDir = $this->setupUploadDir();
830825 $user = User::createNew( 'WikiSysop' );
Index: trunk/phase3/includes/Article.php
@@ -249,7 +249,7 @@
250250 * @return Return the text of this revision
251251 */
252252 public function getContent() {
253 - global $wgUser, $wgContLang, $wgMessageCache;
 253+ global $wgUser, $wgContLang;
254254
255255 wfProfileIn( __METHOD__ );
256256
@@ -258,7 +258,7 @@
259259 # and return the message value for x.
260260 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
261261 # If this is a system message, get the default text.
262 - list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
 262+ list( $message, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
263263 $text = wfMsgGetKey( $message, false, $lang, false );
264264
265265 if ( wfEmptyMsg( $message, $text ) )
@@ -1712,15 +1712,13 @@
17131713 }
17141714
17151715 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1716 - global $wgMessageCache;
1717 -
17181716 if ( $this->getID() == 0 ) {
17191717 $text = false;
17201718 } else {
17211719 $text = $this->getRawText();
17221720 }
17231721
1724 - $wgMessageCache->replace( $this->mTitle->getDBkey(), $text );
 1722+ MessageCache::singleton()->replace( $this->mTitle->getDBkey(), $text );
17251723 }
17261724 }
17271725
@@ -3632,7 +3630,7 @@
36333631 * @param $user User object: User doing the edit
36343632 */
36353633 public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true, User $user = null ) {
3636 - global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgEnableParserCache;
 3634+ global $wgDeferredUpdateList, $wgUser, $wgEnableParserCache;
36373635
36383636 wfProfileIn( __METHOD__ );
36393637
@@ -3710,7 +3708,7 @@
37113709 }
37123710
37133711 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
3714 - $wgMessageCache->replace( $shortTitle, $text );
 3712+ MessageCache::singleton()->replace( $shortTitle, $text );
37153713 }
37163714
37173715 wfProfileOut( __METHOD__ );
@@ -4051,8 +4049,6 @@
40524050 * Clears caches when article is deleted
40534051 */
40544052 public static function onArticleDelete( $title ) {
4055 - global $wgMessageCache;
4056 -
40574053 # Update existence markers on article/talk tabs...
40584054 if ( $title->isTalkPage() ) {
40594055 $other = $title->getSubjectPage();
@@ -4071,7 +4067,7 @@
40724068
40734069 # Messages
40744070 if ( $title->getNamespace() == NS_MEDIAWIKI ) {
4075 - $wgMessageCache->replace( $title->getDBkey(), false );
 4071+ MessageCache::singleton()->replace( $title->getDBkey(), false );
40764072 }
40774073
40784074 # Images
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -628,19 +628,14 @@
629629 * @return string
630630 */
631631 function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) {
632 - global $wgMessageCache;
633 -
634632 wfRunHooks( 'NormalizeMessageKey', array( &$key, &$useDB, &$langCode, &$transform ) );
635633
636 - if ( !is_object( $wgMessageCache ) ) {
637 - throw new MWException( 'Trying to get message before message cache is initialised' );
638 - }
639 -
640 - $message = $wgMessageCache->get( $key, $useDB, $langCode );
 634+ $cache = MessageCache::singleton();
 635+ $message = $cache->get( $key, $useDB, $langCode );
641636 if( $message === false ) {
642637 $message = '<' . htmlspecialchars( $key ) . '>';
643638 } elseif ( $transform ) {
644 - $message = $wgMessageCache->transform( $message );
 639+ $message = $cache->transform( $message );
645640 }
646641 return $message;
647642 }
@@ -775,11 +770,8 @@
776771 $string = $m[1];
777772 }
778773 } elseif ( in_array( 'parsemag', $options, true ) ) {
779 - global $wgMessageCache;
780 - if ( isset( $wgMessageCache ) ) {
781 - $string = $wgMessageCache->transform( $string,
 774+ $string = MessageCache::singleton()->transform( $string,
782775 !$forContent, $langCodeObj );
783 - }
784776 }
785777
786778 if ( in_array( 'escape', $options, true ) ) {
@@ -2250,8 +2242,7 @@
22512243 * @return Boolean True if the message *doesn't* exist.
22522244 */
22532245 function wfEmptyMsg( $key ) {
2254 - global $wgMessageCache;
2255 - return $wgMessageCache->get( $key, /*useDB*/true, /*content*/false ) === false;
 2246+ return MessageCache::singleton()->get( $key, /*useDB*/true, /*content*/false ) === false;
22562247 }
22572248
22582249 /**
Index: trunk/phase3/includes/LocalisationCache.php
@@ -78,12 +78,6 @@
7979 var $recachedLangs = array();
8080
8181 /**
82 - * Data added by extensions using the deprecated $wgMessageCache->addMessages()
83 - * interface.
84 - */
85 - var $legacyData = array();
86 -
87 - /**
8882 * All item keys
8983 */
9084 static public $allKeys = array(
@@ -215,9 +209,6 @@
216210 * Get a subitem, for instance a single message for a given language.
217211 */
218212 public function getSubitem( $code, $key, $subkey ) {
219 - if ( isset( $this->legacyData[$code][$key][$subkey] ) ) {
220 - return $this->legacyData[$code][$key][$subkey];
221 - }
222213 if ( !isset( $this->loadedSubitems[$code][$key][$subkey] )
223214 && !isset( $this->loadedItems[$code][$key] ) )
224215 {
@@ -663,8 +654,6 @@
664655 unset( $this->loadedItems[$code] );
665656 unset( $this->loadedSubitems[$code] );
666657 unset( $this->initialisedLangs[$code] );
667 - // We don't unload legacyData because there's no way to get it back
668 - // again, it's not really a cache
669658 foreach ( $this->shallowFallbacks as $shallowCode => $fbCode ) {
670659 if ( $fbCode === $code ) {
671660 $this->unload( $shallowCode );
@@ -682,22 +671,6 @@
683672 }
684673
685674 /**
686 - * Add messages to the cache, from an extension that has not yet been
687 - * migrated to $wgExtensionMessages or the LocalisationCacheRecache hook.
688 - * Called by deprecated function $wgMessageCache->addMessages().
689 - */
690 - public function addLegacyMessages( $messages ) {
691 - foreach ( $messages as $lang => $langMessages ) {
692 - if ( isset( $this->legacyData[$lang]['messages'] ) ) {
693 - $this->legacyData[$lang]['messages'] =
694 - $langMessages + $this->legacyData[$lang]['messages'];
695 - } else {
696 - $this->legacyData[$lang]['messages'] = $langMessages;
697 - }
698 - }
699 - }
700 -
701 - /**
702675 * Disable the storage backend
703676 */
704677 public function disableBackend() {
Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -88,7 +88,7 @@
8989 $args = array_slice( func_get_args(), 2 );
9090 $message = wfMsgGetKey( $part1, true, $parser->getOptions()->getUserLang(), false );
9191 $message = wfMsgReplaceArgs( $message, $args );
92 - $message = $parser->replaceVariables( $message ); // like $wgMessageCache->transform()
 92+ $message = $parser->replaceVariables( $message ); // like MessageCache::transform()
9393 return $message;
9494 } else {
9595 return array( 'found' => false );
Index: trunk/phase3/includes/MessageCache.php
@@ -62,6 +62,34 @@
6363 */
6464 protected static $mAdaptiveInclusionThreshold = 0.05;
6565
 66+ /**
 67+ * Singleton instance
 68+ */
 69+ private static $instance;
 70+
 71+ /**
 72+ * Get the signleton instance of this class
 73+ *
 74+ * @since 1.18
 75+ * @return MessageCache object
 76+ */
 77+ public static function singleton() {
 78+ if ( is_null( self::$instance ) ) {
 79+ global $wgUseDatabaseMessages, $wgMsgCacheExpiry;
 80+ self::$instance = new self( wfGetMessageCacheStorage(), $wgUseDatabaseMessages, $wgMsgCacheExpiry );
 81+ }
 82+ return self::$instance;
 83+ }
 84+
 85+ /**
 86+ * Destroy the signleton instance
 87+ *
 88+ * @since 1.18
 89+ */
 90+ public static function destroyInstance() {
 91+ self::$instance = null;
 92+ }
 93+
6694 function __construct( $memCached, $useDB, $expiry ) {
6795 if ( !$memCached ) {
6896 $memCached = wfGetCache( CACHE_NONE );
@@ -729,21 +757,6 @@
730758 function disable() { $this->mDisable = true; }
731759 function enable() { $this->mDisable = false; }
732760
733 - /** @deprecated */
734 - function disableTransform(){
735 - wfDeprecated( __METHOD__ );
736 - }
737 - function enableTransform() {
738 - wfDeprecated( __METHOD__ );
739 - }
740 - function setTransform( $x ) {
741 - wfDeprecated( __METHOD__ );
742 - }
743 - function getTransform() {
744 - wfDeprecated( __METHOD__ );
745 - return false;
746 - }
747 -
748761 /**
749762 * Clear all stored messages. Mainly used after a mass rebuild.
750763 */
@@ -758,64 +771,6 @@
759772 $this->mLoadedLanguages = array();
760773 }
761774
762 - /**
763 - * Add a message to the cache
764 - * @deprecated Use $wgExtensionMessagesFiles
765 - *
766 - * @param $key Mixed
767 - * @param $value Mixed
768 - * @param $lang String: the messages language, English by default
769 - */
770 - function addMessage( $key, $value, $lang = 'en' ) {
771 - wfDeprecated( __METHOD__ );
772 - $lc = Language::getLocalisationCache();
773 - $lc->addLegacyMessages( array( $lang => array( $key => $value ) ) );
774 - }
775 -
776 - /**
777 - * Add an associative array of message to the cache
778 - * @deprecated Use $wgExtensionMessagesFiles
779 - *
780 - * @param $messages Array: an associative array of key => values to be added
781 - * @param $lang String: the messages language, English by default
782 - */
783 - function addMessages( $messages, $lang = 'en' ) {
784 - wfDeprecated( __METHOD__ );
785 - $lc = Language::getLocalisationCache();
786 - $lc->addLegacyMessages( array( $lang => $messages ) );
787 - }
788 -
789 - /**
790 - * Add a 2-D array of messages by lang. Useful for extensions.
791 - * @deprecated Use $wgExtensionMessagesFiles
792 - *
793 - * @param $messages Array: the array to be added
794 - */
795 - function addMessagesByLang( $messages ) {
796 - wfDeprecated( __METHOD__ );
797 - $lc = Language::getLocalisationCache();
798 - $lc->addLegacyMessages( $messages );
799 - }
800 -
801 - /**
802 - * Set a hook for addMessagesByLang()
803 - */
804 - function setExtensionMessagesHook( $callback ) {
805 - $this->mAddMessagesHook = $callback;
806 - }
807 -
808 - /**
809 - * @deprecated
810 - */
811 - function loadAllMessages( $lang = false ) {
812 - }
813 -
814 - /**
815 - * @deprecated
816 - */
817 - function loadMessagesFile( $filename, $langcode = false ) {
818 - }
819 -
820775 public function figureMessage( $key ) {
821776 global $wgLanguageCode;
822777 $pieces = explode( '/', $key );
@@ -832,8 +787,8 @@
833788 }
834789
835790 public static function logMessages() {
836 - global $wgMessageCache, $wgAdaptiveMessageCache;
837 - if ( !$wgAdaptiveMessageCache || !$wgMessageCache instanceof MessageCache ) {
 791+ global $wgAdaptiveMessageCache;
 792+ if ( !$wgAdaptiveMessageCache || !self::$instance instanceof MessageCache ) {
838793 return;
839794 }
840795
@@ -852,7 +807,7 @@
853808 $index = substr( wfTimestampNow(), 0, 8 );
854809 if ( !isset( $data[$index] ) ) $data[$index] = array();
855810
856 - foreach ( $wgMessageCache->mRequestedMessages as $message => $_ ) {
 811+ foreach ( self::$instance->mRequestedMessages as $message => $_ ) {
857812 if ( !isset( $data[$index][$message] ) ) $data[$index][$message] = 0;
858813 $data[$index][$message]++;
859814 }
Index: trunk/phase3/includes/db/Database.php
@@ -2897,7 +2897,7 @@
28982898 }
28992899
29002900 function getHTML() {
2901 - global $wgLang, $wgMessageCache, $wgUseFileCache, $wgShowDBErrorBacktrace;
 2901+ global $wgLang, $wgUseFileCache, $wgShowDBErrorBacktrace;
29022902
29032903 $sorry = 'Sorry! This site is experiencing technical difficulties.';
29042904 $again = 'Try waiting a few minutes and reloading.';
@@ -2910,9 +2910,7 @@
29112911 }
29122912
29132913 # No database access
2914 - if ( is_object( $wgMessageCache ) ) {
2915 - $wgMessageCache->disable();
2916 - }
 2914+ MessageCache::singleton()->disable();
29172915
29182916 if ( trim( $this->error ) == '' ) {
29192917 $this->error = $this->db->getProperty( 'mServer' );
Index: trunk/phase3/includes/Setup.php
@@ -387,9 +387,6 @@
388388 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
389389 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
390390
391 -$wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
392 - array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry ) );
393 -
394391 if ( !is_object( $wgAuth ) ) {
395392 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
396393 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
Index: trunk/phase3/includes/EditPage.php
@@ -124,7 +124,7 @@
125125 * @private
126126 */
127127 function getContent( $def_text = '' ) {
128 - global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache;
 128+ global $wgOut, $wgRequest, $wgParser, $wgContLang;
129129
130130 wfProfileIn( __METHOD__ );
131131 # Get variables from query string :P
@@ -141,7 +141,7 @@
142142 if ( !$this->mTitle->exists() ) {
143143 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
144144 # If this is a system message, get the default text.
145 - list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
 145+ list( $message, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
146146 $text = wfMsgGetKey( $message, false, $lang, false );
147147 if( wfEmptyMsg( $message, $text ) )
148148 $text = $this->getPreloadedText( $preload );
@@ -1887,7 +1887,7 @@
18881888 * @return string
18891889 */
18901890 function getPreviewText() {
1891 - global $wgOut, $wgUser, $wgParser, $wgMessageCache;
 1891+ global $wgOut, $wgUser, $wgParser;
18921892
18931893 wfProfileIn( __METHOD__ );
18941894
@@ -1956,7 +1956,7 @@
19571957
19581958 // Parse mediawiki messages with correct target language
19591959 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1960 - list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle->getText() );
 1960+ list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $this->mTitle->getText() );
19611961 $obj = wfGetLangObj( $lang );
19621962 $parserOptions->setTargetLanguage( $obj );
19631963 }
Index: trunk/phase3/includes/Title.php
@@ -3193,20 +3193,19 @@
31943194 $u->doUpdate();
31953195 }
31963196 # Update message cache for interface messages
3197 - global $wgMessageCache;
31983197 if ( $this->getNamespace() == NS_MEDIAWIKI ) {
31993198 # @bug 17860: old article can be deleted, if this the case,
32003199 # delete it from message cache
32013200 if ( $this->getArticleID() === 0 ) {
3202 - $wgMessageCache->replace( $this->getDBkey(), false );
 3201+ MessageCache::singleton()->replace( $this->getDBkey(), false );
32033202 } else {
32043203 $oldarticle = new Article( $this );
3205 - $wgMessageCache->replace( $this->getDBkey(), $oldarticle->getContent() );
 3204+ MessageCache::singleton()->replace( $this->getDBkey(), $oldarticle->getContent() );
32063205 }
32073206 }
32083207 if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
32093208 $newarticle = new Article( $nt );
3210 - $wgMessageCache->replace( $nt->getDBkey(), $newarticle->getContent() );
 3209+ MessageCache::singleton()->replace( $nt->getDBkey(), $newarticle->getContent() );
32113210 }
32123211
32133212 global $wgUser;
Index: trunk/phase3/includes/Message.php
@@ -385,8 +385,7 @@
386386 * @return Wikitext with {{-constructs replaced with their values.
387387 */
388388 protected function transformText( $string ) {
389 - global $wgMessageCache;
390 - return $wgMessageCache->transform( $string, $this->interface, $this->language );
 389+ return MessageCache::singleton()->transform( $string, $this->interface, $this->language );
391390 }
392391
393392 /**
@@ -407,17 +406,17 @@
408407 */
409408 protected function fetchMessage() {
410409 if ( !isset( $this->message ) ) {
411 - global $wgMessageCache;
 410+ $cache = MessageCache::singleton();
412411 if ( is_array($this->key) ) {
413412 foreach ( $this->key as $key ) {
414 - $message = $wgMessageCache->get( $key, $this->useDatabase, $this->language );
 413+ $message = $cache->get( $key, $this->useDatabase, $this->language );
415414 if ( $message !== false && $message !== '' ) {
416415 break;
417416 }
418417 }
419418 $this->message = $message;
420419 } else {
421 - $this->message = $wgMessageCache->get( $this->key, $this->useDatabase, $this->language );
 420+ $this->message = $cache->get( $this->key, $this->useDatabase, $this->language );
422421 }
423422 }
424423 return $this->message;
Index: trunk/phase3/languages/LanguageConverter.php
@@ -842,13 +842,8 @@
843843 *
844844 */
845845 function parseCachedTable( $code, $subpage = '', $recursive = true ) {
846 - global $wgMessageCache;
847846 static $parsed = array();
848847
849 - if ( !is_object( $wgMessageCache ) ) {
850 - return array();
851 - }
852 -
853848 $key = 'Conversiontable/' . $code;
854849 if ( $subpage ) {
855850 $key .= '/' . $subpage;
@@ -858,7 +853,7 @@
859854 }
860855
861856 if ( strpos( $code, '/' ) === false ) {
862 - $txt = $wgMessageCache->get( 'Conversiontable', true, $code );
 857+ $txt = MessageCache::singleton()->get( 'Conversiontable', true, $code );
863858 if ( $txt === false ) {
864859 # FIXME: this method doesn't seem to be expecting
865860 # this possible outcome...
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -44,8 +44,13 @@
4545 $parser->getOptions()->setTargetLanguage( Language::factory( $code ) );
4646 $name = $page->getPageDisplayTitle( $code );
4747 if ( $name ) {
48 - global $wgMessageCache;
49 - $name = $wgMessageCache->transform( $name, false, Language::factory( $code ) );
 48+ if ( method_exists( 'MessageCache', 'singleton' ) ) {
 49+ $cache = MessageCache::singleton();
 50+ } else {
 51+ global $wgMessageCache;
 52+ $cache = $wgMessageCache;
 53+ }
 54+ $name = $cache->transform( $name, false, Language::factory( $code ) );
5055 $parser->getOutput()->setDisplayTitle( $name );
5156 }
5257 }
Index: trunk/extensions/ErrorHandler/ErrorHandler.php
@@ -206,16 +206,8 @@
207207 */
208208 function efErrorHandlerGetMessage(){
209209 static $messages = false;
210 - static $loaded = false;
211210 $args = func_get_args();
212 - if( !$loaded ){
213 - global $wgMessageCache;
214 - if( function_exists( 'wfMsgExt' ) && is_object( $wgMessageCache ) ){
215 - $loaded = true;
216 - wfLoadExtensionMessages( 'ErrorHandler' );
217 - }
218 - }
219 - if( $loaded ){
 211+ if( function_exists( 'wfMsgExt' ) ){
220212 global $wgTitle;
221213 $msg = array_shift( $args );
222214 $opts = array( 'replaceafter' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r87409ProtectSite: $wgMessageCache is dead and addMessages() was removed in r81027....ashley16:22, 4 May 2011
r110204bug fix, $wgMessageCache and MessageCache::addMessages() don't exist anymore ...ning09:17, 28 January 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   01:29, 15 June 2011

Did you see r76110? Not sure how much b/c Yaron keep here.

#Comment by Aaron Schulz (talk | contribs)   01:37, 15 June 2011

The static logMessages() is slightly awkward.

Status & tagging log