2022-10-27 23:52:23 +00:00
|
|
|
<?php
|
|
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
|
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-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
|
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
|
|
|
|
* @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,
|
2022-12-13 20:28:22 +00:00
|
|
|
array $languageData,
|
|
|
|
MessageLocalizer $localizer,
|
|
|
|
User $user,
|
|
|
|
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-10-27 23:52:23 +00:00
|
|
|
if ( $user->isRegistered() ) {
|
|
|
|
$this->optOut = new VectorComponentMainMenuActionOptOut( $skin );
|
2022-12-13 20:28:22 +00:00
|
|
|
$this->pinnableHeader = new VectorComponentPinnableHeader(
|
|
|
|
$this->localizer,
|
|
|
|
false,
|
|
|
|
self::ID,
|
|
|
|
null
|
|
|
|
);
|
2022-10-27 23:52:23 +00:00
|
|
|
}
|
|
|
|
if ( $shouldLanguageAlertBeInSidebar ) {
|
|
|
|
$this->alert = new VectorComponentMainMenuActionLanguageSwitchAlert( $skin );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 );
|
|
|
|
return [
|
|
|
|
'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
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|