From 980c8453ceb418f3ce05d76381eecd94e0c990f2 Mon Sep 17 00:00:00 2001 From: Jan Drewniak Date: Thu, 18 Mar 2021 12:58:55 +0100 Subject: [PATCH] Hide languages-in-header button when no additional languages Hides the languages-in-header feature if there is only one available language. Also factors the additional classes required for the language button into a separate function. Note: Hiding the language button is a temporary solution until T275147 is resolved. Bug: T276950 Change-Id: I241abc6061bba12a6a209074fa4c2d2c89cea930 --- includes/SkinVector.php | 62 +++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/includes/SkinVector.php b/includes/SkinVector.php index 5f2a33e01..ac5d663f0 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -154,6 +154,18 @@ class SkinVector extends SkinMustache { ); } + /** + * If in modern Vector and no languages possible, OR the languages in header button + * is enabled but language array is empty, then we shouldn't show the langauge list. + * @return bool + */ + private function shouldHideLanguages() { + return !$this->isLegacy() && + !$this->canHaveLanguages() || + // NOTE: T276950 - This should be revisited when an empty state for the language button is chosen. + ( $this->isLanguagesInHeader() && empty( $this->getLanguagesCached() ) ); + } + /** * @inheritDoc */ @@ -162,6 +174,11 @@ class SkinVector extends SkinMustache { $skin = $this; $out = $skin->getOutput(); $title = $out->getTitle(); + $parentData = parent::getTemplateData(); + + if ( $this->shouldHideLanguages() ) { + $parentData['data-portlets']['data-languages'] = null; + } // Naming conventions for Mustache parameters. // @@ -180,13 +197,6 @@ class SkinVector extends SkinMustache { // // Conditionally used values must use null to indicate absence (not false or ''). - $parentData = parent::getTemplateData(); - - // Remove language from sidebar if in modern Vector and no languages possible. - if ( !$this->isLegacy() && !$this->canHaveLanguages() ) { - $parentData['data-portlets']['data-languages'] = null; - } - $commonSkinData = array_merge( $parentData, [ 'page-isarticle' => (bool)$out->isArticle(), @@ -276,6 +286,32 @@ class SkinVector extends SkinMustache { ); } + /** + * Combines class and other HTML data required to create the button + * for the languages in header feature with the existing language portletData. + * + * @param array $portletData returned by SkinMustache + * @return array enhanced $portletData + */ + private function createULSLanguageButton( $portletData ) { + $languageButtonData = [ + 'id' => 'p-lang-btn', + 'label' => $this->msg( + 'vector-language-button-label', + count( $this->getLanguagesCached() ) + )->parse(), + 'heading-class' => + ' vector-menu-heading ' . + ' mw-ui-icon ' . + ' mw-ui-icon-before ' . + ' mw-ui-icon-wikimedia-language ' . + ' mw-ui-button mw-ui-quiet ' . + // ext.uls.interface attaches click handler to this selector. + ' mw-interlanguage-selector ', + ]; + return array_merge( $portletData, $languageButtonData ); + } + /** * helper for applying Vector menu classes to portlets * @param array $portletData returned by SkinMustache to decorate @@ -295,17 +331,7 @@ class SkinVector extends SkinMustache { $portletData['heading-class'] = 'vector-menu-heading'; if ( $portletData['id'] === 'p-lang' && $this->isLanguagesInHeader() ) { - $portletData['label'] = $this->msg( - 'vector-language-button-label', - count( $this->getLanguagesCached() ) - )->parse(); - // Adds language icon - $portletData['heading-class'] .= ' mw-ui-icon mw-ui-icon-before ' - . 'mw-ui-icon-wikimedia-language mw-ui-button mw-ui-quiet'; - // Adds .mw-interlanguage-selector (ext.uls.interface attaches click - // handler to this selector). - $portletData['heading-class'] .= ' mw-interlanguage-selector'; - $portletData['id'] = 'p-lang-btn'; + $portletData = $this->createULSLanguageButton( $portletData ); } $class = $portletData['class']; $portletData['class'] = trim( "$class $extraClasses[$type]" );