Merge "Limit the Title backlink cache to two instances."
[lhc/web/wiklou.git] / includes / Title.php
index 98961f8..1b5e21d 100644 (file)
@@ -4432,6 +4432,11 @@ class Title {
                        'rd_title' => $this->getDBkey(),
                        'rd_from = page_id'
                );
+               if ( $this->isExternal() ) {
+                       $where['rd_interwiki'] = $this->getInterwiki();
+               } else {
+                       $where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
+               }
                if ( !is_null( $ns ) ) {
                        $where['page_namespace'] = $ns;
                }
@@ -4526,9 +4531,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
@@ -4553,4 +4558,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;
+       }
 }