From: This, that and the other Date: Mon, 21 Apr 2014 03:20:24 +0000 (+1000) Subject: Allow local interwiki links with an empty title part X-Git-Tag: 1.31.0-rc.0~15105^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=c815f959d6b27b7abad72256af9ac43864692dc2 Allow local interwiki links with an empty title part For example, [[en:]] on enwiki. These links were for some reason considered invalid. However, to support use-cases such as cross-wiki transclusion and the importing of templates across wikis, this type of link should be allowed. I can't see that this would break anything. If anything, it will "un-break" some links. Should MediaWikiTitleCodec depend on Title::newMainPage? Almost certainly not, but I note that splitTitleString is earmarked for demolition, so I expect that the confusing dependency-web will be cleaned up in the future. I also note that MediaWikiTitleCode already uses various static methods of the Title class. Bug: 64167 Change-Id: I27495aa62e6059c7725387135ae0358d7e6fb35b --- diff --git a/includes/title/MediaWikiTitleCodec.php b/includes/title/MediaWikiTitleCodec.php index 288c1d9e3a..9ceea276f5 100644 --- a/includes/title/MediaWikiTitleCodec.php +++ b/includes/title/MediaWikiTitleCodec.php @@ -271,8 +271,16 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { foreach ( $this->localInterwikis as $localIW ) { if ( 0 == strcasecmp( $parts['interwiki'], $localIW ) ) { if ( $dbkey == '' ) { - # Can't have an empty self-link - throw new MalformedTitleException( 'Local interwiki with empty title: ' . $text ); + # Empty self-links should point to the Main Page, to ensure + # compatibility with cross-wiki transclusions and the like. + $mainPage = Title::newMainPage(); + return array( + 'interwiki' => $mainPage->getInterwiki(), + 'fragment' => $mainPage->getFragment(), + 'namespace' => $mainPage->getNamespace(), + 'dbkey' => $mainPage->getDBkey(), + 'user_case_dbkey' => $mainPage->getUserCaseDBKey() + ); } $parts['interwiki'] = ''; diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index e86b5565e8..c94adf25d0 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -80,6 +80,7 @@ class TitleTest extends MediaWikiTestCase { str_repeat( 'x', 252 ), // interwiki prefix 'localtestiw: #anchor', + 'localtestiw:', 'localtestiw:foo', 'localtestiw: foo # anchor', 'localtestiw: Talk: Sandbox # anchor', @@ -140,7 +141,6 @@ class TitleTest extends MediaWikiTestCase { 'Category: ', 'Category: #bar', // interwiki prefix - 'localtestiw:', 'localtestiw: Talk: # anchor', 'localtestiw: Talk:' ) as $text ) {