localizer = $localizer;
$this->out = $out;
$this->pageLang = $pageLang;
$this->title = $title;
$this->titleData = $titleData;
$this->user = $user;
}
/**
* Check if the current page is in the content namespace
*
* @return bool
*/
private function shouldAddParenthesis(): bool {
$ns = $this->title->getNamespace();
$contentNs = MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
return in_array( $ns, $contentNs );
}
/**
* Return new User object based on username or IP address.
* Based on MinervaNeue
*
* @return UserIdentity|null
*/
private function buildPageUserObject() {
$titleText = $this->title->getText();
$user = $this->user;
if ( IPUtils::isIPAddress( $titleText ) ) {
return $user->newFromAnyId( null, $titleText, null );
}
$userIdentity = MediaWikiServices::getInstance()->getUserIdentityLookup()->getUserIdentityByName( $titleText );
if ( $userIdentity && $userIdentity->isRegistered() ) {
return $user->newFromId( $userIdentity->getId() );
}
return null;
}
/**
* Return user tagline message
*
* @return string
*/
private function buildUserTagline(): string {
$localizer = $this->localizer;
$user = $this->buildPageUserObject();
if ( $user ) {
$tagline = '
';
$editCount = $user->getEditCount();
$regDate = $user->getRegistration();
$gender = MediaWikiServices::getInstance()->getGenderCache()->getGenderOf( $user, __METHOD__ );
if ( $gender === 'male' ) {
$msgGender = '♂';
} elseif ( $gender === 'female' ) {
$msgGender = '♀';
}
if ( isset( $msgGender ) ) {
$tagline .= "
$msgGender";
}
if ( $editCount ) {
$msgEditCount = $localizer->msg( 'usereditcount' )->numParams( sprintf( '%s', number_format( $editCount, 0 ) ) );
// TODO: Replace with SkinComponentUtils on 1.43
$editCountHref = SpecialPage::getTitleFor( 'Contributions', $user )->getLocalURL();
$tagline .= "
$msgEditCount";
}
if ( is_string( $regDate ) ) {
$regDateTs = wfTimestamp( TS_UNIX, $regDate );
$msgRegDate = $localizer->msg( 'citizen-tagline-user-regdate', $this->pageLang->userDate( new MWTimestamp( $regDate ), $this->user ), $user );
$tagline .= "
$msgRegDate";
}
$tagline .= '
';
return $tagline;
}
return '';
}
/**
* Return the modified page heading HTML
*
* @return string
*/
private function getPageHeading(): string {
$titleHtml = $this->titleData;
if ( $this->shouldAddParenthesis() ) {
// Look for the to ensure that it is the last parenthesis of the title
$pattern = '/\s?(\p{Ps}.+\p{Pe})<\/span>/';
$replacement = '