From 5cb6ceee7360548bdbaac4311a78b342d379438b Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 4 Sep 2007 02:48:34 +0000 Subject: [PATCH] Allow extensions to define magic words by simply including a $magicWords variable in their registered i18n file. --- includes/MessageCache.php | 6 ++++++ languages/Language.php | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/includes/MessageCache.php b/includes/MessageCache.php index f06f44da6c..10c95a7ee8 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -695,8 +695,14 @@ class MessageCache { * Load messages from a given file */ function loadMessagesFile( $filename ) { + $magicWords = false; require( $filename ); $this->addMessagesByLang( $messages ); + + if ( $magicWords !== false ) { + global $wgContLang; + $wgContLang->addMagicWordsByLang( $magicWords ); + } } } diff --git a/languages/Language.php b/languages/Language.php index 69721ff8ab..3f9d98fbaa 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -59,6 +59,7 @@ class FakeConverter { class Language { var $mConverter, $mVariants, $mCode, $mLoaded = false; + var $mMagicExtensions = array(), $mMagicHookDone = false; static public $mLocalisationKeys = array( 'fallback', 'namespaceNames', 'skinNames', 'mathNames', @@ -1128,8 +1129,8 @@ class Language { # Fill a MagicWord object with data from here function getMagic( &$mw ) { - if ( !isset( $this->mMagicExtensions ) ) { - $this->mMagicExtensions = array(); + if ( !$this->mMagicHookDone ) { + $this->mMagicHookDone = true; wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) ); } if ( isset( $this->mMagicExtensions[$mw->mId] ) ) { @@ -1152,6 +1153,24 @@ class Language { $mw->mSynonyms = array_slice( $rawEntry, 1 ); } + /** + * Add magic words to the extension array + */ + function addMagicWordsByLang( $newWords ) { + $code = $this->getCode(); + $fallbackChain = array(); + while ( $code && !in_array( $code, $fallbackChain ) ) { + $fallbackChain[] = $code; + $code = self::getFallbackFor( $code ); + } + $fallbackChain = array_reverse( $fallbackChain ); + foreach ( $fallbackChain as $code ) { + if ( isset( $newWords[$code] ) ) { + $this->mMagicExtensions = $newWords[$code] + $this->mMagicExtensions; + } + } + } + /** * Get special page names, as an associative array * case folded alias => real name -- 2.20.1