diff --git a/includes/CommentParser.php b/includes/CommentParser.php index 748fe7297..78d672db6 100644 --- a/includes/CommentParser.php +++ b/includes/CommentParser.php @@ -566,15 +566,14 @@ class CommentParser { $username = null; $displayName = null; - $namespaceId = $title->getNamespace(); $mainText = $title->getText(); - if ( $namespaceId === NS_USER || $namespaceId === NS_USER_TALK ) { + if ( $title->inNamespace( NS_USER ) || $title->inNamespace( NS_USER_TALK ) ) { $username = $mainText; if ( str_contains( $username, '/' ) ) { return null; } - if ( $namespaceId === NS_USER ) { + if ( $title->inNamespace( NS_USER ) ) { // Use regex trim for consistency with JS implementation $text = preg_replace( [ '/^[\s]+/u', '/[\s]+$/u' ], '', $link->textContent ?? '' ); // Record the display name if it has been customised beyond changing case @@ -582,7 +581,7 @@ class CommentParser { $displayName = $text; } } - } elseif ( $namespaceId === NS_SPECIAL ) { + } elseif ( $title->inNamespace( NS_SPECIAL ) ) { $parts = explode( '/', $mainText ); if ( count( $parts ) === 2 && $parts[0] === $this->specialContributionsName ) { // Normalize the username: users may link to their contributions with an unnormalized name diff --git a/includes/Hooks/HookUtils.php b/includes/Hooks/HookUtils.php index e911fb326..7a2631ceb 100644 --- a/includes/Hooks/HookUtils.php +++ b/includes/Hooks/HookUtils.php @@ -386,7 +386,7 @@ class HookUtils { static::hasPagePropCached( $title, 'newsectionlink' ) && // excluding the main namespace, unless it has been configured for signatures ( - $title->getNamespace() !== NS_MAIN || + !$title->inNamespace( NS_MAIN ) || $services->getNamespaceInfo()->wantSignatures( $title->getNamespace() ) ) ); @@ -595,7 +595,7 @@ class HookUtils { $namespaceInfo = $services->getNamespaceInfo(); Assert::precondition( $namespaceInfo->isTalk( $talkPage->getNamespace() ), "Page is a talk page" ); - if ( $talkPage->getNamespace() === NS_USER_TALK && !str_contains( $talkPage->getText(), '/' ) ) { + if ( $talkPage->inNamespace( NS_USER_TALK ) && !str_contains( $talkPage->getText(), '/' ) ) { if ( $services->getUserNameUtils()->isIP( $talkPage->getText() ) ) { return true; } diff --git a/includes/Hooks/PageHooks.php b/includes/Hooks/PageHooks.php index 5f825bcb5..dc55c6c9c 100644 --- a/includes/Hooks/PageHooks.php +++ b/includes/Hooks/PageHooks.php @@ -438,7 +438,7 @@ class PageHooks implements $descParams = []; $buttonMsg = 'discussiontools-emptystate-button'; $title = $context->getTitle(); - if ( $title->getNamespace() === NS_USER_TALK && !$title->isSubpage() ) { + if ( $title->inNamespace( NS_USER_TALK ) && !$title->isSubpage() ) { // This is a user talk page $isIP = $this->userNameUtils->isIP( $title->getText() ); $isTemp = $this->userNameUtils->isTemp( $title->getText() ); diff --git a/includes/ThreadItem/ContentCommentItem.php b/includes/ThreadItem/ContentCommentItem.php index e90b426f1..bf59bdc13 100644 --- a/includes/ThreadItem/ContentCommentItem.php +++ b/includes/ThreadItem/ContentCommentItem.php @@ -135,7 +135,7 @@ class ContentCommentItem extends ContentThreadItem implements CommentItem { if ( $href ) { $siteConfig = MediaWikiServices::getInstance()->getMainConfig(); $title = Title::newFromText( CommentUtils::getTitleFromUrl( $href, $siteConfig ) ); - if ( $title && $title->getNamespace() === NS_USER ) { + if ( $title && $title->inNamespace( NS_USER ) ) { // TODO: Consider returning User objects $users[] = $title; }