mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-23 23:33:54 +00:00
Do not show empty user links dropdown in private wikis
In situations where anon account creation is disabled or when combined login link would be used, the usermenu array contains single element (for 'login' or 'login/create') instead of two elements ('login' and 'create account' items separately) If $wgWikimediaMessagesAnonDonateLink is enabled through the WikimediaMessages extension, the third element 'sitesupport' exists, making the number of anon items either 1 or 2 or 3. This patch fixes $isDefaultAnonUserLinks variable to account for all the cases Additionally, if even login is disabled, the element count can be zero and in such case we need to hide the dropdown in all cases (not only on large viewports) because it would always be empty. This patch passes the userlinks count to ::getDropdown() and adds CSS class when appropriate to hide the drowpdown completely. Bug: T332743 Change-Id: I1ce5e1ea30917a6e80ef00f3c1703cbd0ecb6968
This commit is contained in:
parent
9006a0a8f2
commit
02dfbd4acb
|
@ -61,9 +61,10 @@ class VectorComponentUserLinks implements VectorComponent {
|
||||||
/**
|
/**
|
||||||
* @param bool $isDefaultAnonUserLinks
|
* @param bool $isDefaultAnonUserLinks
|
||||||
* @param bool $isAnonEditorLinksEnabled
|
* @param bool $isAnonEditorLinksEnabled
|
||||||
|
* @param int $userLinksCount
|
||||||
* @return VectorComponentDropdown
|
* @return VectorComponentDropdown
|
||||||
*/
|
*/
|
||||||
private function getDropdown( $isDefaultAnonUserLinks, $isAnonEditorLinksEnabled ) {
|
private function getDropdown( $isDefaultAnonUserLinks, $isAnonEditorLinksEnabled, $userLinksCount ) {
|
||||||
$user = $this->user;
|
$user = $this->user;
|
||||||
$isAnon = !$user->isRegistered();
|
$isAnon = !$user->isRegistered();
|
||||||
|
|
||||||
|
@ -76,12 +77,21 @@ class VectorComponentUserLinks implements VectorComponent {
|
||||||
// Hide entire user links dropdown on larger viewports if it only contains
|
// Hide entire user links dropdown on larger viewports if it only contains
|
||||||
// create account & login link, which are only shown on smaller viewports
|
// create account & login link, which are only shown on smaller viewports
|
||||||
if ( $isAnon && $isDefaultAnonUserLinks && !$isAnonEditorLinksEnabled ) {
|
if ( $isAnon && $isDefaultAnonUserLinks && !$isAnonEditorLinksEnabled ) {
|
||||||
$class .= ' user-links-collapsible-item';
|
$linkclass = ' user-links-collapsible-item';
|
||||||
|
|
||||||
|
if ( $userLinksCount === 0 ) {
|
||||||
|
// The user links can be completely empty when even login is not possible
|
||||||
|
// (e.g using remote authentication). In this case, we need to hide the
|
||||||
|
// dropdown completely not only on larger viewports.
|
||||||
|
$linkclass .= '--none';
|
||||||
|
}
|
||||||
|
|
||||||
|
$class .= $linkclass;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tooltip = '';
|
$tooltip = '';
|
||||||
$icon = $this->userIcon;
|
$icon = $this->userIcon;
|
||||||
if ( $icon === '' ) {
|
if ( $icon === '' && $userLinksCount ) {
|
||||||
$icon = 'ellipsis';
|
$icon = 'ellipsis';
|
||||||
// T287494 We use tooltip messages to provide title attributes on hover over certain menu icons.
|
// T287494 We use tooltip messages to provide title attributes on hover over certain menu icons.
|
||||||
// For modern Vector, the "tooltip-p-personal" key is set to "User menu" which is appropriate for
|
// For modern Vector, the "tooltip-p-personal" key is set to "User menu" which is appropriate for
|
||||||
|
@ -237,7 +247,8 @@ class VectorComponentUserLinks implements VectorComponent {
|
||||||
public function getTemplateData(): array {
|
public function getTemplateData(): array {
|
||||||
$portletData = $this->portletData;
|
$portletData = $this->portletData;
|
||||||
|
|
||||||
$isDefaultAnonUserLinks = count( $portletData['data-user-menu']['array-items'] ) === 3;
|
$userLinksCount = count( $portletData['data-user-menu']['array-items'] );
|
||||||
|
$isDefaultAnonUserLinks = $userLinksCount <= 3;
|
||||||
$isAnonEditorLinksEnabled = isset( $portletData['data-user-menu-anon-editor']['is-empty'] )
|
$isAnonEditorLinksEnabled = isset( $portletData['data-user-menu-anon-editor']['is-empty'] )
|
||||||
&& !$portletData['data-user-menu-anon-editor']['is-empty'];
|
&& !$portletData['data-user-menu-anon-editor']['is-empty'];
|
||||||
|
|
||||||
|
@ -333,8 +344,8 @@ class VectorComponentUserLinks implements VectorComponent {
|
||||||
'data-user-links-overflow' => $overflowMenu->getTemplateData(),
|
'data-user-links-overflow' => $overflowMenu->getTemplateData(),
|
||||||
'data-user-links-preferences' => $preferencesMenu->getTemplateData(),
|
'data-user-links-preferences' => $preferencesMenu->getTemplateData(),
|
||||||
'data-user-links-user-page' => $userPageMenu->getTemplateData(),
|
'data-user-links-user-page' => $userPageMenu->getTemplateData(),
|
||||||
'data-user-links-dropdown' => $this->getDropdown( $isDefaultAnonUserLinks, $isAnonEditorLinksEnabled )
|
'data-user-links-dropdown' => $this->getDropdown(
|
||||||
->getTemplateData(),
|
$isDefaultAnonUserLinks, $isAnonEditorLinksEnabled, $userLinksCount )->getTemplateData(),
|
||||||
'data-user-links-menus' => array_map( static function ( $menu ) {
|
'data-user-links-menus' => array_map( static function ( $menu ) {
|
||||||
return $menu->getTemplateData();
|
return $menu->getTemplateData();
|
||||||
}, $this->getMenus( $isDefaultAnonUserLinks, $isAnonEditorLinksEnabled ) ),
|
}, $this->getMenus( $isDefaultAnonUserLinks, $isAnonEditorLinksEnabled ) ),
|
||||||
|
|
|
@ -43,6 +43,10 @@
|
||||||
@media ( min-width: @min-width-breakpoint-tablet ) {
|
@media ( min-width: @min-width-breakpoint-tablet ) {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--none {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue