2022-12-02 18:09:52 +00:00
|
|
|
<?php
|
|
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
|
2022-12-13 20:28:22 +00:00
|
|
|
use MediaWiki\Skins\Vector\Constants;
|
|
|
|
use MediaWiki\Skins\Vector\FeatureManagement\FeatureManager;
|
2022-12-14 17:04:32 +00:00
|
|
|
use MessageLocalizer;
|
|
|
|
use User;
|
2022-12-02 18:09:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* VectorComponentMainMenu component
|
|
|
|
*/
|
|
|
|
class VectorComponentPageTools implements VectorComponent {
|
|
|
|
|
|
|
|
/** @var array */
|
2022-12-14 17:04:32 +00:00
|
|
|
private $menus;
|
2022-12-02 18:09:52 +00:00
|
|
|
|
2022-12-13 20:28:22 +00:00
|
|
|
/** @var MessageLocalizer */
|
|
|
|
private $localizer;
|
|
|
|
|
2022-12-07 22:15:31 +00:00
|
|
|
/** @var bool */
|
|
|
|
private $isPinned;
|
|
|
|
|
|
|
|
/** @var VectorComponentPinnableHeader|null */
|
2022-12-02 18:09:52 +00:00
|
|
|
private $pinnableHeader;
|
|
|
|
|
2022-12-14 17:04:32 +00:00
|
|
|
/** @var string */
|
|
|
|
public const ID = 'vector-page-tools';
|
|
|
|
|
2022-12-02 18:09:52 +00:00
|
|
|
/** @var string */
|
|
|
|
public const TOOLBOX_ID = 'p-tb';
|
|
|
|
|
2022-12-14 17:04:32 +00:00
|
|
|
/** @var string */
|
|
|
|
private const ACTIONS_ID = 'p-cactions';
|
|
|
|
|
2022-12-02 18:09:52 +00:00
|
|
|
/**
|
2022-12-14 17:04:32 +00:00
|
|
|
* @param array $menus
|
|
|
|
* @param MessageLocalizer $localizer
|
|
|
|
* @param User $user
|
2022-12-13 20:28:22 +00:00
|
|
|
* @param FeatureManager $featureManager
|
2022-12-02 18:09:52 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-12-14 17:04:32 +00:00
|
|
|
array $menus,
|
|
|
|
MessageLocalizer $localizer,
|
2022-12-13 20:28:22 +00:00
|
|
|
User $user,
|
|
|
|
FeatureManager $featureManager
|
2022-12-02 18:09:52 +00:00
|
|
|
) {
|
2022-12-14 17:04:32 +00:00
|
|
|
$this->menus = $menus;
|
|
|
|
$this->localizer = $localizer;
|
2022-12-13 20:28:22 +00:00
|
|
|
$this->isPinned = $featureManager->isFeatureEnabled( Constants::FEATURE_PAGE_TOOLS_PINNED );
|
2022-12-07 22:15:31 +00:00
|
|
|
$this->pinnableHeader = $user->isRegistered() ? new VectorComponentPinnableHeader(
|
2022-12-14 17:04:32 +00:00
|
|
|
$localizer,
|
2022-12-13 20:28:22 +00:00
|
|
|
$this->isPinned,
|
2022-12-07 22:15:31 +00:00
|
|
|
// Name
|
2022-12-13 20:28:22 +00:00
|
|
|
self::ID,
|
2022-12-07 22:15:31 +00:00
|
|
|
// Feature name
|
|
|
|
'page-tools-pinned'
|
|
|
|
) : null;
|
2022-12-14 17:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Revises the labels of the p-tb and p-cactions menus.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getMenus(): array {
|
|
|
|
return array_map( function ( $menu ) {
|
|
|
|
switch ( $menu['id'] ?? '' ) {
|
|
|
|
case self::TOOLBOX_ID:
|
2022-12-13 20:28:22 +00:00
|
|
|
$menu['label'] = $this->localizer->msg( 'vector-page-tools-general-label' )->text();
|
2022-12-14 17:04:32 +00:00
|
|
|
break;
|
|
|
|
case self::ACTIONS_ID:
|
2022-12-13 20:28:22 +00:00
|
|
|
$menu['label'] = $this->localizer->msg( 'vector-page-tools-actions-label' )->text();
|
2022-12-14 17:04:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $menu;
|
|
|
|
}, $this->menus );
|
2022-12-02 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
2022-12-14 20:42:52 +00:00
|
|
|
$pinnedContainer = new VectorComponentPinnableContainer( self::ID, $this->isPinned );
|
2022-12-14 17:04:32 +00:00
|
|
|
$pinnableElement = new VectorComponentPinnableElement( self::ID );
|
2022-12-02 18:09:52 +00:00
|
|
|
|
2022-12-07 01:05:22 +00:00
|
|
|
$data = $pinnableElement->getTemplateData() +
|
|
|
|
$pinnedContainer->getTemplateData();
|
2022-12-14 17:04:32 +00:00
|
|
|
|
2022-12-07 01:05:22 +00:00
|
|
|
return $data + [
|
2022-12-07 22:15:31 +00:00
|
|
|
'data-pinnable-header' => $this->pinnableHeader ? $this->pinnableHeader->getTemplateData() : null,
|
2022-12-14 17:04:32 +00:00
|
|
|
'data-menus' => $this->getMenus()
|
2022-12-02 18:09:52 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|