Allow local interwiki links with an empty title part
authorThis, that and the other <at.light@live.com.au>
Mon, 21 Apr 2014 03:20:24 +0000 (13:20 +1000)
committerThis, that and the other <at.light@live.com.au>
Mon, 21 Apr 2014 03:20:24 +0000 (13:20 +1000)
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

includes/title/MediaWikiTitleCodec.php
tests/phpunit/includes/TitleTest.php

index 288c1d9..9ceea27 100644 (file)
@@ -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'] = '';
 
index e86b556..c94adf2 100644 (file)
@@ -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 ) {