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;
|
2024-03-13 20:59:40 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2022-11-30 22:22:33 +00:00
|
|
|
use MessageLocalizer;
|
2022-10-27 23:52:23 +00:00
|
|
|
use Skin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VectorComponentMainMenu component
|
|
|
|
*/
|
|
|
|
class VectorComponentMainMenu implements VectorComponent {
|
|
|
|
/** @var VectorComponent|null */
|
|
|
|
private $optOut;
|
|
|
|
/** @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
|
2022-11-30 22:22:33 +00:00
|
|
|
* @param array $languageData
|
2022-12-13 20:28:22 +00:00
|
|
|
* @param MessageLocalizer $localizer
|
2024-03-13 20:59:40 +00:00
|
|
|
* @param UserIdentity $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-12-13 20:28:22 +00:00
|
|
|
array $languageData,
|
|
|
|
MessageLocalizer $localizer,
|
2024-03-13 20:59:40 +00:00
|
|
|
UserIdentity $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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
|
|
|
$action = $this->optOut;
|
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,
|
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
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|