From 87d0630aa2ff65e39f8f5c6b55530804dcfbdcad Mon Sep 17 00:00:00 2001 From: Jan Drewniak Date: Wed, 24 Aug 2022 17:06:28 -0400 Subject: [PATCH] Change ULS label for sticky header when 0 Languages available. Modifies the `getULSLabel()` function to centralize the logic related to the ULS language button messages. Renames this function `getULSLabels()` since it retrieves both the text and aria label for this input. This logic conditionally returns the values based on whether or not there are multiple languages available for an title. It method is used in both sticky header and language button near the page title. Bug: T315556 Change-Id: I47e313414ae9c86d057e9b65ec67e522e9e7c464 --- includes/SkinVector.php | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/includes/SkinVector.php b/includes/SkinVector.php index 8c7d8ce56..40f2eb3cf 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -659,16 +659,25 @@ abstract class SkinVector extends SkinMustache { } /** - * Returns ULS button label within the context of the translated message taking a placeholder. + * Get the ULS button label, accounting for the number of available + * languages. * - * @param string $message - * @param int $count - * @return string + * @return array */ - private function getULSLabel( string $message, int $count ): string { - return $this->msg( $message ) - ->numParams( $count ) - ->escaped(); + private function getULSLabels(): array { + $numLanguages = count( $this->getLanguagesCached() ); + + if ( $numLanguages === 0 ) { + return [ + 'label' => $this->msg( 'vector-no-language-button-label' )->text(), + 'aria-label' => $this->msg( 'vector-no-language-button-aria-label' )->text() + ]; + } else { + return [ + 'label' => $this->msg( 'vector-language-button-label' )->numParams( $numLanguages )->escaped(), + 'aria-label' => $this->msg( 'vector-language-button-aria-label' )->numParams( $numLanguages )->escaped() + ]; + } } /** @@ -702,7 +711,7 @@ abstract class SkinVector extends SkinMustache { 'class' => 'mw-interlanguage-selector', 'is-quiet' => true, 'tabindex' => '-1', - 'label' => $this->getULSLabel( 'vector-language-button-label', $numLanguages ), + 'label' => $this->getULSLabels()[ 'label' ], 'html-vector-button-icon' => Hooks::makeIcon( 'wikimedia-language' ), 'event' => 'ui.dropdown-p-lang-btn-sticky-header' ]; @@ -718,14 +727,8 @@ abstract class SkinVector extends SkinMustache { $languageButtonData = [ 'id' => 'p-lang-btn', - // 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 ), + 'label' => $this->getULSLabels()['label'], + 'aria-label' => $this->getULSLabels()['aria-label'], // ext.uls.interface attaches click handler to this selector. 'checkbox-class' => ' mw-interlanguage-selector ', 'html-vector-heading-icon' => Hooks::makeIcon( 'wikimedia-language-progressive' ),