From 9883b2471c3ea57f43d9fa8efd200098e6a85ea1 Mon Sep 17 00:00:00 2001 From: "This, that and the other" Date: Fri, 1 Aug 2014 18:17:49 +1000 Subject: [PATCH] Don't include images/categories when behind a local interwiki prefix 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 | 7 +++++-- includes/Title.php | 13 +++++++++++++ includes/parser/Parser.php | 6 ++---- includes/title/MediaWikiTitleCodec.php | 4 ++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index ec4bc0fa0c..a65d7e725f 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -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. diff --git a/includes/Title.php b/includes/Title.php index ab55257a04..68919751cc 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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']; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index bc4fcce282..611f7a029c 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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] ) ) { diff --git a/includes/title/MediaWikiTitleCodec.php b/includes/title/MediaWikiTitleCodec.php index 12b7143f33..6ca0799c8e 100644 --- a/includes/title/MediaWikiTitleCodec.php +++ b/includes/title/MediaWikiTitleCodec.php @@ -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; -- 2.20.1