+ // Is this the same title?
+ $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo()
+ ->getSubject( $this->mNamespace );
+ if ( $this->mNamespace == $subjectNS ) {
+ return $this;
+ }
+ // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles.
+ // Instead of failing on invalid titles, let's just log the issue for now.
+ // See the discussion on T227817.
+ $title = self::makeTitle( $subjectNS, $this->mDbkeyform );
+
+ $this->warnIfPageCannotExist( $title, __METHOD__ );
+
+ return $title;
+ // TODO: replace the above with the code below:
+ // return self::castFromLinkTarget(
+ // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) );
+ }
+
+ /**
+ * @param Title $title
+ * @param string $method
+ *
+ * @return bool whether a warning was issued
+ */
+ private function warnIfPageCannotExist( Title $title, $method ) {
+ if ( $this->getText() == '' ) {
+ wfLogWarning(
+ $method . ': called on empty title ' . $this->getFullText() . ', returning '
+ . $title->getFullText()
+ );
+
+ return true;
+ }
+
+ if ( $this->getInterwiki() !== '' ) {
+ wfLogWarning(
+ $method . ': called on interwiki title ' . $this->getFullText() . ', returning '
+ . $title->getFullText()
+ );
+
+ return true;
+ }
+
+ return false;