Language: Introduce new method equals( Language $lang )
authorFomafix <fomafix@googlemail.com>
Mon, 16 May 2016 22:33:33 +0000 (22:33 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Mon, 16 May 2016 22:33:33 +0000 (22:33 +0000)
Use

 $lang->equals( $wgContLang )

instead of

 $lang->getCode() === $wgContLang->getCode()

Change-Id: Id7ed6a21ce5e2ea2887ec98c7bd9d3eba83d733b

includes/Message.php
includes/Title.php
includes/api/ApiQueryAllMessages.php
includes/cache/HTMLFileCache.php
includes/parser/ParserOptions.php
includes/specials/pagers/AllMessagesTablePager.php
languages/Language.php

index c7752aa..c204aee 100644 (file)
@@ -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;
                }
 
index 25fbce3..3043ed4 100644 (file)
@@ -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] );
index f1d787b..e0ba4ea 100644 (file)
@@ -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';
index cdf00c7..bb78aa0 100644 (file)
@@ -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
index 729b9db..91cd0f4 100644 (file)
@@ -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()
                );
        }
index 2f2cbc2..8e4fbaa 100644 (file)
@@ -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();
 
index e7643b1..0a6ccd3 100644 (file)
@@ -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
         *