Merge "'lang' attrib in #mw-content-text should be set to variant code."
[lhc/web/wiklou.git] / includes / Title.php
index eccae70..f9c7bdf 100644 (file)
@@ -4530,9 +4530,9 @@ class Title {
        }
 
        /**
-        * Get the language in which the content of this page is written.
-        * Defaults to $wgContLang, but in certain cases it can be e.g.
-        * $wgLang (such as special pages, which are in the user language).
+        * Get the language in which the content of this page is written in
+        * wikitext. Defaults to $wgContLang, but in certain cases it can be
+        * e.g. $wgLang (such as special pages, which are in the user language).
         *
         * @since 1.18
         * @return Language
@@ -4557,4 +4557,29 @@ class Title {
                wfRunHooks( 'PageContentLanguage', array( $this, &$pageLang, $wgLang ) );
                return wfGetLangObj( $pageLang );
        }
+
+       /**
+        * Get the language in which the content of this page is written when
+        * viewed by user. Defaults to $wgContLang, but in certain cases it can be
+        * e.g. $wgLang (such as special pages, which are in the user language).
+        *
+        * @since 1.20
+        * @return Language
+        */
+       public function getPageViewLanguage() {
+               $pageLang = $this->getPageLanguage();
+               // If this is nothing special (so the content is converted when viewed)
+               if ( !$this->isSpecialPage()
+                       && !$this->isCssOrJsPage() && !$this->isCssJsSubpage()
+                       && $this->getNamespace() !== NS_MEDIAWIKI
+               ) {
+                       // If the user chooses a variant, the content is actually
+                       // in a language whose code is the variant code.
+                       $variant = $pageLang->getPreferredVariant();
+                       if ( $pageLang->getCode() !== $variant ) {
+                               $pageLang = Language::factory( $variant );
+                       }
+               }
+               return $pageLang;
+       }
 }