Don't include images/categories when behind a local interwiki prefix
authorThis, that and the other <at.light@live.com.au>
Fri, 1 Aug 2014 08:17:49 +0000 (18:17 +1000)
committerThis, that and the other <at.light@live.com.au>
Fri, 1 Aug 2014 08:20:51 +0000 (18:20 +1000)
This solution is somewhat imperfect, as the logic being added here to
MediaWikiTitleCodec really belongs in the parser. However, given the
current state of this code, this is the cleanest possible solution at
the moment.

Modified the existing release note for this.

Bug: 68802
Change-Id: I38309186bdcad23f49e23beb26daaf3ef5bceea1

RELEASE-NOTES-1.24
includes/Title.php
includes/parser/Parser.php
includes/title/MediaWikiTitleCodec.php

index ec4bc0f..a65d7e7 100644 (file)
@@ -129,9 +129,12 @@ production.
 * (bug 66440) The MediaWiki web installer will now allow you to choose the skins
   to enable (from the ones included in download tarball) and decide which one
   should be the default.
-* (bug 68085) Links of the form [[localInterwikiPrefix:languageCode:pageTitle]],
+* (bug 68085, 68802) Links like [[localInterwikiPrefix:languageCode:pageTitle]],
   where localInterwikiPrefix is a member of the $wgLocalInterwikis array, will
-  no longer be displayed in the sidebar when $wgInterwikiMagic is true.
+  no longer be displayed in the sidebar when $wgInterwikiMagic is true. In a
+  similar way, links like [[localInterwikiPrefix:File:Image.png]] and
+  [[localInterwikiPrefix:Category:Hello]] will now render as regular links, and
+  will not include the file or add the page to the category.
 * New special page, MyLanguages, to redirect users to subpages with localised
   versions of a page. (Integrated from Extension:Translate)
 * MediaWiki now supports multiple password types, including bcrypt and PBKDF2.
index ab55257..6891975 100644 (file)
@@ -74,6 +74,9 @@ class Title {
        /** @var string Interwiki prefix */
        public $mInterwiki = '';
 
+       /** @var bool Was this Title created from a string with a local interwiki prefix? */
+       private $mLocalInterwiki = false;
+
        /** @var string Title fragment (i.e. the bit after the #) */
        public $mFragment = '';
 
@@ -823,6 +826,15 @@ class Title {
                return $this->mInterwiki;
        }
 
+       /**
+        * Was this a local interwiki link?
+        *
+        * @return bool
+        */
+       public function wasLocalInterwiki() {
+               return $this->mLocalInterwiki;
+       }
+
        /**
         * Determine whether the object refers to a page within
         * this project and is transcludable.
@@ -3289,6 +3301,7 @@ class Title {
                # Fill fields
                $this->setFragment( '#' . $parts['fragment'] );
                $this->mInterwiki = $parts['interwiki'];
+               $this->mLocalInterwiki = $parts['local_interwiki'];
                $this->mNamespace = $parts['namespace'];
                $this->mUserCaseDBKey = $parts['user_case_dbkey'];
 
index bc4fcce..611f7a0 100644 (file)
@@ -2096,16 +2096,14 @@ class Parser {
                        }
 
                        # Link not escaped by : , create the various objects
-                       if ( $noforce ) {
+                       if ( $noforce && !$nt->wasLocalInterwiki() ) {
                                # Interwikis
                                wfProfileIn( __METHOD__ . "-interwiki" );
-                               # The final condition here is due to bug 68085
                                if (
                                        $iw && $this->mOptions->getInterwikiMagic() && $nottalk && (
                                                Language::fetchLanguageName( $iw, null, 'mw' ) ||
                                                in_array( $iw, $wgExtraInterlanguageLinkPrefixes )
-                                       ) && substr_compare( $this->getTargetLanguage()->lc( ltrim( $origLink ) ),
-                                               $iw, 0, strlen( $iw ) ) === 0
+                                       )
                                ) {
                                        # Bug 24502: filter duplicates
                                        if ( !isset( $this->mLangLinkLanguages[$iw] ) ) {
index 12b7143..6ca0799 100644 (file)
@@ -206,6 +206,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                # Initialisation
                $parts = array(
                        'interwiki' => '',
+                       'local_interwiki' => false,
                        'fragment' => '',
                        'namespace' => $defaultNamespace,
                        'dbkey' => $dbkey,
@@ -282,6 +283,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                                                                $mainPage = Title::newMainPage();
                                                                return array(
                                                                        'interwiki' => $mainPage->getInterwiki(),
+                                                                       'local_interwiki' => true,
                                                                        'fragment' => $mainPage->getFragment(),
                                                                        'namespace' => $mainPage->getNamespace(),
                                                                        'dbkey' => $mainPage->getDBkey(),
@@ -289,6 +291,8 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                                                                );
                                                        }
                                                        $parts['interwiki'] = '';
+                                                       # local interwikis should behave like initial-colon links
+                                                       $parts['local_interwiki'] = true;
 
                                                        # Do another namespace split...
                                                        continue 2;