Merge "Use upstream Title::inNamespace() instead of manual comparisons"

This commit is contained in:
jenkins-bot 2023-12-04 23:09:28 +00:00 committed by Gerrit Code Review
commit 957788d9d5
4 changed files with 7 additions and 8 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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() );

View file

@ -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;
}