From 1f53b6ee6ae2fc6e92b22ad42a5a63803f9a20db Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Tue, 29 Aug 2017 12:53:53 -0700 Subject: [PATCH] Title: Make getOtherPage() check canHaveTalkPage() Practically this doesn't make any difference, but once it's possible for namespaces to not have talk pages, this function would have returned an invalid Title. Bug: T165149 Change-Id: I940433c22193d406d8b4a6cab0e6ad37e88e62c6 --- includes/Title.php | 5 ++++- tests/phpunit/includes/TitleMethodsTest.php | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/Title.php b/includes/Title.php index b6a1689c71..6535890b23 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1355,7 +1355,7 @@ class Title implements LinkTarget { * get the talk page, if it is a subject page get the talk page * * @since 1.25 - * @throws MWException + * @throws MWException If the page doesn't have an other page * @return Title */ public function getOtherPage() { @@ -1365,6 +1365,9 @@ class Title implements LinkTarget { if ( $this->isTalkPage() ) { return $this->getSubjectPage(); } else { + if ( !$this->canHaveTalkPage() ) { + throw new MWException( "{$this->getPrefixedText()} does not have an other page" ); + } return $this->getTalkPage(); } } diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index 8af34346c1..d9c01cb9f1 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -305,6 +305,7 @@ class TitleMethodsTest extends MediaWikiLangTestCase { [ 'Help:Main Page', 'Help talk:Main Page' ], [ 'Help talk:Main Page', 'Help:Main Page' ], [ 'Special:FooBar', null ], + [ 'Media:File.jpg', null ], ]; } -- 2.20.1