2022-10-27 23:52:23 +00:00
|
|
|
<?php
|
|
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
|
2022-12-14 20:57:25 +00:00
|
|
|
use MediaWiki\Skins\Vector\Constants;
|
|
|
|
use MediaWiki\Skins\Vector\FeatureManagement\FeatureManager;
|
2022-11-30 22:22:33 +00:00
|
|
|
use MessageLocalizer;
|
2022-10-27 23:52:23 +00:00
|
|
|
use Skin;
|
2022-11-30 22:22:33 +00:00
|
|
|
use User;
|
2022-10-27 23:52:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* VectorComponentMainMenu component
|
|
|
|
*/
|
|
|
|
class VectorComponentMainMenu implements VectorComponent {
|
|
|
|
/** @var VectorComponent|null */
|
|
|
|
private $optOut;
|
|
|
|
/** @var VectorComponent|null */
|
|
|
|
private $alert;
|
|
|
|
/** @var array */
|
|
|
|
private $sidebarData;
|
2022-11-30 22:22:33 +00:00
|
|
|
/** @var array */
|
|
|
|
private $languageData;
|
|
|
|
/** @var MessageLocalizer */
|
|
|
|
private $localizer;
|
2022-12-14 20:57:25 +00:00
|
|
|
/** @var bool */
|
|
|
|
private $isPinned;
|
2022-12-13 20:28:22 +00:00
|
|
|
/** @var VectorComponentPinnableHeader|null */
|
|
|
|
private $pinnableHeader;
|
|
|
|
/** @var string */
|
|
|
|
public const ID = 'vector-main-menu';
|
2022-10-27 23:52:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $sidebarData
|
|
|
|
* @param bool $shouldLanguageAlertBeInSidebar
|
2023-05-19 16:45:26 +00:00
|
|
|
* @param int $numLanguages
|
2022-11-30 22:22:33 +00:00
|
|
|
* @param array $languageData
|
2022-12-13 20:28:22 +00:00
|
|
|
* @param MessageLocalizer $localizer
|
|
|
|
* @param User $user
|
2022-12-14 20:57:25 +00:00
|
|
|
* @param FeatureManager $featureManager
|
2022-12-13 20:28:22 +00:00
|
|
|
* @param Skin $skin
|
2022-10-27 23:52:23 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
array $sidebarData,
|
2022-11-30 22:22:33 +00:00
|
|
|
bool $shouldLanguageAlertBeInSidebar,
|
2023-05-19 16:45:26 +00:00
|
|
|
int $numLanguages,
|
2022-12-13 20:28:22 +00:00
|
|
|
array $languageData,
|
|
|
|
MessageLocalizer $localizer,
|
|
|
|
User $user,
|
2022-12-14 20:57:25 +00:00
|
|
|
FeatureManager $featureManager,
|
2022-12-13 20:28:22 +00:00
|
|
|
Skin $skin
|
2022-10-27 23:52:23 +00:00
|
|
|
) {
|
|
|
|
$this->sidebarData = $sidebarData;
|
2022-11-30 22:22:33 +00:00
|
|
|
$this->languageData = $languageData;
|
2022-12-13 20:28:22 +00:00
|
|
|
$this->localizer = $localizer;
|
2022-12-15 22:52:24 +00:00
|
|
|
$this->isPinned = $featureManager->isFeatureEnabled( Constants::FEATURE_MAIN_MENU_PINNED );
|
2022-12-13 20:28:22 +00:00
|
|
|
|
2023-03-27 20:29:34 +00:00
|
|
|
$this->pinnableHeader = new VectorComponentPinnableHeader(
|
|
|
|
$this->localizer,
|
|
|
|
$this->isPinned,
|
|
|
|
self::ID,
|
|
|
|
'main-menu-pinned'
|
|
|
|
);
|
|
|
|
|
2022-10-27 23:52:23 +00:00
|
|
|
if ( $user->isRegistered() ) {
|
|
|
|
$this->optOut = new VectorComponentMainMenuActionOptOut( $skin );
|
|
|
|
}
|
|
|
|
if ( $shouldLanguageAlertBeInSidebar ) {
|
2023-05-19 16:45:26 +00:00
|
|
|
$this->alert = new VectorComponentMainMenuActionLanguageSwitchAlert( $skin, $numLanguages );
|
2022-10-27 23:52:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
|
|
|
$action = $this->optOut;
|
|
|
|
$alert = $this->alert;
|
2022-12-13 20:28:22 +00:00
|
|
|
$pinnableHeader = $this->pinnableHeader;
|
2022-11-30 22:22:33 +00:00
|
|
|
|
2022-12-07 23:41:10 +00:00
|
|
|
$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 );
|
2022-12-14 20:57:25 +00:00
|
|
|
|
|
|
|
$pinnableContainer = new VectorComponentPinnableContainer( self::ID, $this->isPinned );
|
|
|
|
$pinnableElement = new VectorComponentPinnableElement( self::ID );
|
|
|
|
|
|
|
|
return $pinnableElement->getTemplateData() + $pinnableContainer->getTemplateData() + [
|
2022-12-07 23:41:10 +00:00
|
|
|
'data-portlets-first' => $firstPortlet->getTemplateData(),
|
|
|
|
'array-portlets-rest' => $portletsRest,
|
2022-10-27 23:52:23 +00:00
|
|
|
'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,
|
2022-12-13 20:28:22 +00:00
|
|
|
'data-pinnable-header' => $pinnableHeader ? $pinnableHeader->getTemplateData() : null,
|
2022-12-07 23:41:10 +00:00
|
|
|
'data-languages' => $languageMenu->getTemplateData(),
|
2022-10-27 23:52:23 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|