Merge "Move toolbox and menus that follow into page tools"

This commit is contained in:
jenkins-bot 2022-12-14 23:39:56 +00:00 committed by Gerrit Code Review
commit 89b3879bc5
4 changed files with 54 additions and 33 deletions

View file

@ -50,6 +50,8 @@
"vector-site-nav-label": "Site",
"vector-main-menu-label": "Main menu",
"vector-page-tools-label": "Tools",
"vector-page-tools-general-label": "General",
"vector-page-tools-actions-label": "Actions",
"vector-pin-element-label": "move to sidebar",
"vector-unpin-element-label": "hide",
"vector-2022-prefs-talkpage": "[[mw:Talk:Reading/Web/Desktop_Improvements|Discussion]]",

View file

@ -66,6 +66,8 @@
"vector-site-nav-label": "Accessible label for site (main menu) nav landmark",
"vector-main-menu-label": "Main menu label",
"vector-page-tools-label": "Label for the page tools pinnable dropdown\n{{identical|Tools}}",
"vector-page-tools-general-label": "Label for the page tools 'General' menu",
"vector-page-tools-actions-label": "Label for the page tools 'Actions' menu",
"vector-pin-element-label": "Label for toggle button in PinnableHeader to pin an element",
"vector-unpin-element-label": "Label for toggle button in PinnableHeader to unpin an element",
"vector-2022-prefs-talkpage": "Link to the desktop improvements project talk page which is shown before the preview link in skin preferences. See T307113 for more information.",

View file

@ -1,7 +1,8 @@
<?php
namespace MediaWiki\Skins\Vector\Components;
use Skin;
use MessageLocalizer;
use User;
/**
* VectorComponentMainMenu component
@ -9,68 +10,84 @@ use Skin;
class VectorComponentPageTools implements VectorComponent {
/** @var array */
private $toolbox;
/** @var array */
private $actionsMenu;
private $menus;
/** @var bool */
private $isPinned;
/** @var Skin */
private $skin;
/** @var VectorComponentPinnableHeader|null */
private $pinnableHeader;
/** @var string */
public const ID = 'vector-page-tools';
/** @var string */
public const TOOLBOX_ID = 'p-tb';
/** @var string */
private const ACTIONS_ID = 'p-cactions';
/** @var MessageLocalizer */
private $localizer;
/**
* @param array $toolbox
* @param array $actionsMenu
* @param array $menus
* @param bool $isPinned
* @param Skin $skin
* @param MessageLocalizer $localizer
* @param User $user
*/
public function __construct(
array $toolbox,
array $actionsMenu,
array $menus,
bool $isPinned,
Skin $skin
MessageLocalizer $localizer,
User $user
) {
$user = $skin->getUser();
$this->toolbox = $toolbox;
$this->actionsMenu = $actionsMenu;
$this->menus = $menus;
$this->isPinned = $isPinned;
$this->localizer = $localizer;
$this->pinnableHeader = $user->isRegistered() ? new VectorComponentPinnableHeader(
$skin->getContext(),
$localizer,
$isPinned,
// Name
'vector-page-tools',
// Feature name
'page-tools-pinned'
) : null;
$this->skin = $skin;
}
/**
* 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:
$menu['label'] = $this->localizer->msg( 'vector-page-tools-general-label' );
break;
case self::ACTIONS_ID:
$menu['label'] = $this->localizer->msg( 'vector-page-tools-actions-label' );
break;
}
return $menu;
}, $this->menus );
}
/**
* @inheritDoc
*/
public function getTemplateData(): array {
$toolbox = new VectorComponentMenu( $this->toolbox );
$actions = new VectorComponentMenu( $this->actionsMenu );
$id = 'vector-page-tools';
$pinnedContainer = new VectorComponentPinnedContainer( $id, $this->isPinned );
$pinnableElement = new VectorComponentPinnableElement( $id );
$pinnedContainer = new VectorComponentPinnedContainer( self::ID, $this->isPinned );
$pinnableElement = new VectorComponentPinnableElement( self::ID );
$data = $pinnableElement->getTemplateData() +
$pinnedContainer->getTemplateData();
return $data + [
'data-pinnable-header' => $this->pinnableHeader ? $this->pinnableHeader->getTemplateData() : null,
'data-menus' => [
$toolbox->getTemplateData(),
$actions->getTemplateData(),
]
'data-menus' => $this->getMenus()
];
}
}

View file

@ -217,7 +217,7 @@ class SkinVector22 extends SkinVector {
$isPageToolsEnabled = $featureManager->isFeatureEnabled( Constants::FEATURE_PAGE_TOOLS );
$isPageToolsPinned = $featureManager->isFeatureEnabled( Constants::FEATURE_PAGE_TOOLS_PINNED );
$sidebar = $parentData[ 'data-portlets-sidebar' ];
$toolbox = [];
$pageToolsMenus = [];
$restPortlets = $parentData[ 'data-portlets-sidebar' ][ 'array-portlets-rest' ];
if ( $isPageToolsEnabled ) {
$toolboxMenuIndex = array_search(
@ -231,7 +231,7 @@ class SkinVector22 extends SkinVector {
if ( $toolboxMenuIndex !== false ) {
// Splice removes the toolbox menu from the $restPortlets array
// and current returns the first value of array_splice, i.e. the $toolbox menu data.
$toolbox = current( array_splice( $restPortlets, $toolboxMenuIndex, 1 ) );
$pageToolsMenus = array_splice( $restPortlets, $toolboxMenuIndex );
$parentData[ 'data-portlets-sidebar' ]['array-portlets-rest'] = $restPortlets;
$sidebar = $parentData[ 'data-portlets-sidebar' ];
}
@ -266,10 +266,10 @@ class SkinVector22 extends SkinVector {
$parentData['data-portlets']['data-languages'] ?? [],
),
'data-page-tools' => $isPageToolsEnabled ? new VectorComponentPageTools(
$toolbox,
$parentData['data-portlets']['data-actions'] ?? [],
array_merge( [ $parentData['data-portlets']['data-actions'] ?? [] ], $pageToolsMenus ),
$isPageToolsPinned,
$this
$this->getContext(),
$this->getUser()
) : null,
'data-page-tools-dropdown' => $isPageToolsEnabled ?
new VectorComponentDropdown( 'vector-page-tools', $this->msg( 'toolbox' )->text() ) : null,