From ac140d53e61407c1f7b98c35028e289ac5292e59 Mon Sep 17 00:00:00 2001 From: Peter Ovchyn Date: Tue, 7 Jul 2020 11:59:14 +0300 Subject: [PATCH] Select initial side bar visibility depends on user login state and defaults Bug: T254230 Change-Id: If121b6c8187ef6b8562d135bd1c40403be3e9564 --- includes/Constants.php | 12 ++++++++++++ includes/VectorTemplate.php | 21 ++++++++++++++++++++- skin.json | 6 ++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/includes/Constants.php b/includes/Constants.php index 6527da378..0f6d0a3b7 100644 --- a/includes/Constants.php +++ b/includes/Constants.php @@ -55,6 +55,18 @@ final class Constants { public const CONFIG_KEY_DEFAULT_SKIN_VERSION_FOR_NEW_ACCOUNTS = 'VectorDefaultSkinVersionForNewAccounts'; + /** + * @var string + */ + public const CONFIG_KEY_DEFAULT_SIDEBAR_VISIBLE_FOR_AUTHORISED_USER = + 'VectorDefaultSidebarVisibleForAuthorisedUser'; + + /** + * @var string + */ + public const CONFIG_KEY_DEFAULT_SIDEBAR_VISIBLE_FOR_ANONYMOUS_USER = + 'VectorDefaultSidebarVisibleForAnonymousUser'; + /** * @var string */ diff --git a/includes/VectorTemplate.php b/includes/VectorTemplate.php index f53530970..ff1190cd1 100644 --- a/includes/VectorTemplate.php +++ b/includes/VectorTemplate.php @@ -22,6 +22,8 @@ * @ingroup Skins */ +use Vector\Constants; + /** * QuickTemplate subclass for Vector * @ingroup Skins @@ -170,7 +172,7 @@ class VectorTemplate extends BaseTemplate { 'data-sidebar' => $this->buildSidebar(), // [todo] fetch user preference when logged in (T246427). - 'sidebar-visible' => true, + 'sidebar-visible' => $this->isSidebarVisible(), 'msg-vector-action-toggle-sidebar' => $this->msg( 'vector-action-toggle-sidebar' )->text(), ] + $this->getMenuProps(); @@ -259,6 +261,23 @@ class VectorTemplate extends BaseTemplate { return $data; } + /** + * Determines wheather the initial state of sidebar is visible on not + * + * @return bool + */ + private function isSidebarVisible() { + $skin = $this->getSkin(); + if ( $skin->getUser()->isLoggedIn() ) { + return $this->getConfig()->get( + Constants::CONFIG_KEY_DEFAULT_SIDEBAR_VISIBLE_FOR_AUTHORISED_USER + ); + } + return $this->getConfig()->get( + Constants::CONFIG_KEY_DEFAULT_SIDEBAR_VISIBLE_FOR_ANONYMOUS_USER + ); + } + /** * Render a series of portals * diff --git a/skin.json b/skin.json index 6ee79b625..b6c4f2a6c 100644 --- a/skin.json +++ b/skin.json @@ -153,6 +153,12 @@ "VectorDefaultSkinVersionForNewAccounts": { "value": "1", "description": "@var string:['2'|'1'] The version ('2' for latest, '1' for legacy) of the Vector skin to **set** for newly created user accounts. **The value is persisted as a user preference.** This configuration is not used for preexisting accounts (see VectorDefaultSkinVersionForExistingAccounts) and only ever executed once at new account creation time." + }, + "VectorDefaultSidebarVisibleForAuthorisedUser": { + "value": true + }, + "VectorDefaultSidebarVisibleForAnonymousUser": { + "value": false } }, "ServiceWiringFiles": [