feat(core): expand user page tagline and allow citizen-tagline to be parsed (#657)

* Add registration date to user tagline
* Add contribution link to edit count in user tagline
* Add gender to user tagline
* Allow `citizen-tagline` to be fully parsed

---------

Co-authored-by: alistair3149 <alistair3149@users.noreply.github.com>
This commit is contained in:
沈澄心 2023-06-09 04:03:48 +08:00 committed by GitHub
parent 8351aa5203
commit 25d25e381b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 15 deletions

View file

@ -33,6 +33,7 @@
"citizen-search-empty-desc": "Type to start searching",
"citizen-search-noresults-title": "Uh oh! No results for $1",
"citizen-search-noresults-desc": "Maybe try the options below?",
"citizen-tagline": "-",
"citizen-tagline-ns-talk": "Discussion page of {{SUBJECTPAGENAME}}",
"citizen-tagline-ns-project": "Information about {{SITENAME}}",
"citizen-tagline-ns-file": "File on {{SITENAME}}",
@ -40,6 +41,16 @@
"citizen-tagline-ns-template": "Template page",
"citizen-tagline-ns-help": "Help page",
"citizen-tagline-ns-category": "Category page",
"citizen-tagline-user-regdate": "Joined $1",
"citizen-pronouns-subjective-male": "He",
"citizen-pronouns-objective-male": "Him",
"citizen-pronouns-possessive-male": "His",
"citizen-pronouns-subjective-female": "She",
"citizen-pronouns-objective-female": "Her",
"citizen-pronouns-possessive-female": "Hers",
"citizen-pronouns-subjective-notknown": "They",
"citizen-pronouns-objective-notknown": "Them",
"citizen-pronouns-possessive-notknown": "Theirs",
"prefs-citizen-theme-label": "Theme",
"prefs-citizen-theme-option-auto": "Auto",
"prefs-citizen-theme-option-light": "Light",

View file

@ -38,6 +38,7 @@
"citizen-search-empty-desc": "Helper text in the search suggestion when there are no search query",
"citizen-search-noresults-title": "Title in the search suggestion when there are no search results",
"citizen-search-noresults-desc": "Description in the search suggestion when there are no search results",
"citizen-tagline": "{{notranslate}}\n\nTagline for Citizen skin only",
"citizen-tagline-ns-talk": "Tagline for pages in talk namespace",
"citizen-tagline-ns-project": "Tagline for pages in project namespace",
"citizen-tagline-ns-file": "Tagline for pages in file namespace",
@ -45,6 +46,16 @@
"citizen-tagline-ns-template": "Tagline for pages in template namespace",
"citizen-tagline-ns-help": "Tagline for pages in help namespace",
"citizen-tagline-ns-category": "Tagline for pages in category namespace",
"citizen-tagline-user-regdate": "Label for registration date in taglines on userpages",
"citizen-pronouns-subjective-male": "Male subjective pronoun",
"citizen-pronouns-objective-male": "Male objective pronoun",
"citizen-pronouns-possessive-male": "Male possessive pronoun",
"citizen-pronouns-subjective-female": "Female subjective pronoun",
"citizen-pronouns-objective-female": "Female objective pronoun",
"citizen-pronouns-possessive-female": "Female possessive pronoun",
"citizen-pronouns-subjective-notknown": "Neutral subjective pronoun",
"citizen-pronouns-objective-notknown": "Neutral objective pronoun",
"citizen-pronouns-possessive-notknown": "Neutral possessive pronoun",
"prefs-citizen-theme-label": "Tooltip for the theme dropdown in Special:Preferences",
"prefs-citizen-theme-option-auto": "Label for the auto theme option",
"prefs-citizen-theme-option-light": "Label for the light theme option",

View file

@ -26,6 +26,8 @@ declare( strict_types=1 );
namespace MediaWiki\Skins\Citizen\Partials;
use MediaWiki\MediaWikiServices;
use MWTimestamp;
use SpecialPage;
use Title;
use User;
use Wikimedia\IPUtils;
@ -61,23 +63,26 @@ final class Tagline extends Partial {
$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() ) {
$tagline = $skin->msg( 'citizen-tagline-ns-talk' )->parse();
} elseif ( ( $title->inNamespace( NS_USER ) || ( defined( 'NS_USER_WIKI' ) && $title->inNamespace( NS_USER_WIKI ) ) || ( defined( 'NS_USER_WIKI' ) && $title->inNamespace( NS_USER_PROFILE ) ) ) && !$title->isSubpage() ) {
// Build user tagline if it is a top-level user page
$tagline = $this->buildUserTagline( $title );
} 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();
}
@ -105,16 +110,35 @@ final class Tagline extends Partial {
private function buildUserTagline( $title ) {
$user = $this->buildPageUserObject( $title );
if ( $user ) {
$skin = $this->skin;
$tagline = '<div id="citizen-tagline-user">';
$editCount = $user->getEditCount();
$regDate = $user->getRegistration();
$gender = MediaWikiServices::getInstance()->getGenderCache()->getGenderOf( $user, __METHOD__ );
$msgGender = sprintf(
'%s / %s / %s',
$skin->msg( 'citizen-pronouns-subjective-' . $gender )->text(),
$skin->msg( 'citizen-pronouns-objective-' . $gender )->text(),
$skin->msg( 'citizen-pronouns-possessive-' . $gender )->text()
);
$tagline .= "<span id=\"citizen-tagline-user-gender\" data-user-gender=\"$gender\">$msgGender</span>";
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;
$msgEditCount = $skin->msg( 'usereditcount' )->numParams( sprintf( '%s', number_format( $editCount, 0 ) ) );
$editCountHref = SpecialPage::getTitleFor( 'Contributions', $user )->getLocalURL();
$tagline .= "<span id=\"citizen-tagline-user-editcount\" data-user-editcount=\"$editCount\"><a href=\"$editCountHref\">$msgEditCount</a></span>";
}
if ( is_string( $regDate ) ) {
$regDateTs = wfTimestamp( TS_UNIX, $regDate );
$msgRegDate = $skin->msg( 'citizen-tagline-user-regdate', $skin->getLanguage()->userDate( new MWTimestamp( $regDate ), $skin->getUser() ), $user );
$tagline .= "<span id=\"citizen-tagline-user-regdate\" data-user-regdate=\"$regDateTs\">$msgRegDate</span>";
}
$tagline .= '</div>';
return $tagline;
}
return null;
}

View file

@ -4,8 +4,8 @@
* Module: mediawiki.skinning.interface-subtitle
* Version: REL1_39
*
* Date: 2022-11-15
*/
* Date: 2023-06-06
*/
#siteSub {
display: block;
@ -30,6 +30,17 @@
margin-top: ~'calc( var( --space-xs ) * -1 )';
}
#citizen-tagline-user > span::after {
content: "·";
margin: 0 var( --space-xxs );
-webkit-user-select: none;
user-select: none;
}
#citizen-tagline-user > span:last-child:after {
display: none;
}
span.subpages {
display: block;
}

View file

@ -11,9 +11,9 @@
{{{html-title-heading--formatted}}}
{{>Indicators}}
</div>
<div id="siteSub">{{html-tagline}}</div>
<div id="siteSub">{{{html-tagline}}}</div>
<a href="#top" class="citizen-jumptotop" title="{{html-citizen-jumptotop}}"></a>
</div>
{{>PageTools}}
</header>
<div id="citizen-body-header-sticky-sentinel"></div>
<div id="citizen-body-header-sticky-sentinel"></div>