Introduce a Language::getMessagesFileName hook that will allow extensions to define...
authorDaniel Friesen <dantman@users.mediawiki.org>
Mon, 12 Dec 2011 19:32:59 +0000 (19:32 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Mon, 12 Dec 2011 19:32:59 +0000 (19:32 +0000)
RELEASE-NOTES-1.19
docs/hooks.txt
languages/Language.php

index 7d4e01e..a29ac1a 100644 (file)
@@ -103,6 +103,8 @@ production.
   perceiving colors differently. Colors comes from the French Wikipedia.
 * (bug 32879) Upgrade jQuery to 1.7.1
 * jQuery UI upgraded to 1.8.17
+* Extensions can use the 'Language::getMessagesFileName' hook to define new
+  languages using messages files outside of core.
 
 === Bug fixes in 1.19 ===
 * $wgUploadNavigationUrl should be used for file redlinks if.
index e16b4c2..759874b 100644 (file)
@@ -1103,6 +1103,10 @@ $password: The password entered by the user
 &$result: Set this and return false to override the internal checks
 $user: User the password is being validated for
 
+'Language::getMessagesFileName':
+$code: The language code or the language we're looking for a messages file for
+&$file: The messages file path, you can override this to change the location.
+
 'LanguageGetNamespaces': Provide custom ordering for namespaces or
 remove namespaces. Do not use this hook to add namespaces. Use
 CanonicalNamespaces for that.
index 21f6ca7..a712246 100644 (file)
@@ -659,14 +659,13 @@ class Language {
 
                global $IP;
                $names = array();
-               $dir = opendir( "$IP/languages/messages" );
-               while ( false !== ( $file = readdir( $dir ) ) ) {
-                       $code = self::getCodeFromFileName( $file, 'Messages' );
-                       if ( $code && isset( $allNames[$code] ) ) {
+               // We do this using a foreach over the codes instead of a directory
+               // loop so that messages files in extensions will work correctly.
+               foreach ( $allNames as $code => $value ) {
+                       if ( is_readable( self::getMessagesFileName( $code ) ) ) {
                                $names[$code] = $allNames[$code];
                        }
                }
-               closedir( $dir );
                return $names;
        }
 
@@ -3521,7 +3520,9 @@ class Language {
         */
        static function getMessagesFileName( $code ) {
                global $IP;
-               return self::getFileName( "$IP/languages/messages/Messages", $code, '.php' );
+               $file = self::getFileName( "$IP/languages/messages/Messages", $code, '.php' );
+               wfRunHooks( 'Language::getMessagesFileName', array( $code, &$file ) );
+               return $file;
        }
 
        /**