Adrian Heine has uploaded a new change for review.
https://gerrit.wikimedia.org/r/282124
Change subject: Reduce code duplication in MessageCache
......................................................................
Reduce code duplication in MessageCache
Change-Id: I3432958c8f81b7a33079b7933e85b87ced7363fa
---
M includes/cache/MessageCache.php
1 file changed, 51 insertions(+), 52 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/24/282124/1
diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php
index b26dc8d..1569ab2 100644
--- a/includes/cache/MessageCache.php
+++ b/includes/cache/MessageCache.php
@@ -818,24 +818,42 @@
* @return string|bool The message, or false if not found
*/
protected function getMessageFromFallbackChain( $lang, $lckey, $useDB )
{
- global $wgLanguageCode, $wgContLang;
+ global $wgContLang;
- $uckey = $wgContLang->ucfirst( $lckey );
+ // First try the requested language.
+ $message = $this->getMessageForLang( $lang, $lckey, $useDB );
+ if ( $message !== false ) {
+ return $message;
+ }
+
+ // Now try checking the site language.
+ $message = $this->getMessageForLang( $wgContLang, $lckey,
$useDB );
+ return $message;
+ }
+
+ /**
+ * Given a language, try and fetch messages from that language and its
fallbacks.
+ *
+ * @see MessageCache::get
+ * @param Language|StubObject $lang Preferred language
+ * @param string $lckey Lowercase key for the message (as for
localisation cache)
+ * @param bool $useDB Whether to include messages from the wiki database
+ * @return string|bool The message, or false if not found
+ */
+ private function getMessageForLang( $lang, $lckey, $useDB ) {
+ global $wgContLang;
$langcode = $lang->getCode();
$message = false;
- // First try the requested language.
+ // Try checking the database for the requested language
if ( $useDB ) {
- if ( $langcode === $wgLanguageCode ) {
- // Messages created in the content language
will not have the /lang extension
- $message = $this->getMsgFromNamespace( $uckey,
$langcode );
- } else {
- $message = $this->getMsgFromNamespace(
"$uckey/$langcode", $langcode );
- }
- }
+ $uckey = $wgContLang->ucfirst( $lckey );
- if ( $message !== false ) {
- return $message;
+ $message = $this->getMsgFromNamespace(
$this->getMessagePageName( $langcode, $uckey ), $langcode );
+
+ if ( $message !== false ) {
+ return $message;
+ }
}
// Check the CDB cache
@@ -844,56 +862,37 @@
return $message;
}
- list( $fallbackChain, $siteFallbackChain ) =
- Language::getFallbacksIncludingSiteLanguage( $langcode
);
-
- // Next try checking the database for all of the fallback
languages of the requested language.
+ // Try checking the database for all of the fallback languages
if ( $useDB ) {
+ $fallbackChain = Language::getFallbacksFor( $langcode );
+
foreach ( $fallbackChain as $code ) {
- if ( $code === $wgLanguageCode ) {
- // Messages created in the content
language will not have the /lang extension
- $message = $this->getMsgFromNamespace(
$uckey, $code );
- } else {
- $message = $this->getMsgFromNamespace(
"$uckey/$code", $code );
- }
+ $message = $this->getMsgFromNamespace(
$this->getMessagePageName( $code, $uckey ), $code );
if ( $message !== false ) {
- // Found the message.
return $message;
}
}
}
- // Now try checking the site language.
- if ( $useDB ) {
- $message = $this->getMsgFromNamespace( $uckey,
$wgLanguageCode );
- if ( $message !== false ) {
- return $message;
- }
+ return $message;
+ }
+
+ /**
+ * Get the message page name for a given language
+ *
+ * @param string $langcode
+ * @param string $uckey Uppercase key for the message
+ * @return string The page name
+ */
+ private function getMessagePageName( $langcode, $uckey ) {
+ global $wgLanguageCode;
+ if ( $langcode === $wgLanguageCode ) {
+ // Messages created in the content language will not
have the /lang extension
+ return $uckey;
+ } else {
+ return "$uckey/$langcode";
}
-
- $message = $wgContLang->getMessage( $lckey );
- if ( $message !== null ) {
- return $message;
- }
-
- // Finally try the DB for the site language's fallbacks.
- if ( $useDB ) {
- foreach ( $siteFallbackChain as $code ) {
- $message = $this->getMsgFromNamespace(
"$uckey/$code", $code );
- if ( $message === false && $code ===
$wgLanguageCode ) {
- // Messages created in the content
language will not have the /lang extension
- $message = $this->getMsgFromNamespace(
$uckey, $code );
- }
-
- if ( $message !== false ) {
- // Found the message.
- return $message;
- }
- }
- }
-
- return false;
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/282124
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3432958c8f81b7a33079b7933e85b87ced7363fa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Adrian Heine <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits