Merge "Hide languages-in-header button when no additional languages"

This commit is contained in:
jenkins-bot 2021-03-30 18:23:55 +00:00 committed by Gerrit Code Review
commit d6b7ef0a8e
1 changed files with 44 additions and 18 deletions

View File

@ -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]" );