Merge "Add and use Title::getOtherPage()"
[lhc/web/wiklou.git] / includes / Title.php
index 4b60bcb..cf11bd3 100644 (file)
@@ -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
         *