Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -2975,7 +2975,11 @@ |
2976 | 2976 | * @return null |
2977 | 2977 | */ |
2978 | 2978 | function wfDeprecated( $function ) { |
2979 | | - wfWarn( "Use of $function is deprecated.", 2 ); |
| 2979 | + static $functionsWarned = array(); |
| 2980 | + if ( !isset( $functionsWarned[$function] ) ) { |
| 2981 | + $functionsWarned[$function] = true; |
| 2982 | + wfWarn( "Use of $function is deprecated.", 2 ); |
| 2983 | + } |
2980 | 2984 | } |
2981 | 2985 | |
2982 | 2986 | function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) { |
Index: trunk/phase3/includes/LocalisationCache.php |
— | — | @@ -78,6 +78,12 @@ |
79 | 79 | var $recachedLangs = array(); |
80 | 80 | |
81 | 81 | /** |
| 82 | + * Data added by extensions using the deprecated $wgMessageCache->addMessages() |
| 83 | + * interface. |
| 84 | + */ |
| 85 | + var $legacyData = array(); |
| 86 | + |
| 87 | + /** |
82 | 88 | * All item keys |
83 | 89 | */ |
84 | 90 | static public $allKeys = array( |
— | — | @@ -137,10 +143,6 @@ |
138 | 144 | global $wgCacheDirectory; |
139 | 145 | |
140 | 146 | $this->conf = $conf; |
141 | | - $this->data = array(); |
142 | | - $this->loadedItems = array(); |
143 | | - $this->loadedSubitems = array(); |
144 | | - $this->initialisedLangs = array(); |
145 | 147 | if ( !empty( $conf['storeClass'] ) ) { |
146 | 148 | $storeClass = $conf['storeClass']; |
147 | 149 | } else { |
— | — | @@ -208,6 +210,9 @@ |
209 | 211 | * Get a subitem, for instance a single message for a given language. |
210 | 212 | */ |
211 | 213 | public function getSubitem( $code, $key, $subkey ) { |
| 214 | + if ( isset( $this->legacyData[$code][$key][$subkey] ) ) { |
| 215 | + return $this->legacyData[$code][$key][$subkey]; |
| 216 | + } |
212 | 217 | if ( !isset( $this->loadedSubitems[$code][$key][$subkey] ) ) { |
213 | 218 | if ( isset( $this->loadedItems[$code][$key] ) ) { |
214 | 219 | if ( isset( $this->data[$code][$key][$subkey] ) ) { |
— | — | @@ -619,12 +624,30 @@ |
620 | 625 | unset( $this->loadedItems[$code] ); |
621 | 626 | unset( $this->loadedSubitems[$code] ); |
622 | 627 | unset( $this->initialisedLangs[$code] ); |
| 628 | + // We don't unload legacyData because there's no way to get it back |
| 629 | + // again, it's not really a cache |
623 | 630 | foreach ( $this->shallowFallbacks as $shallowCode => $fbCode ) { |
624 | 631 | if ( $fbCode === $code ) { |
625 | 632 | $this->unload( $shallowCode ); |
626 | 633 | } |
627 | 634 | } |
628 | 635 | } |
| 636 | + |
| 637 | + /** |
| 638 | + * Add messages to the cache, from an extension that has not yet been |
| 639 | + * migrated to $wgExtensionMessages or the LocalisationCacheRecache hook. |
| 640 | + * Called by deprecated function $wgMessageCache->addMessages(). |
| 641 | + */ |
| 642 | + public function addLegacyMessages( $messages ) { |
| 643 | + foreach ( $messages as $lang => $langMessages ) { |
| 644 | + if ( isset( $this->legacyData[$lang]['messages'] ) ) { |
| 645 | + $this->legacyData[$lang]['messages'] = |
| 646 | + $langMessages + $this->legacyData[$lang]['messages']; |
| 647 | + } else { |
| 648 | + $this->legacyData[$lang]['messages'] = $langMessages; |
| 649 | + } |
| 650 | + } |
| 651 | + } |
629 | 652 | } |
630 | 653 | |
631 | 654 | /** |
Index: trunk/phase3/includes/MessageCache.php |
— | — | @@ -501,6 +501,12 @@ |
502 | 502 | function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) { |
503 | 503 | global $wgContLanguageCode, $wgContLang; |
504 | 504 | |
| 505 | + if ( !is_string( $key ) ) { |
| 506 | + throw new MWException( __METHOD__.': Invalid message key of type ' . gettype( $key ) ); |
| 507 | + } elseif ( $key === '' ) { |
| 508 | + throw new MWException( __METHOD__.': Invaild message key: empty string' ); |
| 509 | + } |
| 510 | + |
505 | 511 | $lang = wfGetLangObj( $langcode ); |
506 | 512 | $langcode = $lang->getCode(); |
507 | 513 | |
— | — | @@ -701,7 +707,53 @@ |
702 | 708 | } |
703 | 709 | } |
704 | 710 | |
| 711 | + /** |
| 712 | + * Add a message to the cache |
| 713 | + * @deprecated Use $wgExtensionMessagesFiles |
| 714 | + * |
| 715 | + * @param mixed $key |
| 716 | + * @param mixed $value |
| 717 | + * @param string $lang The messages language, English by default |
| 718 | + */ |
| 719 | + function addMessage( $key, $value, $lang = 'en' ) { |
| 720 | + wfDeprecated( __METHOD__ ); |
| 721 | + $lc = Language::getLocalisationCache(); |
| 722 | + $lc->addLegacyMessages( array( $lang => array( $key => $value ) ) ); |
| 723 | + } |
| 724 | + |
705 | 725 | /** |
| 726 | + * Add an associative array of message to the cache |
| 727 | + * @deprecated Use $wgExtensionMessagesFiles |
| 728 | + * |
| 729 | + * @param array $messages An associative array of key => values to be added |
| 730 | + * @param string $lang The messages language, English by default |
| 731 | + */ |
| 732 | + function addMessages( $messages, $lang = 'en' ) { |
| 733 | + wfDeprecated( __METHOD__ ); |
| 734 | + $lc = Language::getLocalisationCache(); |
| 735 | + $lc->addLegacyMessages( array( $lang => $messages ) ); |
| 736 | + } |
| 737 | + |
| 738 | + /** |
| 739 | + * Add a 2-D array of messages by lang. Useful for extensions. |
| 740 | + * @deprecated Use $wgExtensionMessagesFiles |
| 741 | + * |
| 742 | + * @param array $messages The array to be added |
| 743 | + */ |
| 744 | + function addMessagesByLang( $messages ) { |
| 745 | + wfDeprecated( __METHOD__ ); |
| 746 | + $lc = Language::getLocalisationCache(); |
| 747 | + $lc->addLegacyMessages( $messages ); |
| 748 | + } |
| 749 | + |
| 750 | + /** |
| 751 | + * Set a hook for addMessagesByLang() |
| 752 | + */ |
| 753 | + function setExtensionMessagesHook( $callback ) { |
| 754 | + $this->mAddMessagesHook = $callback; |
| 755 | + } |
| 756 | + |
| 757 | + /** |
706 | 758 | * @deprecated |
707 | 759 | */ |
708 | 760 | function loadAllMessages( $lang = false ) { |
Index: trunk/phase3/includes/Exception.php |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | function useMessageCache() { |
28 | 28 | global $wgLang; |
29 | 29 | foreach ( $this->getTrace() as $frame ) { |
30 | | - if ( $frame['class'] == 'LocalisationCache' ) { |
| 30 | + if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) { |
31 | 31 | return false; |
32 | 32 | } |
33 | 33 | } |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -50,6 +50,8 @@ |
51 | 51 | to true |
52 | 52 | * Removed $wgEnableSerializedMessages and $wgCheckSerialized. Similar |
53 | 53 | functionality is now available via $wgLocalisationCacheConf. |
| 54 | +* $wgMessageCache->addMessages() is deprecated. Messages added via this |
| 55 | + interface will not appear in Special:AllMessages. |
54 | 56 | |
55 | 57 | === New features in 1.16 === |
56 | 58 | |