jenkins-bot has submitted this change and it was merged.
Change subject: Add and use Title::getOtherPage()
......................................................................
Add and use Title::getOtherPage()
Change-Id: I40a51c14ce07c301c15c6c2128cc18bb12e71103
---
M includes/Title.php
M includes/page/WikiPage.php
M tests/phpunit/includes/TitleMethodsTest.php
3 files changed, 47 insertions(+), 10 deletions(-)
Approvals:
Parent5446: Looks good to me, but someone else must approve
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Title.php b/includes/Title.php
index 638da08..562fc54 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -1336,6 +1336,25 @@
}
/**
+ * 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
*
* @return int Default namespace index
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 8b26c23..31d6fc8 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -3158,11 +3158,7 @@
*/
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 @@
*/
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 5904fac..707a4a1 100644
--- a/tests/phpunit/includes/TitleMethodsTest.php
+++ b/tests/phpunit/includes/TitleMethodsTest.php
@@ -297,4 +297,30 @@
$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() );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/177729
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I40a51c14ce07c301c15c6c2128cc18bb12e71103
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits