mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-28 00:01:05 +00:00
ci: 👷 lint code to MediaWiki standards
Check commit and GitHub actions for more details
This commit is contained in:
parent
d4d71dc34a
commit
1827a1b5c9
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace MediaWiki\Skins\Citizen\Components;
|
namespace MediaWiki\Skins\Citizen\Components;
|
||||||
|
|
||||||
|
@ -13,8 +13,7 @@ use MessageLocalizer;
|
||||||
/**
|
/**
|
||||||
* CitizenComponentUserInfo component
|
* CitizenComponentUserInfo component
|
||||||
*/
|
*/
|
||||||
class CitizenComponentUserInfo implements CitizenComponent
|
class CitizenComponentUserInfo implements CitizenComponent {
|
||||||
{
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $isRegistered;
|
private $isRegistered;
|
||||||
|
|
||||||
|
@ -62,20 +61,19 @@ class CitizenComponentUserInfo implements CitizenComponent
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
private function getUserEditCount(): ?array
|
private function getUserEditCount(): ?array {
|
||||||
{
|
|
||||||
// Return user edits
|
// Return user edits
|
||||||
$edits = MediaWikiServices::getInstance()->getUserEditTracker()->getUserEditCount($this->user);
|
$edits = MediaWikiServices::getInstance()->getUserEditTracker()->getUserEditCount( $this->user );
|
||||||
|
|
||||||
if (empty($edits)) {
|
if ( empty( $edits ) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$label = $this->localizer->msg('usereditcount')->numParams($edits);
|
$label = $this->localizer->msg( 'usereditcount' )->numParams( $edits );
|
||||||
$label = str_replace($edits, '', $label);
|
$label = str_replace( $edits, '', $label );
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'count' => number_format($edits, 0),
|
'count' => number_format( $edits, 0 ),
|
||||||
'label' => $label
|
'label' => $label
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -85,35 +83,34 @@ class CitizenComponentUserInfo implements CitizenComponent
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
private function getUserGroups(): ?array
|
private function getUserGroups(): ?array {
|
||||||
{
|
$groups = MediaWikiServices::getInstance()->getUserGroupManager()->getUserGroups( $this->user );
|
||||||
$groups = MediaWikiServices::getInstance()->getUserGroupManager()->getUserGroups($this->user);
|
|
||||||
|
|
||||||
if (empty($groups)) {
|
if ( empty( $groups ) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$listItems = [];
|
$listItems = [];
|
||||||
$msgKey = 'group-%s-member';
|
$msgKey = 'group-%s-member';
|
||||||
foreach ($groups as $group) {
|
foreach ( $groups as $group ) {
|
||||||
$id = sprintf($msgKey, $group);
|
$id = sprintf( $msgKey, $group );
|
||||||
$text = $this->localizer->msg($id)->text();
|
$text = $this->localizer->msg( $id )->text();
|
||||||
try {
|
try {
|
||||||
$title = $this->title->newFromTextThrow($text, NS_PROJECT);
|
$title = $this->title->newFromTextThrow( $text, NS_PROJECT );
|
||||||
} catch (MalformedTitleException $e) {
|
} catch ( MalformedTitleException $e ) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$text || !$title) {
|
if ( !$text || !$title ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$link = new CitizenComponentLink(
|
$link = new CitizenComponentLink(
|
||||||
$title->getLinkURL(),
|
$title->getLinkURL(),
|
||||||
ucfirst($text)
|
ucfirst( $text )
|
||||||
);
|
);
|
||||||
|
|
||||||
$listItem = new CitizenComponentMenuListItem($link, 'citizen-userInfo-usergroup', $id);
|
$listItem = new CitizenComponentMenuListItem( $link, 'citizen-userInfo-usergroup', $id );
|
||||||
|
|
||||||
$listItems[] = $listItem->getTemplateData();
|
$listItems[] = $listItem->getTemplateData();
|
||||||
}
|
}
|
||||||
|
@ -128,14 +125,13 @@ class CitizenComponentUserInfo implements CitizenComponent
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getUserPage(): array
|
private function getUserPage(): array {
|
||||||
{
|
|
||||||
$user = $this->user;
|
$user = $this->user;
|
||||||
$userPageData = $this->userPageData;
|
$userPageData = $this->userPageData;
|
||||||
|
|
||||||
$htmlItems = $userPageData['html-items'];
|
$htmlItems = $userPageData['html-items'];
|
||||||
$realname = $user->getRealName();
|
$realname = $user->getRealName();
|
||||||
if (!empty($realname)) {
|
if ( !empty( $realname ) ) {
|
||||||
$username = $user->getName();
|
$username = $user->getName();
|
||||||
$innerHtml = <<<HTML
|
$innerHtml = <<<HTML
|
||||||
<span id="pt-userpage-realname">$realname</span>
|
<span id="pt-userpage-realname">$realname</span>
|
||||||
|
@ -149,12 +145,12 @@ class CitizenComponentUserInfo implements CitizenComponent
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$menu = new CitizenComponentMenu([
|
$menu = new CitizenComponentMenu( [
|
||||||
'id' => 'citizen-user-menu-userpage',
|
'id' => 'citizen-user-menu-userpage',
|
||||||
'class' => null,
|
'class' => null,
|
||||||
'label' => null,
|
'label' => null,
|
||||||
'html-items' => $htmlItems
|
'html-items' => $htmlItems
|
||||||
]);
|
] );
|
||||||
|
|
||||||
return $menu->getTemplateData();
|
return $menu->getTemplateData();
|
||||||
}
|
}
|
||||||
|
@ -162,26 +158,25 @@ class CitizenComponentUserInfo implements CitizenComponent
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function getTemplateData(): array
|
public function getTemplateData(): array {
|
||||||
{
|
|
||||||
$localizer = $this->localizer;
|
$localizer = $this->localizer;
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
if ($this->isRegistered) {
|
if ( $this->isRegistered ) {
|
||||||
$data = [
|
$data = [
|
||||||
'data-user-page' => $this->getUserPage(),
|
'data-user-page' => $this->getUserPage(),
|
||||||
'data-user-edit' => $this->getUserEditCount()
|
'data-user-edit' => $this->getUserEditCount()
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->isTemp) {
|
if ( $this->isTemp ) {
|
||||||
$data['text'] = $localizer->msg('citizen-user-info-text-temp');
|
$data['text'] = $localizer->msg( 'citizen-user-info-text-temp' );
|
||||||
} else {
|
} else {
|
||||||
$data['data-user-groups'] = $this->getUserGroups();
|
$data['data-user-groups'] = $this->getUserGroups();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$data = [
|
$data = [
|
||||||
'title' => $localizer->msg('notloggedin'),
|
'title' => $localizer->msg( 'notloggedin' ),
|
||||||
'text' => $localizer->msg('citizen-user-info-text-anon')
|
'text' => $localizer->msg( 'citizen-user-info-text-anon' )
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue