Merge "Show ULS button when article exist only in single language"

This commit is contained in:
jenkins-bot 2022-07-27 20:22:02 +00:00 committed by Gerrit Code Review
commit e4b4f5bf9f
4 changed files with 45 additions and 11 deletions

View File

@ -16,6 +16,8 @@
"vector-languages": "Languages",
"vector-language-button-aria-label": "Go to an article in another language. Available in {{PLURAL:$1|$1 language|$1 languages}}",
"vector-language-button-label": "{{PLURAL:$1|$1 language|$1 languages}}",
"vector-no-language-button-label": "Add languages",
"vector-no-language-button-aria-label": "This article exist only in this language. Add the article for other languages",
"vector-language-redirect-to-top": "On this {{SITENAME}} the language links are at the top of the page across from the article title. [[#p-lang-btn|Go to top]].",
"vector-language-variant-switcher-label": "Change language variant",
"vector-action-addsection": "Add topic",

View File

@ -31,6 +31,8 @@
"vector-languages": "Label for language alert in sidebar when language switching is in header\n\n{{Identical|Language}}",
"vector-language-button-aria-label": "Accessibility label for language button dropdown menu in modern Vector.\n* $1 - the count of languages available, supports plural",
"vector-language-button-label": "Label for language button in modern Vector.\n\nArguments:\n* $1 number of languages, supports plural",
"vector-no-language-button-label": "Label for language button when article does not exist in any other language.",
"vector-no-language-button-aria-label": "Accessibility label for language button dropdown menu in modern Vector.\n",
"vector-language-redirect-to-top": "Explains language links location at top of page and provides link to top. See also [[:phab:T295555]].",
"vector-language-variant-switcher-label": "Label for the language variant switcher.",
"vector-action-addsection": "Used in the Vector skin. See for example {{canonicalurl:Talk:Main_Page|useskin=vector}}\n{{Identical|Add topic}}",

View File

@ -223,12 +223,13 @@ abstract class SkinVector extends SkinMustache {
/**
* Show the ULS button if it's modern Vector, languages in header is enabled,
* and the language array isn't empty. Hide it otherwise.
* and the ULS extension is enabled. Hide it otherwise.
* There is no point in showing the language button if ULS extension is unavailable
* as there is no ways to add languages without it.
* @return bool
*/
protected function shouldHideLanguages() {
// NOTE: T276950 - This should be revisited when an empty state for the language button is chosen.
return $this->isLegacy() || !$this->isLanguagesInContent() || empty( $this->getLanguagesCached() );
return $this->isLegacy() || !$this->isLanguagesInContent() || !$this->isULSExtensionEnabled();
}
/**
@ -378,6 +379,15 @@ abstract class SkinVector extends SkinMustache {
Hooks::onSkinTemplateNavigation( $skin, $content_navigation );
}
/**
* Check whether ULS is enabled
*
* @return bool
*/
private function isULSExtensionEnabled(): bool {
return ExtensionRegistry::getInstance()->isLoaded( 'UniversalLanguageSelector' );
}
/**
* Generate data needed to generate the sticky header.
* @param array $searchBoxData
@ -399,8 +409,7 @@ abstract class SkinVector extends SkinMustache {
$btns[] = $this->getAddSectionButtonData();
// Show sticky ULS if the ULS extension is enabled and the ULS in header is not hidden
$showStickyULS = ExtensionRegistry::getInstance()->isLoaded( 'UniversalLanguageSelector' )
&& !$this->shouldHideLanguages();
$showStickyULS = $this->isULSExtensionEnabled() && !$this->shouldHideLanguages();
return [
'data-primary-action' => $showStickyULS ?
$this->getULSButtonData() : null,
@ -457,6 +466,7 @@ abstract class SkinVector extends SkinMustache {
*/
public function getTemplateData(): array {
$skin = $this;
$parentData = $this->decoratePortletsData( parent::getTemplateData() );
$featureManager = VectorServices::getFeatureManager();
@ -677,11 +687,12 @@ abstract class SkinVector extends SkinMustache {
* Returns ULS button label within the context of the translated message taking a placeholder.
*
* @param string $message
* @param int $count
* @return string
*/
private function getULSLabel( string $message ) {
private function getULSLabel( string $message, int $count ): string {
return $this->msg( $message )
->numParams( count( $this->getLanguagesCached() ) )
->numParams( $count )
->escaped();
}
@ -709,12 +720,14 @@ abstract class SkinVector extends SkinMustache {
* @return array
*/
private function getULSButtonData() {
$numLanguages = count( $this->getLanguagesCached() );
return [
'id' => 'p-lang-btn-sticky-header',
'class' => 'mw-interlanguage-selector',
'is-quiet' => true,
'tabindex' => '-1',
'label' => $this->getULSLabel( 'vector-language-button-label' ),
'label' => $this->getULSLabel( 'vector-language-button-label', $numLanguages ),
'html-vector-button-icon' => Hooks::makeIcon( 'wikimedia-language' ),
'event' => 'ui.dropdown-p-lang-btn-sticky-header'
];
@ -726,14 +739,23 @@ abstract class SkinVector extends SkinMustache {
* @return array
*/
private function getULSPortletData() {
$numLanguages = count( $this->getLanguagesCached() );
$languageButtonData = [
'id' => 'p-lang-btn',
'label' => $this->getULSLabel( 'vector-language-button-label' ),
'aria-label' => $this->getULSLabel( 'vector-language-button-aria-label' ),
// No languages present for the article.
// But the page can show languages if there were languages.
'label' => $numLanguages === 0 ?
$this->msg( 'vector-no-language-button-label' )->text() :
$this->getULSLabel( 'vector-language-button-label', $numLanguages ),
'aria-label' => $numLanguages === 0 ?
$this->msg( 'vector-no-language-button-aria-label' )->text() :
$this->getULSLabel( 'vector-language-button-aria-label', $numLanguages ),
// ext.uls.interface attaches click handler to this selector.
'checkbox-class' => ' mw-interlanguage-selector ',
'html-vector-heading-icon' => Hooks::makeIcon( 'wikimedia-language-progressive' ),
'heading-class' => self::CLASS_QUIET_BUTTON . ' ' . self::CLASS_PROGRESSIVE
'heading-class' => self::CLASS_QUIET_BUTTON . ' ' . self::CLASS_PROGRESSIVE .
' mw-portlet-lang-heading-' . strval( $numLanguages ),
];
// Adds class to hide language button

View File

@ -17,6 +17,14 @@
opacity: 0.87;
}
// If there are no languages and JavaScript is not enabled there is no fallback so we hide
// the button altogether.
.mw-portlet-lang-heading-0 {
.client-nojs & {
display: none;
}
}
.vector-menu-heading {
// Prevent select of span text "X languages"
user-select: none;