From 54626e5ce172ea469942b01e0ea73f34fb5de07a Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 12 Jul 2019 12:21:44 +0200 Subject: [PATCH] Title: Title::getSubpage should not lose the interwiki prefix This issue was discovered while investigating T227700, and added some confusion. This patch is necessary for Special:MyLanguage to behave correctly in all cases, but it's not necessary for fixing the primary critical problem. Bug: T227700 Change-Id: Ib4cbeec47a877c473cbd501cc964cc66d169b99e --- includes/Title.php | 7 +++++- tests/phpunit/includes/TitleTest.php | 36 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/includes/Title.php b/includes/Title.php index 6e75102c92..079f2c8a55 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1887,7 +1887,12 @@ class Title implements LinkTarget, IDBAccessObject { * @since 1.20 */ public function getSubpage( $text ) { - return self::makeTitleSafe( $this->mNamespace, $this->getText() . '/' . $text ); + return self::makeTitleSafe( + $this->mNamespace, + $this->getText() . '/' . $text, + '', + $this->mInterwiki + ); } /** diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 4ffef02d19..d0a95c252f 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -1,5 +1,6 @@ getMock( InterwikiLookup::class ); + $interwikiLookup->expects( $this->any() ) + ->method( 'isValidInterwiki' ) + ->willReturnCallback( + function ( $prefix ) { + return $prefix == 'wiki'; + } + ); + + $this->setService( 'InterwikiLookup', $interwikiLookup ); + + $title = Title::newFromText( $title ); + $expected = Title::newFromLinkTarget( $expected ); + $actual = $title->getSubpage( $sub ); + + // NOTE: convert to string for comparison + $this->assertSame( $expected->getPrefixedText(), $actual->getPrefixedText(), 'text form' ); + $this->assertTrue( $expected->equals( $actual ), 'Title equality' ); + } + public static function provideNewFromTitleValue() { return [ [ new TitleValue( NS_MAIN, 'Foo' ) ], -- 2.20.1