From dee1c197b98565e6875d5fdd1455fdf24d2634b4 Mon Sep 17 00:00:00 2001 From: Piotr Miazga Date: Mon, 24 Jun 2019 19:59:11 +0200 Subject: [PATCH] On user pages, move language icon from Toolbar to Overflow menu The Language icon is not useful on user pages as most probably there are no translated user pages, thus there is no need to show all-time disabled Language icon. If overflow menu is available, don't show Language switcher icon in toolbar, show it as first item in the overflow menu. Bug: T224735 Follow-Up: I46d58758356e870c408a74b2c087a42d6ad0ddea Change-Id: I05be9e6457257a1f2eb224ca9ec5808814bc9ed7 --- i18n/en.json | 1 + i18n/qqq.json | 1 + includes/ServiceWiring.php | 14 ++++-- .../menu/Entries/LanguageSelectorEntry.php | 28 +++++++++--- includes/menu/PageActions/ToolbarBuilder.php | 16 ++++--- .../UserNamespaceOverflowBuilder.php | 44 +++++++++++++++++-- .../pageactions.less | 3 +- skin.json | 9 +++- 8 files changed, 96 insertions(+), 20 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 16d688419..50bb3a8c7 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -56,6 +56,7 @@ "minerva-page-actions-user-rights": "User rights", "minerva-page-actions-logs": "Logs", "minerva-page-actions-wikibase": "{{WBREPONAME}} item", + "minerva-page-actions-language-switcher": "Languages", "skinname-minerva": "MinervaNeue", "minerva-skin-desc": "A responsive mobile first skin", "skin-minerva-issue-learn-more": "Learn more", diff --git a/i18n/qqq.json b/i18n/qqq.json index 3ddc39090..7d2405336 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -65,6 +65,7 @@ "minerva-page-actions-user-rights": "In the secondary page menu for user pages, the user rights button label", "minerva-page-actions-logs": "In the secondary page menu for user pages, the user logs button label", "minerva-page-actions-wikibase": "In the secondary page menu, the wikibase item button label", + "minerva-page-actions-language-switcher": "In the secondary page menu, the language switcher item button label\n{{Identical|Languages}}", "skinname-minerva": "{{name}}", "minerva-skin-desc": "{{desc|name=Minerva Neue|url=https://www.mediawiki.org/wiki/Skin:Minerva_Neue|what=skin}}", "skin-minerva-issue-learn-more": "Label for link that allows expanding of ambox issue templates.", diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index b88374bda..811485e71 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -52,10 +52,13 @@ return [ */ $skinOptions = $services->getService( 'Minerva.SkinOptions' ); $context = RequestContext::getMain(); + $title = $context->getTitle(); + $output = $context->getOutput(); + $user = $context->getUser(); $userPageHelper = $services->getService( 'Minerva.SkinUserPageHelper' ); $toolbarBuilder = new PageActionsMenu\ToolbarBuilder( - $context->getTitle(), - $context->getUser(), + $title, + $user, $context, $services->getPermissionManager(), $services->getService( 'Minerva.Permissions' ), @@ -63,10 +66,15 @@ return [ $services->get( 'Minerva.SkinUserPageHelper' ) ); if ( $skinOptions->get( SkinOptions::OPTION_OVERFLOW_SUBMENU ) ) { + $hasVariants = $title->getPageLanguage()->hasVariants(); + $hasLanguages = count( $output->getLanguageLinks() ); $overflowBuilder = $userPageHelper->isUserPage() ? new PageActionsMenu\UserNamespaceOverflowBuilder( + $title, $context, - $userPageHelper + $userPageHelper, + $services->getService( 'Minerva.Permissions' ), + $hasVariants || $hasLanguages ) : new PageActionsMenu\DefaultOverflowBuilder( $context diff --git a/includes/menu/Entries/LanguageSelectorEntry.php b/includes/menu/Entries/LanguageSelectorEntry.php index 6a5a8ecf5..82880d573 100644 --- a/includes/menu/Entries/LanguageSelectorEntry.php +++ b/includes/menu/Entries/LanguageSelectorEntry.php @@ -18,7 +18,6 @@ namespace MediaWiki\Minerva\Menu\Entries; use MessageLocalizer; -use MinervaUI; use SpecialPage; use Title; @@ -39,22 +38,37 @@ class LanguageSelectorEntry implements IMenuEntry { * @var bool */ private $doesPageHaveLanguages; + /** + * @var string An icon class generated via MinervaUI::iconClass() + */ + private $iconClass; + + /** + * @var string A translatable label used as text and title + */ + private $label; + /** * LanguageSelectorEntry constructor. * @param Title $title Current Title * @param bool $doesPageHaveLanguages Whether the page is also available in other * languages or variants * @param MessageLocalizer $messageLocalizer Used for translation texts - * + * @param string $iconClass An icon class generated via MinervaUI::iconClass() + * @param string $label Menu entry label and title */ public function __construct( Title $title, $doesPageHaveLanguages, - MessageLocalizer $messageLocalizer + MessageLocalizer $messageLocalizer, + $iconClass, + $label = 'mobile-frontend-language-article-heading' ) { $this->title = $title; $this->doesPageHaveLanguages = $doesPageHaveLanguages; $this->messageLocalizer = $messageLocalizer; + $this->iconClass = $iconClass; + $this->label = $label; } /** @@ -86,14 +100,14 @@ class LanguageSelectorEntry implements IMenuEntry { } else { $switcherClasses .= ' disabled'; } - $iconClass = MinervaUI::iconClass( 'language-switcher', 'element', $switcherClasses ); + $msg = $this->messageLocalizer->msg( $this->label ); return [ [ 'href' => $switcherLink, - 'class' => $iconClass, - 'text' => $this->messageLocalizer->msg( 'mobile-frontend-language-article-heading' ), - 'title' => $this->messageLocalizer->msg( 'mobile-frontend-language-article-heading' ) + 'class' => $this->iconClass . $switcherClasses, + 'text' => $msg, + 'title' => $msg ] ]; diff --git a/includes/menu/PageActions/ToolbarBuilder.php b/includes/menu/PageActions/ToolbarBuilder.php index b6b08d903..fc584222f 100644 --- a/includes/menu/PageActions/ToolbarBuilder.php +++ b/includes/menu/PageActions/ToolbarBuilder.php @@ -108,10 +108,17 @@ class ToolbarBuilder { public function getGroup( $doesPageHaveLanguages ): Group { $group = new Group(); $permissions = $this->permissions; + $userPageWithOveflowMode = $this->skinOptions->get( SkinOptions::OPTION_OVERFLOW_SUBMENU ) && + $this->userPageHelper->isUserPage(); - if ( $permissions->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) ) { - $group->insertEntry( new LanguageSelectorEntry( $this->title, $doesPageHaveLanguages, - $this->messageLocalizer ) ); + if ( !$userPageWithOveflowMode && $permissions->isAllowed( + IMinervaPagePermissions::SWITCH_LANGUAGE ) ) { + $group->insertEntry( new LanguageSelectorEntry( + $this->title, + $doesPageHaveLanguages, + $this->messageLocalizer, + MinervaUI::iconClass( 'language-switcher', 'element', '' ) ) + ); } if ( $permissions->isAllowed( IMinervaPagePermissions::WATCH ) ) { @@ -122,8 +129,7 @@ class ToolbarBuilder { $group->insertEntry( $this->getHistoryPageAction() ); } - if ( $this->skinOptions->get( SkinOptions::OPTION_OVERFLOW_SUBMENU ) && - $this->userPageHelper->isUserPage() ) { + if ( $userPageWithOveflowMode ) { // User links are hidden when Overflow menu is visible. We want to show Contributions // link on toolbar only when overflow is visible $group->insertEntry( $this->createContributionsPageAction() ); diff --git a/includes/menu/PageActions/UserNamespaceOverflowBuilder.php b/includes/menu/PageActions/UserNamespaceOverflowBuilder.php index ea0695cf7..aa0079530 100644 --- a/includes/menu/PageActions/UserNamespaceOverflowBuilder.php +++ b/includes/menu/PageActions/UserNamespaceOverflowBuilder.php @@ -22,10 +22,13 @@ namespace MediaWiki\Minerva\Menu\PageActions; use Hooks; use MediaWiki\Minerva\Menu\Group; +use MediaWiki\Minerva\Menu\Entries\LanguageSelectorEntry; +use MediaWiki\Minerva\Permissions\IMinervaPagePermissions; use MediaWiki\Minerva\SkinUserPageHelper; use MessageLocalizer; use MinervaUI; use MWException; +use Title; use SpecialPage; use User; @@ -41,14 +44,41 @@ class UserNamespaceOverflowBuilder implements IOverflowBuilder { */ private $pageUser; + /** + * @var Title + */ + private $title; + + /** + * @var IMinervaPagePermissions + */ + private $permissions; + + /** + * @var bool + */ + private $doesPageHaveLanguages; + /** * Initialize the overflow menu visible on the User namespace + * @param Title $title * @param MessageLocalizer $msgLocalizer * @param SkinUserPageHelper $userPageHelper + * @param IMinervaPagePermissions $permissions + * @param bool $doesPageHaveLanguages */ - public function __construct( MessageLocalizer $msgLocalizer, SkinUserPageHelper $userPageHelper ) { + public function __construct( + Title $title, + MessageLocalizer $msgLocalizer, + SkinUserPageHelper $userPageHelper, + IMinervaPagePermissions $permissions, + $doesPageHaveLanguages + ) { + $this->title = $title; $this->messageLocalizer = $msgLocalizer; $this->pageUser = $userPageHelper->getPageUser(); + $this->permissions = $permissions; + $this->doesPageHaveLanguages = $doesPageHaveLanguages; } /** @@ -57,6 +87,14 @@ class UserNamespaceOverflowBuilder implements IOverflowBuilder { */ public function getGroup( array $toolbox ): Group { $group = new Group(); + if ( $this->permissions->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) ) { + $group->insertEntry( new LanguageSelectorEntry( $this->title, + $this->doesPageHaveLanguages, $this->messageLocalizer, + MinervaUI::iconClass( 'language-switcher-base20', 'before', + 'minerva-page-actions-language-switcher toggle-list-item__anchor--menu' ), + 'minerva-page-actions-language-switcher' + ) ); + } $group->insertEntry( $this->build( 'uploads', 'upload', SpecialPage::getTitleFor( 'Uploads', $this->pageUser )->getLocalURL() ) ); @@ -102,8 +140,8 @@ class UserNamespaceOverflowBuilder implements IOverflowBuilder { new PageActionMenuEntry( 'page-actions-overflow-' . $name, $href, - MinervaUI::iconClass( - '', 'before', 'wikimedia-ui-' . $icon . '-base20 toggle-list-item__anchor--menu' + MinervaUI::iconClass( '', 'before', + 'wikimedia-ui-' . $icon . '-base20 toggle-list-item__anchor--menu' ), $this->messageLocalizer->msg( 'minerva-page-actions-' . $name ) ) : null; diff --git a/resources/skins.minerva.base.styles/pageactions.less b/resources/skins.minerva.base.styles/pageactions.less index 97b27e8b1..b52f0f9ad 100644 --- a/resources/skins.minerva.base.styles/pageactions.less +++ b/resources/skins.minerva.base.styles/pageactions.less @@ -16,7 +16,8 @@ } // used to disable the languages icon. -.mw-ui-icon-element.disabled { +.mw-ui-icon-element.disabled, +.language-selector.disabled { cursor: default; opacity: 0.25; } diff --git a/skin.json b/skin.json index a0e91d5a3..aa2ded2d3 100644 --- a/skin.json +++ b/skin.json @@ -306,6 +306,10 @@ "invert": { "color": "#fff", "global": false + }, + "base20": { + "color": "#54595d", + "global": false } }, "images": { @@ -315,7 +319,10 @@ "mainmenu": "resources/skins.minerva.icons.images/hamburger.svg", "edit": "resources/skins.minerva.icons.images/editLocked.svg", "edit-enabled": "resources/skins.minerva.icons.images/edit.svg", - "language-switcher": "resources/skins.minerva.icons.images/languageSwitcher.svg", + "language-switcher": { + "file": "resources/skins.minerva.icons.images/languageSwitcher.svg", + "variants": [ "base20" ] + }, "profile": "resources/skins.minerva.icons.images/profile.svg", "clock": { "file": "resources/skins.minerva.icons.images/clock.svg",