Skip to content

Commit

Permalink
fix: tagline.php
Browse files Browse the repository at this point in the history
  • Loading branch information
WaitSpringQW committed Sep 29, 2024
1 parent 8700a8b commit 2a0c500
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions includes/Partials/Tagline.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace MediaWiki\Skins\Citizen\Partials;

use MediaWiki\MediaWikiServices;
use Title;
use MediaWiki\Title\Title;
use User;
use Wikimedia\IPUtils;

Expand Down Expand Up @@ -61,23 +61,23 @@ public function getTagline() {
$msg = $skin->msg( 'citizen-tagline-ns-' . strtolower( $namespaceText ) );
// Use custom message if exists
if ( !$msg->isDisabled() ) {
$tagline = $msg->text();
$tagline = $msg->parse();
} else {
if ( $title->isSpecialPage() ) {
// No tagline if special page
$tagline = '';
} elseif ( $title->isTalkPage() ) {
// Use generic talk page message if talk page
$tagline = $skin->msg( 'citizen-tagline-ns-talk' )->text();

} elseif ( $title->inNamespace( NS_USER ) && !$title->isSubpage() ) {
// Build user tagline if it is a top-level user page
$tagline = $this->buildUserTagline( $title );
$tagline = $skin->msg( 'citizen-tagline-ns-talk' )->parse();
} elseif ( !$skin->msg( 'citizen-tagline' )->isDisabled() ) {
$tagline = $skin->msg( 'citizen-tagline' )->parse();
} else {
// Fallback to site tagline
$tagline = $skin->msg( 'tagline' )->text();
}
}
} elseif ( !$skin->msg( 'citizen-tagline' )->isDisabled() ) {
$tagline = $skin->msg( 'citizen-tagline' )->parse();
} else {
$tagline = $skin->msg( 'tagline' )->text();
}
Expand All @@ -96,29 +96,6 @@ public function getTagline() {
return $tagline;
}

/**
* Return user tagline message
*
* @param Title $title
* @return string
*/
private function buildUserTagline( $title ) {
$user = $this->buildPageUserObject( $title );
if ( $user ) {
$editCount = $user->getEditCount();
if ( $editCount ) {
$skin = $this->skin;
// TODO: Figure out a waw to get registration duration,
// like Langauge::getHumanTimestamp()
//$registration = $user->getRegistration();
$msgEditCount = $skin->msg( 'usereditcount' )
->numParams( sprintf( '%s', number_format( $editCount, 0 ) ) );
return $msgEditCount;
}
}
return null;
}

/**
* Return new User object based on username or IP address.
* Based on MinervaNeue
Expand All @@ -134,9 +111,9 @@ private function buildPageUserObject( $title ) {
return $user->newFromAnyId( null, $titleText, null );
}

$pageUserId = $user->idFromName( $titleText );
if ( $pageUserId ) {
return $user->newFromId( $pageUserId );
$userIdentity = MediaWikiServices::getInstance()->getUserIdentityLookup()->getUserIdentityByName( $titleText );
if ( $userIdentity && $userIdentity->isRegistered() ) {
return $user->newFromId( $userIdentity->getId() );
}

return null;
Expand Down

0 comments on commit 2a0c500

Please sign in to comment.