From a25dba2a199322c5997d26de0b22d7c7c70ccf38 Mon Sep 17 00:00:00 2001 From: Nicholas Ray Date: Wed, 14 Dec 2022 10:04:32 -0700 Subject: [PATCH] Move toolbox and menus that follow into page tools Uses all of the changes from Jon's patch in 866503 to move all of the sidebar menus after and including the tools menu into the page tools component. The rest of the menus remain in the main menu. Additionally: * Per T317898#8468437, the "Tools" label should be "General". It was also assumed from the prototype that the "More" label should become "Actions" Bug: T317898 Change-Id: Ic9c1586febd8ebfff4a17285e6bd59cee509bd34 --- i18n/en.json | 2 + i18n/qqq.json | 2 + .../Components/VectorComponentPageTools.php | 73 ++++++++++++------- includes/SkinVector22.php | 10 +-- 4 files changed, 54 insertions(+), 33 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 01984d44f..55cc8df86 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -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]]", diff --git a/i18n/qqq.json b/i18n/qqq.json index d48fb0d41..2ef57d4f1 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -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.", diff --git a/includes/Components/VectorComponentPageTools.php b/includes/Components/VectorComponentPageTools.php index 78d33d0e6..d3f47825f 100644 --- a/includes/Components/VectorComponentPageTools.php +++ b/includes/Components/VectorComponentPageTools.php @@ -1,7 +1,8 @@ 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() ]; } } diff --git a/includes/SkinVector22.php b/includes/SkinVector22.php index b372360dc..af68673aa 100644 --- a/includes/SkinVector22.php +++ b/includes/SkinVector22.php @@ -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,