From f8ac44cca56091573894b7d02cf99edbcc98e354 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 9 Jun 2017 20:29:18 +0200 Subject: [PATCH] Rename canTalk methods This renames Title::canTalk to Title::canHaveTalkPage and MWNamespace::canTalk to MWNamespace::hasTalkNamespace. Bug: T165149 Change-Id: I342a273a497b31282388b13bf76dadfb1122dcbb --- RELEASE-NOTES-1.30 | 4 ++ includes/MWNamespace.php | 18 ++++++++- includes/Title.php | 19 +++++++-- tests/phpunit/includes/MWNamespaceTest.php | 46 ++++++++++++++++------ tests/phpunit/includes/TitleTest.php | 41 +++++++++++++++++++ 5 files changed, 111 insertions(+), 17 deletions(-) diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30 index f2cb871466..79f3dc327f 100644 --- a/RELEASE-NOTES-1.30 +++ b/RELEASE-NOTES-1.30 @@ -85,6 +85,10 @@ changes to languages because of Phabricator reports. deprecated. There are no known callers. * File::getStreamHeaders() was deprecated. * MediaHandler::getStreamHeaders() was deprecated. +* Title::canTalk() was deprecated, the new Title::canHaveTalkPage() should be + used instead. +* MWNamespace::canTalk() was deprecated, the new MWNamespace::hasTalkNamespace() + should be used instead. * The ExtractThumbParameters hook (deprecated in 1.21) was removed. * The OutputPage::addParserOutputNoText and ::getHeadLinks methods (both deprecated in 1.24) were removed. diff --git a/includes/MWNamespace.php b/includes/MWNamespace.php index 4c5561fba8..89cb616a7b 100644 --- a/includes/MWNamespace.php +++ b/includes/MWNamespace.php @@ -278,12 +278,26 @@ class MWNamespace { } /** - * Can this namespace ever have a talk namespace? + * Does this namespace ever have a talk namespace? + * + * @deprecated since 1.30, use hasTalkNamespace() instead. * * @param int $index Namespace index - * @return bool + * @return bool True if this namespace either is or has a corresponding talk namespace. */ public static function canTalk( $index ) { + return self::hasTalkNamespace( $index ); + } + + /** + * Does this namespace ever have a talk namespace? + * + * @since 1.30 + * + * @param int $index Namespace ID + * @return bool True if this namespace either is or has a corresponding talk namespace. + */ + public static function hasTalkNamespace( $index ) { return $index >= NS_MAIN; } diff --git a/includes/Title.php b/includes/Title.php index c9f09f79e2..2ebeb0d756 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1020,12 +1020,25 @@ class Title implements LinkTarget { } /** - * Could this title have a corresponding talk page? + * Can this title have a corresponding talk page? * - * @return bool + * @deprecated since 1.30, use canHaveTalkPage() instead. + * + * @return bool True if this title either is a talk page or can have a talk page associated. */ public function canTalk() { - return MWNamespace::canTalk( $this->mNamespace ); + return $this->canHaveTalkPage(); + } + + /** + * Can this title have a corresponding talk page? + * + * @see MWNamespace::hasTalkNamespace + * + * @return bool True if this title either is a talk page or can have a talk page associated. + */ + public function canHaveTalkPage() { + return MWNamespace::hasTalkNamespace( $this->mNamespace ); } /** diff --git a/tests/phpunit/includes/MWNamespaceTest.php b/tests/phpunit/includes/MWNamespaceTest.php index 597765228b..498532f76c 100644 --- a/tests/phpunit/includes/MWNamespaceTest.php +++ b/tests/phpunit/includes/MWNamespaceTest.php @@ -262,21 +262,43 @@ class MWNamespaceTest extends MediaWikiTestCase { } */ + public function provideHasTalkNamespace() { + return [ + [ NS_MEDIA, false ], + [ NS_SPECIAL, false ], + + [ NS_MAIN, true ], + [ NS_TALK, true ], + [ NS_USER, true ], + [ NS_USER_TALK, true ], + + [ 100, true ], + [ 101, true ], + ]; + } + /** - * @covers MWNamespace::canTalk + * @dataProvider provideHasTalkNamespace + * @covers MWNamespace::hasTalkNamespace + * + * @param int $index + * @param bool $expected */ - public function testCanTalk() { - $this->assertCanNotTalk( NS_MEDIA ); - $this->assertCanNotTalk( NS_SPECIAL ); - - $this->assertCanTalk( NS_MAIN ); - $this->assertCanTalk( NS_TALK ); - $this->assertCanTalk( NS_USER ); - $this->assertCanTalk( NS_USER_TALK ); + public function testHasTalkNamespace( $index, $expected ) { + $actual = MWNamespace::hasTalkNamespace( $index ); + $this->assertSame( $actual, $expected, "NS $index" ); + } - // User defined namespaces - $this->assertCanTalk( 100 ); - $this->assertCanTalk( 101 ); + /** + * @dataProvider provideHasTalkNamespace + * @covers MWNamespace::canTalk + * + * @param int $index + * @param bool $expected + */ + public function testCanTalk( $index, $expected ) { + $actual = MWNamespace::canTalk( $index ); + $this->assertSame( $actual, $expected, "NS $index" ); } /** diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 6c4499948d..c06a2e4f1c 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -675,6 +675,47 @@ class TitleTest extends MediaWikiTestCase { ); } + public function provideCanHaveTalkPage() { + return [ + 'User page has talk page' => [ + Title::makeTitle( NS_USER, 'Jane' ), true + ], + 'Talke page has talk page' => [ + Title::makeTitle( NS_TALK, 'Foo' ), true + ], + 'Special page cannot have talk page' => [ + Title::makeTitle( NS_SPECIAL, 'Thing' ), false + ], + 'Virtual namespace cannot have talk page' => [ + Title::makeTitle( NS_MEDIA, 'Kitten.jpg' ), false + ], + ]; + } + + /** + * @dataProvider provideCanHaveTalkPage + * @covers Title::canHaveTalkPage + * + * @param Title $title + * @param bool $expected + */ + public function testCanHaveTalkPage( Title $title, $expected ) { + $actual = $title->canHaveTalkPage(); + $this->assertSame( $expected, $actual, $title->getPrefixedDBkey() ); + } + + /** + * @dataProvider provideCanHaveTalkPage + * @covers Title::canTalk + * + * @param Title $title + * @param bool $expected + */ + public function testCanTalk( Title $title, $expected ) { + $actual = $title->canTalk(); + $this->assertSame( $expected, $actual, $title->getPrefixedDBkey() ); + } + public function provideCreateFragmentTitle() { return [ [ Title::makeTitle( NS_MAIN, 'Test' ), 'foo' ], -- 2.20.1