Show ULS button when article exist only in single language

When the article exist only in one language, currently we do not show
language selector. This prevents showing the entry points to create article
in other languages by various means.

Show the language selector so that options like translate, interlanguage
links, language settings can be shown.

Bug: T275147
Bug: T290436
Depends-On: I42c5d44ec15e291d71723c9738ddb8f0d1cf0b09
Change-Id: I7fb68457c1203d824fe7433c9f272f300a483c44
This commit is contained in:
Santhosh Thottingal 2022-06-21 14:49:14 +05:30 committed by Jon Robson
parent 2d9585c8e3
commit 40f6c5e29d
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

@ -214,12 +214,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();
}
/**
@ -369,6 +370,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
@ -388,8 +398,7 @@ abstract class SkinVector extends SkinMustache {
}
// 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,
@ -446,6 +455,7 @@ abstract class SkinVector extends SkinMustache {
*/
public function getTemplateData(): array {
$skin = $this;
$parentData = $this->decoratePortletsData( parent::getTemplateData() );
$featureManager = VectorServices::getFeatureManager();
@ -666,11 +676,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();
}
@ -680,12 +691,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'
];
@ -697,14 +710,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;