Merge "Title: Make getOtherPage() check canHaveTalkPage()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 7 Sep 2017 09:38:24 +0000 (09:38 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 7 Sep 2017 09:38:24 +0000 (09:38 +0000)
includes/Title.php
tests/phpunit/includes/TitleMethodsTest.php

index 0687a15..c97a42b 100644 (file)
@@ -1356,7 +1356,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() {
@@ -1366,6 +1366,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 ],
                ];
        }