Introduce UserLinks and LanguageButton components

Bug: T322089
Change-Id: I0bf504b2c9c129ef56c95c2370204ee20a41bd7a
This commit is contained in:
Jon Robson 2022-12-07 11:31:14 -08:00 committed by Jdlrobson
parent dba4fa6265
commit bcb2a73ba1
3 changed files with 47 additions and 10 deletions

View file

@ -0,0 +1,24 @@
<?php
namespace MediaWiki\Skins\Vector\Components;
use MediaWiki\Skins\Vector\Hooks;
/**
* VectorComponentLanguageButton component
*/
class VectorComponentLanguageButton implements VectorComponent {
/**
* @inheritDoc
*/
public function getTemplateData(): array {
return [
'id' => 'p-lang-btn-sticky-header',
'class' => 'mw-interlanguage-selector',
'is-quiet' => true,
'tabindex' => '-1',
'html-vector-button-icon' => Hooks::makeIcon( 'wikimedia-language' ),
'event' => 'ui.dropdown-p-lang-btn-sticky-header'
];
}
}

View file

@ -0,0 +1,15 @@
<?php
namespace MediaWiki\Skins\Vector\Components;
/**
* VectorComponentUserLinks component
*/
class VectorComponentUserLinks implements VectorComponent {
/**
* @inheritDoc
*/
public function getTemplateData(): array {
return [];
}
}

View file

@ -27,6 +27,8 @@ namespace MediaWiki\Skins\Vector;
use ExtensionRegistry;
use Linker;
use MediaWiki\MediaWikiServices;
use MediaWiki\Skins\Vector\Components\VectorComponentLanguageButton;
use MediaWiki\Skins\Vector\Components\VectorComponentUserLinks;
use RuntimeException;
use SkinMustache;
use SkinTemplate;
@ -266,7 +268,7 @@ abstract class SkinVector extends SkinMustache {
/**
* Returns template data for UserLinks.mustache
* FIXME: Move to component (T322089)
* FIXME: Move to VectorComponentUserLinks (T322089)
*
* @param array $userMenuData existing menu template data to be transformed and copied for UserLinks
* @param array $overflowMenuData existing menu template data to be transformed and copied for UserLinks
@ -300,8 +302,9 @@ abstract class SkinVector extends SkinMustache {
$additionalData = [];
}
$userLinks = new VectorComponentUserLinks();
$moreItems = substr_count( $userMenuOverflowData['html-items'], '<li' );
return $additionalData + [
return $userLinks->getTemplateData() + $additionalData + [
'html-logout-link' => $this->getLogoutHTML(),
'is-temp-user' => $isTempUser,
'is-wide' => $moreItems > 3,
@ -461,15 +464,10 @@ abstract class SkinVector extends SkinMustache {
*/
private function getULSButtonData() {
$numLanguages = count( $this->getLanguagesCached() );
$langButton = new VectorComponentLanguageButton();
return [
'id' => 'p-lang-btn-sticky-header',
'class' => 'mw-interlanguage-selector',
'is-quiet' => true,
'tabindex' => '-1',
return $langButton->getTemplateData() + [
'label' => $this->getULSLabels()[ 'label' ],
'html-vector-button-icon' => Hooks::makeIcon( 'wikimedia-language' ),
'event' => 'ui.dropdown-p-lang-btn-sticky-header'
];
}
@ -512,7 +510,7 @@ abstract class SkinVector extends SkinMustache {
/**
* Creates portlet data for the user menu dropdown
* FIXME: Move to SkinVector22
* FIXME: Move to VectorComponentUserMenu
*
* @param array $portletData
* @return array