Title: Make getOtherPage() check canHaveTalkPage()
authorKunal Mehta <legoktm@member.fsf.org>
Tue, 29 Aug 2017 19:53:53 +0000 (12:53 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Thu, 7 Sep 2017 02:52:34 +0000 (19:52 -0700)
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
tests/phpunit/includes/TitleMethodsTest.php

index b6a1689..6535890 100644 (file)
@@ -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();
                }
        }
index 8af3434..d9c01cb 100644 (file)
@@ -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 ],
                ];
        }