Rename canTalk methods
authordaniel <daniel.kinzler@wikimedia.de>
Fri, 9 Jun 2017 18:29:18 +0000 (20:29 +0200)
committerLegoktm <legoktm@member.fsf.org>
Sun, 25 Jun 2017 10:15:30 +0000 (10:15 +0000)
This renames Title::canTalk to Title::canHaveTalkPage
and MWNamespace::canTalk to MWNamespace::hasTalkNamespace.

Bug: T165149
Change-Id: I342a273a497b31282388b13bf76dadfb1122dcbb

RELEASE-NOTES-1.30
includes/MWNamespace.php
includes/Title.php
tests/phpunit/includes/MWNamespaceTest.php
tests/phpunit/includes/TitleTest.php

index f2cb871..79f3dc3 100644 (file)
@@ -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.
index 4c5561f..89cb616 100644 (file)
@@ -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;
        }
 
index c9f09f7..2ebeb0d 100644 (file)
@@ -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 );
        }
 
        /**
index 5977652..498532f 100644 (file)
@@ -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" );
        }
 
        /**
index 6c44999..c06a2e4 100644 (file)
@@ -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' ],