From 4086d850e547c6a56c906d145b629494efe1b65e Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Thu, 14 May 2020 14:19:12 -0700 Subject: [PATCH] Show empty language portal if HTML has been added after portal Bug: T252800 Change-Id: Iefe0ed2728b6fd08da8f3e58edbfaae7d27d1a2d --- includes/VectorTemplate.php | 23 ++++++++++++------- .../integration/VectorTemplateTest.php | 5 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/includes/VectorTemplate.php b/includes/VectorTemplate.php index b9beb37..e2bda2b 100644 --- a/includes/VectorTemplate.php +++ b/includes/VectorTemplate.php @@ -346,12 +346,16 @@ class VectorTemplate extends BaseTemplate { case 'LANGUAGES': // @phan-suppress-next-line PhanUndeclaredMethod $languages = $skin->getLanguages(); - if ( count( $languages ) ) { - $props[] = $this->getMenuData( - 'lang', - $languages, - self::MENU_TYPE_PORTAL - ); + $portal = $this->getMenuData( + 'lang', + $languages, + self::MENU_TYPE_PORTAL + ); + // The language portal will be added provided either + // languages exist or there is a value in html-after-portal + // for example to show the add language wikidata link (T252800) + if ( count( $languages ) || $portal['html-after-portal'] ) { + $props[] = $portal; } break; default: @@ -445,7 +449,6 @@ class VectorTemplate extends BaseTemplate { array $options = [], bool $setLabelToSelected = false ) : array { - $class = ( count( $urls ) == 0 ) ? 'vector-menu-empty emptyPortlet' : ''; $extraClasses = [ self::MENU_TYPE_DROPDOWN => 'vector-menu vector-menu-dropdown vectorMenu', self::MENU_TYPE_TABS => 'vector-menu vector-menu-tabs vectorTabs', @@ -459,7 +462,6 @@ class VectorTemplate extends BaseTemplate { $msgObj = $this->msg( self::MENU_LABEL_KEYS[ $label ] ?? $label ); $props = [ 'id' => "p-$label", - 'class' => trim( "$class $extraClasses[$type]" ), 'label-id' => "p-{$label}-label", // If no message exists fallback to plain text (T252727) 'label' => $msgObj->exists() ? $msgObj->text() : $label, @@ -482,6 +484,11 @@ class VectorTemplate extends BaseTemplate { } $props['html-after-portal'] = $isPortal ? $this->getAfterPortlet( $label ) : ''; + + // Mark the portal as empty if it has no content + $class = ( count( $urls ) == 0 && !$props['html-after-portal'] ) + ? 'vector-menu-empty emptyPortlet' : ''; + $props['class'] = trim( "$class $extraClasses[$type]" ); return $props; } diff --git a/tests/phpunit/integration/VectorTemplateTest.php b/tests/phpunit/integration/VectorTemplateTest.php index a8571f5..4d5e11f 100644 --- a/tests/phpunit/integration/VectorTemplateTest.php +++ b/tests/phpunit/integration/VectorTemplateTest.php @@ -154,15 +154,14 @@ class VectorTemplateTest extends MediaWikiIntegrationTestCase { $this->assertSame( $views, [ 'id' => 'p-views', - 'class' => 'vector-menu-empty emptyPortlet vector-menu vector-menu-tabs vectorTabs', 'label-id' => 'p-views-label', 'label' => 'Views', 'html-userlangattributes' => $langAttrs, 'html-items' => '', - 'class' => 'vector-menu-empty emptyPortlet vector-menu vector-menu-tabs vectorTabs', 'is-dropdown' => false, 'html-tooltip' => '', - 'html-after-portal' => '' + 'html-after-portal' => '', + 'class' => 'vector-menu-empty emptyPortlet vector-menu vector-menu-tabs vectorTabs', ] ); $variants = $props['data-variants'];