From 9d0ee321b6788907f0bf051862c06ac1f6362b2c Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Mon, 12 Dec 2011 19:32:59 +0000 Subject: [PATCH] Introduce a Language::getMessagesFileName hook that will allow extensions to define new language messages files outside of core. --- RELEASE-NOTES-1.19 | 2 ++ docs/hooks.txt | 4 ++++ languages/Language.php | 13 +++++++------ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 7d4e01e6ac..a29ac1a242 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -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. diff --git a/docs/hooks.txt b/docs/hooks.txt index e16b4c2125..759874b775 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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. diff --git a/languages/Language.php b/languages/Language.php index 21f6ca7baa..a712246d22 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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; } /** -- 2.20.1