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
*
*/
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();
*/
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();
$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() );
+ }
}