From: jenkins-bot Date: Thu, 25 Dec 2014 15:22:36 +0000 (+0000) Subject: Merge "Add and use Title::getOtherPage()" X-Git-Tag: 1.31.0-rc.0~12858 X-Git-Url: https://git.heureux-cyclage.org/w/index.php?a=commitdiff_plain;h=a300fabb68430e6204eebceb2af9ddbffd72017a;hp=8c3738e088f377642c540a0ccddb01b16ba7116b;p=lhc%2Fweb%2Fwiklou.git Merge "Add and use Title::getOtherPage()" --- diff --git a/includes/Title.php b/includes/Title.php index 4b60bcb6e4..cf11bd3328 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1334,6 +1334,25 @@ class Title { return Title::makeTitle( $subjectNS, $this->getDBkey() ); } + /** + * Get the other title for this page, if this is a subject page + * get the talk page, if it is a subject page get the talk page + * + * @since 1.25 + * @throws MWException + * @return Title + */ + public function getOtherPage() { + if ( $this->isSpecialPage() ) { + throw new MWException( 'Special pages cannot have other pages' ); + } + if ( $this->isTalkPage() ) { + return $this->getSubjectPage(); + } else { + return $this->getTalkPage(); + } + } + /** * Get the default namespace index, for when there is no namespace * diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 282506470c..dcebe54216 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -3158,11 +3158,7 @@ class WikiPage implements Page, IDBAccessObject { */ public static function onArticleCreate( $title ) { // Update existence markers on article/talk tabs... - if ( $title->isTalkPage() ) { - $other = $title->getSubjectPage(); - } else { - $other = $title->getTalkPage(); - } + $other = $title->getOtherPage(); $other->invalidateCache(); $other->purgeSquid(); @@ -3179,11 +3175,7 @@ class WikiPage implements Page, IDBAccessObject { */ public static function onArticleDelete( $title ) { // Update existence markers on article/talk tabs... - if ( $title->isTalkPage() ) { - $other = $title->getSubjectPage(); - } else { - $other = $title->getTalkPage(); - } + $other = $title->getOtherPage(); $other->invalidateCache(); $other->purgeSquid(); diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index 5904facd07..707a4a1c0b 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -297,4 +297,30 @@ class TitleMethodsTest extends MediaWikiTestCase { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isWikitextPage() ); } + + public static function provideGetOtherPage() { + return array( + array( 'Main Page', 'Talk:Main Page' ), + array( 'Talk:Main Page', 'Main Page' ), + array( 'Help:Main Page', 'Help talk:Main Page' ), + array( 'Help talk:Main Page', 'Help:Main Page' ), + array( 'Special:FooBar', null ), + ); + } + + /** + * @dataProvider provideGetOtherpage + * @covers Title::getOtherPage + * + * @param string $text + * @param string|null $expected + */ + public function testGetOtherPage( $text, $expected ) { + if ( $expected === null ) { + $this->setExpectedException( 'MWException' ); + } + + $title = Title::newFromText( $text ); + $this->assertEquals( $expected, $title->getOtherPage()->getPrefixedText() ); + } }