r105922 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105921‎ | r105922 | r105923 >
Date:19:32, 12 December 2011
Author:dantman
Status:ok (Comments)
Tags:
Comment:
Introduce a Language::getMessagesFileName hook that will allow extensions to define new language messages files outside of core.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1103,6 +1103,10 @@
11041104 &$result: Set this and return false to override the internal checks
11051105 $user: User the password is being validated for
11061106
 1107+'Language::getMessagesFileName':
 1108+$code: The language code or the language we're looking for a messages file for
 1109+&$file: The messages file path, you can override this to change the location.
 1110+
11071111 'LanguageGetNamespaces': Provide custom ordering for namespaces or
11081112 remove namespaces. Do not use this hook to add namespaces. Use
11091113 CanonicalNamespaces for that.
Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -103,6 +103,8 @@
104104 perceiving colors differently. Colors comes from the French Wikipedia.
105105 * (bug 32879) Upgrade jQuery to 1.7.1
106106 * jQuery UI upgraded to 1.8.17
 107+* Extensions can use the 'Language::getMessagesFileName' hook to define new
 108+ languages using messages files outside of core.
107109
108110 === Bug fixes in 1.19 ===
109111 * $wgUploadNavigationUrl should be used for file redlinks if.
Index: trunk/phase3/languages/Language.php
@@ -659,14 +659,13 @@
660660
661661 global $IP;
662662 $names = array();
663 - $dir = opendir( "$IP/languages/messages" );
664 - while ( false !== ( $file = readdir( $dir ) ) ) {
665 - $code = self::getCodeFromFileName( $file, 'Messages' );
666 - if ( $code && isset( $allNames[$code] ) ) {
 663+ // We do this using a foreach over the codes instead of a directory
 664+ // loop so that messages files in extensions will work correctly.
 665+ foreach ( $allNames as $code => $value ) {
 666+ if ( is_readable( self::getMessagesFileName( $code ) ) ) {
667667 $names[$code] = $allNames[$code];
668668 }
669669 }
670 - closedir( $dir );
671670 return $names;
672671 }
673672
@@ -3521,7 +3520,9 @@
35223521 */
35233522 static function getMessagesFileName( $code ) {
35243523 global $IP;
3525 - return self::getFileName( "$IP/languages/messages/Messages", $code, '.php' );
 3524+ $file = self::getFileName( "$IP/languages/messages/Messages", $code, '.php' );
 3525+ wfRunHooks( 'Language::getMessagesFileName', array( $code, &$file ) );
 3526+ return $file;
35263527 }
35273528
35283529 /**

Comments

#Comment by SPQRobin (talk | contribs)   22:13, 13 December 2011

We could make wgExtraLanguageNames accept an array like $wgExtraLanguageNames['code'] = array( 'Language name', '/path/to/MessagesFile.php' );. Then we don't need a hook. Anyway, it's just an idea..

Status & tagging log