. * * @file * @ingroup Skins */ declare( strict_types=1 ); namespace MediaWiki\Skins\Citizen\Partials; use MediaWiki\MediaWikiServices; use Skin; use User; /** * Header partial of Skin Citizen * Generates the following partials: * - User Menu * - Search */ final class Header extends Partial { /** * Decorate search box template data * * @param array $searchBoxData original data-search-box * @return array */ public function decorateSearchBoxData( $searchBoxData ): array { return $searchBoxData += [ 'msg-citizen-search-toggle-shortcut' => '[/]', 'html-random-href' => Skin::makeSpecialUrl( 'Randompage' ), ]; } /** * Get the user info template data for user menu * * TODO: Consider dropping Menu.mustache since the DOM doesn't make much sense * * @param $userPageData data-portlets.data-user-page * @return array */ public function getUserInfoData( $userPageData ): array { $isRegistered = $this->user->isRegistered(); $html = $this->getUserPageHTML( $isRegistered, $userPageData ); if ( $isRegistered ) { $html .= $this->getUserGroupsHTML(); $html .= $this->getUserContributionsHTML(); } return [ 'id' => 'p-user-info', 'html-items' => $html, ]; } /** * Get the user page HTML * * @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 = << $msg HTML; } return $html; } /** * Get the user groups HTML * * @return string|null */ private function getUserGroupsHTML(): ?string { // This does not return implicit groups $groups = MediaWikiServices::getInstance()->getUserGroupManager()->getUserGroups( $this->user ); if ( empty( $groups ) ) { return null; } $html = ''; $msgName = 'group-%s'; // There must be a cleaner way foreach ( $groups as $group ) { $id = sprintf( $msgName, $group ); $msg = $this->skin->msg( $id )->text(); $title = $this->title->newFromText( $this->skin->msg( sprintf( $msgName, $group ) )->text(), NS_PROJECT ); if ( $title ) { $href = $title->getLinkURL(); $html .= <<< HTML