2021-01-28 11:19:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Citizen - A responsive skin developed for the Star Citizen Wiki
|
|
|
|
*
|
|
|
|
* This file is part of Citizen.
|
|
|
|
*
|
|
|
|
* Citizen is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Citizen is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Citizen. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Skins
|
|
|
|
*/
|
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
declare( strict_types=1 );
|
2021-01-28 11:19:50 +00:00
|
|
|
|
2022-05-26 20:54:52 +00:00
|
|
|
namespace MediaWiki\Skins\Citizen\Partials;
|
2021-01-28 11:19:50 +00:00
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use Skin;
|
2022-05-22 19:06:49 +00:00
|
|
|
use User;
|
2021-01-28 11:19:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Header partial of Skin Citizen
|
|
|
|
* Generates the following partials:
|
2022-10-05 22:22:40 +00:00
|
|
|
* - User Menu
|
2021-01-28 11:19:50 +00:00
|
|
|
* - Search
|
|
|
|
*/
|
2021-01-28 19:34:46 +00:00
|
|
|
final class Header extends Partial {
|
2021-01-28 11:21:58 +00:00
|
|
|
/**
|
2022-10-05 02:40:23 +00:00
|
|
|
* Decorate search box template data
|
2021-01-28 11:21:58 +00:00
|
|
|
*
|
2022-10-05 02:40:23 +00:00
|
|
|
* @param array $searchBoxData original data-search-box
|
2021-01-28 11:21:58 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2022-10-05 02:40:23 +00:00
|
|
|
public function decorateSearchBoxData( $searchBoxData ): array {
|
2022-10-05 02:40:52 +00:00
|
|
|
return $searchBoxData += [
|
2022-10-05 02:40:23 +00:00
|
|
|
'msg-citizen-search-toggle-shortcut' => '[/]',
|
2021-01-28 11:21:58 +00:00
|
|
|
'html-random-href' => Skin::makeSpecialUrl( 'Randompage' ),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-05 21:23:51 +00:00
|
|
|
* Get the user info template data for user menu
|
2022-10-05 21:52:55 +00:00
|
|
|
*
|
2022-10-05 21:52:19 +00:00
|
|
|
* TODO: Consider dropping Menu.mustache since the DOM doesn't make much sense
|
2021-01-28 11:21:58 +00:00
|
|
|
*
|
2022-10-05 21:23:51 +00:00
|
|
|
* @param $userPageData data-portlets.data-user-page
|
2022-05-18 06:56:15 +00:00
|
|
|
* @return array
|
2021-01-28 11:21:58 +00:00
|
|
|
*/
|
2022-10-05 21:23:51 +00:00
|
|
|
public function getUserInfoData( $userPageData ): array {
|
|
|
|
$isRegistered = $this->user->isRegistered();
|
|
|
|
|
|
|
|
$html = $this->getUserPageHTML( $isRegistered, $userPageData );
|
|
|
|
|
|
|
|
if ( $isRegistered ) {
|
|
|
|
$html .= $this->getUserGroupsHTML();
|
|
|
|
$html .= $this->getUserContributionsHTML();
|
2022-06-02 14:46:14 +00:00
|
|
|
}
|
2022-05-17 02:52:04 +00:00
|
|
|
|
2022-10-05 21:23:51 +00:00
|
|
|
return [
|
|
|
|
'id' => 'p-user-info',
|
|
|
|
'html-items' => $html,
|
|
|
|
];
|
2022-05-17 02:52:04 +00:00
|
|
|
}
|
2021-01-28 11:21:58 +00:00
|
|
|
|
2022-05-17 02:52:04 +00:00
|
|
|
/**
|
2022-10-05 21:23:51 +00:00
|
|
|
* Get the user page HTML
|
2022-05-17 02:52:04 +00:00
|
|
|
*
|
2022-10-05 21:23:51 +00:00
|
|
|
* @param bool $isRegistered
|
|
|
|
* @param array $userPageData data-portlets.data-user-page
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getUserPageHTML( $isRegistered, $userPageData ): ?string {
|
|
|
|
if ( $isRegistered ) {
|
|
|
|
$html = $userPageData['html-items'];
|
|
|
|
} else {
|
|
|
|
// There must be a cleaner way to do this
|
|
|
|
$msg = $this->skin->msg( 'notloggedin' )->text();
|
|
|
|
$tooltip = $this->skin->msg( 'tooltip-pt-anonuserpage' )->text();
|
|
|
|
$html = <<<HTML
|
|
|
|
<li id="pt-anonuserpage" class="mw-list-item">
|
|
|
|
<span title="$tooltip">$msg</span>
|
|
|
|
</li>
|
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the user groups HTML
|
2022-05-17 02:52:04 +00:00
|
|
|
*
|
2022-10-05 21:23:51 +00:00
|
|
|
* @return string|null
|
2022-05-17 02:52:04 +00:00
|
|
|
*/
|
2022-10-05 21:23:51 +00:00
|
|
|
private function getUserGroupsHTML(): ?string {
|
2021-01-28 11:21:58 +00:00
|
|
|
// This does not return implicit groups
|
2022-10-05 21:23:51 +00:00
|
|
|
$groups = MediaWikiServices::getInstance()->getUserGroupManager()->getUserGroups( $this->user );
|
2021-03-09 20:04:48 +00:00
|
|
|
|
2022-05-17 02:52:04 +00:00
|
|
|
if ( empty( $groups ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-01-28 11:21:58 +00:00
|
|
|
|
2022-10-05 21:23:51 +00:00
|
|
|
$html = '';
|
2022-05-17 02:52:04 +00:00
|
|
|
$msgName = 'group-%s';
|
|
|
|
|
2022-10-05 21:23:51 +00:00
|
|
|
// There must be a cleaner way
|
2022-05-17 02:52:04 +00:00
|
|
|
foreach ( $groups as $group ) {
|
2022-10-05 21:23:51 +00:00
|
|
|
$id = sprintf( $msgName, $group );
|
|
|
|
$msg = $this->skin->msg( $id )->text();
|
2023-02-10 15:06:06 +00:00
|
|
|
$title = $this->title->newFromText(
|
2022-10-05 21:23:51 +00:00
|
|
|
$this->skin->msg( sprintf( $msgName, $group ) )->text(),
|
|
|
|
NS_PROJECT
|
2023-02-10 15:06:06 +00:00
|
|
|
);
|
|
|
|
if ( $title ) {
|
|
|
|
$href = $title->getLinkURL();
|
|
|
|
$html .= <<< HTML
|
|
|
|
<li>
|
|
|
|
<a href="$href" id="$id">$msg</a>
|
|
|
|
</li>
|
|
|
|
HTML;
|
|
|
|
}
|
2021-01-28 11:21:58 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 21:23:51 +00:00
|
|
|
$html = sprintf( '<li id="pt-usergroups"><ul>%s</ul></li>', $html );
|
|
|
|
|
|
|
|
return $html;
|
2022-05-17 02:52:04 +00:00
|
|
|
}
|
2021-03-09 20:04:48 +00:00
|
|
|
|
2022-05-17 02:52:04 +00:00
|
|
|
/**
|
2022-10-05 21:23:51 +00:00
|
|
|
* Get the user contributions HTML
|
2022-05-17 02:52:04 +00:00
|
|
|
*
|
2022-10-05 21:23:51 +00:00
|
|
|
* @return string|null
|
2022-05-17 02:52:04 +00:00
|
|
|
*/
|
2022-10-05 21:23:51 +00:00
|
|
|
private function getUserContributionsHTML(): ?string {
|
2022-05-17 02:52:04 +00:00
|
|
|
// Return user edits
|
2022-10-05 21:23:51 +00:00
|
|
|
$edits = MediaWikiServices::getInstance()->getUserEditTracker()->getUserEditCount( $this->user );
|
2021-01-28 11:21:58 +00:00
|
|
|
|
2022-05-17 02:52:04 +00:00
|
|
|
if ( empty( $edits ) ) {
|
|
|
|
return null;
|
2021-01-28 11:21:58 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 21:23:51 +00:00
|
|
|
$editsText = $this->skin->msg( 'usereditcount' )
|
|
|
|
->numParams( sprintf( '%s', number_format( $edits, 0 ) ) );
|
2022-05-22 19:06:49 +00:00
|
|
|
|
2022-10-05 21:23:51 +00:00
|
|
|
// There must be a cleaner way
|
|
|
|
$html = '<li id="pt-usercontris">' . $editsText . '</li>';
|
|
|
|
|
|
|
|
return $html;
|
2021-01-28 11:21:58 +00:00
|
|
|
}
|
2021-01-28 11:19:50 +00:00
|
|
|
}
|