mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-01 10:46:54 +00:00
d1c0e6cd6f
The languages alert is misleading when there are no languages and the user has JS disabled. This change adds a class to the alert if there are 0 languages, and then adds "display: none" to the alert if the client-nojs class is present. This is the same approach being used for the language switcher button. Bug: T326185 Change-Id: Iee292d661ed1f47700f588053712f5f547022b17
100 lines
3 KiB
PHP
100 lines
3 KiB
PHP
<?php
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
use MediaWiki\Skins\Vector\Constants;
|
|
use MediaWiki\Skins\Vector\FeatureManagement\FeatureManager;
|
|
use MessageLocalizer;
|
|
use Skin;
|
|
use User;
|
|
|
|
/**
|
|
* VectorComponentMainMenu component
|
|
*/
|
|
class VectorComponentMainMenu implements VectorComponent {
|
|
/** @var VectorComponent|null */
|
|
private $optOut;
|
|
/** @var VectorComponent|null */
|
|
private $alert;
|
|
/** @var array */
|
|
private $sidebarData;
|
|
/** @var array */
|
|
private $languageData;
|
|
/** @var MessageLocalizer */
|
|
private $localizer;
|
|
/** @var bool */
|
|
private $isPinned;
|
|
/** @var VectorComponentPinnableHeader|null */
|
|
private $pinnableHeader;
|
|
/** @var string */
|
|
public const ID = 'vector-main-menu';
|
|
|
|
/**
|
|
* @param array $sidebarData
|
|
* @param bool $shouldLanguageAlertBeInSidebar
|
|
* @param int $numLanguages
|
|
* @param array $languageData
|
|
* @param MessageLocalizer $localizer
|
|
* @param User $user
|
|
* @param FeatureManager $featureManager
|
|
* @param Skin $skin
|
|
*/
|
|
public function __construct(
|
|
array $sidebarData,
|
|
bool $shouldLanguageAlertBeInSidebar,
|
|
int $numLanguages,
|
|
array $languageData,
|
|
MessageLocalizer $localizer,
|
|
User $user,
|
|
FeatureManager $featureManager,
|
|
Skin $skin
|
|
) {
|
|
$this->sidebarData = $sidebarData;
|
|
$this->languageData = $languageData;
|
|
$this->localizer = $localizer;
|
|
$this->isPinned = $featureManager->isFeatureEnabled( Constants::FEATURE_MAIN_MENU_PINNED );
|
|
|
|
$this->pinnableHeader = new VectorComponentPinnableHeader(
|
|
$this->localizer,
|
|
$this->isPinned,
|
|
self::ID,
|
|
'main-menu-pinned'
|
|
);
|
|
|
|
if ( $user->isRegistered() ) {
|
|
$this->optOut = new VectorComponentMainMenuActionOptOut( $skin );
|
|
}
|
|
if ( $shouldLanguageAlertBeInSidebar ) {
|
|
$this->alert = new VectorComponentMainMenuActionLanguageSwitchAlert( $skin, $numLanguages );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getTemplateData(): array {
|
|
$action = $this->optOut;
|
|
$alert = $this->alert;
|
|
$pinnableHeader = $this->pinnableHeader;
|
|
|
|
$portletsRest = [];
|
|
foreach ( $this->sidebarData[ 'array-portlets-rest' ] as $data ) {
|
|
$portletsRest[] = ( new VectorComponentMenu( $data ) )->getTemplateData();
|
|
}
|
|
$firstPortlet = new VectorComponentMenu( $this->sidebarData['data-portlets-first'] );
|
|
$languageMenu = new VectorComponentMenu( $this->languageData );
|
|
|
|
$pinnableContainer = new VectorComponentPinnableContainer( self::ID, $this->isPinned );
|
|
$pinnableElement = new VectorComponentPinnableElement( self::ID );
|
|
|
|
return $pinnableElement->getTemplateData() + $pinnableContainer->getTemplateData() + [
|
|
'data-portlets-first' => $firstPortlet->getTemplateData(),
|
|
'array-portlets-rest' => $portletsRest,
|
|
'data-main-menu-action' => $action ? $action->getTemplateData() : null,
|
|
// T295555 Add language switch alert message temporarily (to be removed).
|
|
'data-vector-language-switch-alert' => $alert ? $alert->getTemplateData() : null,
|
|
'data-pinnable-header' => $pinnableHeader ? $pinnableHeader->getTemplateData() : null,
|
|
'data-languages' => $languageMenu->getTemplateData(),
|
|
];
|
|
}
|
|
}
|