use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase;
use MediaWiki\Linker\LinkTarget;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase;
use MediaWiki\Linker\LinkTarget;
* Invalid titles may get returned from makeTitle(), and it may be useful to
* allow them to exist, e.g. in order to process log entries about pages in
* namespaces that belong to extensions that are no longer installed.
* Invalid titles may get returned from makeTitle(), and it may be useful to
* allow them to exist, e.g. in order to process log entries about pages in
* namespaces that belong to extensions that are no longer installed.
- * @see NamespaceInfo::hasTalkNamespace
+ * False for relative section links (with getText() === ''),
+ * interwiki links (with getInterwiki() !== ''), and pages in NS_SPECIAL.
+ *
+ * @see NamespaceInfo::canHaveTalkPage
* @since 1.30
*
* @return bool True if this title either is a talk page or can have a talk page associated.
*/
public function canHaveTalkPage() {
* @since 1.30
*
* @return bool True if this title either is a talk page or can have a talk page associated.
*/
public function canHaveTalkPage() {
- return !$this->isExternal() && MediaWikiServices::getInstance()->getNamespaceInfo()->
- isWatchable( $this->mNamespace );
+ $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+ return $this->getText() !== '' && !$this->isExternal() &&
+ $nsInfo->isWatchable( $this->mNamespace );
- return self::makeTitle( $this->mNamespace, $this->getRootText() );
+ $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() );
+ Assert::postcondition(
+ $title !== null,
+ 'makeTitleSafe() should always return a Title for the text returned by getRootText().'
+ );
+ return $title;
- return self::makeTitle( $this->mNamespace, $this->getBaseText() );
+ $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() );
+ Assert::postcondition(
+ $title !== null,
+ 'makeTitleSafe() should always return a Title for the text returned by getBaseText().'
+ );
+ return $title;