From 796d62d034643a3efe63c1693606fcef4b1c6f24 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Mon, 16 May 2016 22:33:33 +0000 Subject: [PATCH] Language: Introduce new method equals( Language $lang ) Use $lang->equals( $wgContLang ) instead of $lang->getCode() === $wgContLang->getCode() Change-Id: Id7ed6a21ce5e2ea2887ec98c7bd9d3eba83d733b --- includes/Message.php | 4 ++-- includes/Title.php | 2 +- includes/api/ApiQueryAllMessages.php | 5 ++--- includes/cache/HTMLFileCache.php | 5 ++--- includes/parser/ParserOptions.php | 2 +- includes/specials/pagers/AllMessagesTablePager.php | 2 +- languages/Language.php | 11 +++++++++++ 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/includes/Message.php b/includes/Message.php index c7752aac24..c204aee032 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -447,12 +447,12 @@ class Message implements MessageSpecifier, Serializable { public function getTitle() { global $wgContLang, $wgForceUIMsgAsContentMsg; - $code = $this->getLanguage()->getCode(); $title = $this->key; if ( - $wgContLang->getCode() !== $code + !$this->language->equals( $wgContLang ) && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) { + $code = $this->language->getCode(); $title .= '/' . $code; } diff --git a/includes/Title.php b/includes/Title.php index 25fbce3f57..3043ed4864 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1714,7 +1714,7 @@ class Title implements LinkTarget { if ( $url === false && $wgVariantArticlePath && preg_match( '/^variant=([^&]*)$/', $query, $matches ) - && $wgContLang->getCode() === $this->getPageLanguage()->getCode() + && $this->getPageLanguage()->equals( $wgContLang ) && $this->getPageLanguage()->hasVariants() ) { $variant = urldecode( $matches[1] ); diff --git a/includes/api/ApiQueryAllMessages.php b/includes/api/ApiQueryAllMessages.php index f1d787b8b3..e0ba4ea1c1 100644 --- a/includes/api/ApiQueryAllMessages.php +++ b/includes/api/ApiQueryAllMessages.php @@ -113,15 +113,14 @@ class ApiQueryAllMessages extends ApiQueryBase { $customiseFilterEnabled = $params['customised'] !== 'all'; if ( $customiseFilterEnabled ) { global $wgContLang; - $lang = $langObj->getCode(); $customisedMessages = AllMessagesTablePager::getCustomisedStatuses( array_map( [ $langObj, 'ucfirst' ], $messages_target ), - $lang, - $lang != $wgContLang->getCode() + $langObj->getCode(), + !$langObj->equals( $wgContLang ) ); $customised = $params['customised'] === 'modified'; diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php index cdf00c7a58..bb78aa0dbd 100644 --- a/includes/cache/HTMLFileCache.php +++ b/includes/cache/HTMLFileCache.php @@ -124,11 +124,10 @@ class HTMLFileCache extends FileCacheBase { $user = $context->getUser(); // Check for non-standard user language; this covers uselang, // and extensions for auto-detecting user language. - $ulang = $context->getLanguage()->getCode(); - $clang = $wgContLang->getCode(); + $ulang = $context->getLanguage(); // Check that there are no other sources of variation - if ( $user->getId() || $user->getNewtalk() || $ulang != $clang ) { + if ( $user->getId() || $user->getNewtalk() || $ulang->equals( $wgContLang ) ) { return false; } // Allow extensions to disable caching diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 729b9db8a9..91cd0f4126 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -701,7 +701,7 @@ class ParserOptions { } // Check the object and lazy-loaded options return ( - $this->mUserLang->getCode() === $other->mUserLang->getCode() && + $this->mUserLang->equals( $other->mUserLang ) && $this->getDateFormat() === $other->getDateFormat() ); } diff --git a/includes/specials/pagers/AllMessagesTablePager.php b/includes/specials/pagers/AllMessagesTablePager.php index 2f2cbc2be8..8e4fbaaad2 100644 --- a/includes/specials/pagers/AllMessagesTablePager.php +++ b/includes/specials/pagers/AllMessagesTablePager.php @@ -56,7 +56,7 @@ class AllMessagesTablePager extends TablePager { $this->lang = ( $langObj ? $langObj : $wgContLang ); $this->langcode = $this->lang->getCode(); - $this->foreign = $this->langcode !== $wgContLang->getCode(); + $this->foreign = !$this->lang->equals( $wgContLang ); $request = $this->getRequest(); diff --git a/languages/Language.php b/languages/Language.php index e7643b1e76..0a6ccd3eb2 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -4190,6 +4190,17 @@ class Language { return $lang; } + /** + * Compare with an other language object + * + * @since 1.28 + * @param Language $lang + * @return boolean + */ + public function equals( Language $lang ) { + return $lang->getCode() === $this->mCode; + } + /** * Get the internal language code for this language object * -- 2.20.1