r25465 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25464‎ | r25465 | r25466 >
Date:02:48, 4 September 2007
Author:tstarling
Status:old
Tags:
Comment:
Allow extensions to define magic words by simply including a $magicWords variable in their registered i18n file.
Modified paths:
  • /trunk/phase3/includes/MessageCache.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/MessageCache.php
@@ -695,8 +695,14 @@
696696 * Load messages from a given file
697697 */
698698 function loadMessagesFile( $filename ) {
 699+ $magicWords = false;
699700 require( $filename );
700701 $this->addMessagesByLang( $messages );
 702+
 703+ if ( $magicWords !== false ) {
 704+ global $wgContLang;
 705+ $wgContLang->addMagicWordsByLang( $magicWords );
 706+ }
701707 }
702708 }
703709
Index: trunk/phase3/languages/Language.php
@@ -59,6 +59,7 @@
6060
6161 class Language {
6262 var $mConverter, $mVariants, $mCode, $mLoaded = false;
 63+ var $mMagicExtensions = array(), $mMagicHookDone = false;
6364
6465 static public $mLocalisationKeys = array( 'fallback', 'namespaceNames',
6566 'skinNames', 'mathNames',
@@ -1128,8 +1129,8 @@
11291130
11301131 # Fill a MagicWord object with data from here
11311132 function getMagic( &$mw ) {
1132 - if ( !isset( $this->mMagicExtensions ) ) {
1133 - $this->mMagicExtensions = array();
 1133+ if ( !$this->mMagicHookDone ) {
 1134+ $this->mMagicHookDone = true;
11341135 wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
11351136 }
11361137 if ( isset( $this->mMagicExtensions[$mw->mId] ) ) {
@@ -1153,6 +1154,24 @@
11541155 }
11551156
11561157 /**
 1158+ * Add magic words to the extension array
 1159+ */
 1160+ function addMagicWordsByLang( $newWords ) {
 1161+ $code = $this->getCode();
 1162+ $fallbackChain = array();
 1163+ while ( $code && !in_array( $code, $fallbackChain ) ) {
 1164+ $fallbackChain[] = $code;
 1165+ $code = self::getFallbackFor( $code );
 1166+ }
 1167+ $fallbackChain = array_reverse( $fallbackChain );
 1168+ foreach ( $fallbackChain as $code ) {
 1169+ if ( isset( $newWords[$code] ) ) {
 1170+ $this->mMagicExtensions = $newWords[$code] + $this->mMagicExtensions;
 1171+ }
 1172+ }
 1173+ }
 1174+
 1175+ /**
11571176 * Get special page names, as an associative array
11581177 * case folded alias => real name
11591178 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r25530Merged revisions 25454-25529 via svnmerge from...david08:28, 5 September 2007

Status & tagging log