diff --git a/includes/Constants.php b/includes/Constants.php index 0441d81..3e22aa6 100644 --- a/includes/Constants.php +++ b/includes/Constants.php @@ -104,6 +104,11 @@ final class Constants { */ public const FEATURE_LATEST_SKIN = 'LatestSkin'; + /** + * @var string + */ + public const CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE = 'VectorDisableSidebarPersistence'; + // These are used for query parameters. /** * Override the skin version user preference and site Config. See readme. diff --git a/includes/Hooks.php b/includes/Hooks.php index 01f5e80..f1c282d 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -224,6 +224,34 @@ class Hooks { } } + /** + * NOTE: Please use ResourceLoaderGetConfigVars hook instead if possible + * for adding config to the page. + * Adds config variables to JS that depend on current page/request. + * + * Adds a config flag that can disable saving the VectorSidebarVisible + * user preference when the sidebar menu icon is clicked. + * + * @param array &$vars Array of variables to be added into the output. + * @param OutputPage $out OutputPage instance calling the hook + */ + public static function onMakeGlobalVariablesScript( &$vars, OutputPage $out ) { + if ( $out->getSkin() instanceof SkinVector ) { + $skinVersionLookup = new SkinVersionLookup( + $out->getRequest(), + $out->getUser(), + self::getServiceConfig() + ); + + if ( !$skinVersionLookup->isLegacy() ) { + $vars[ 'wgVectorDisableSidebarPersistence' ] = + self::getConfig( + Constants::CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE + ); + } + } + } + /** * Get a configuration variable such as `Constants::CONFIG_KEY_SHOW_SKIN_PREFERENCES`. * diff --git a/resources/skins.vector.js/sidebar.js b/resources/skins.vector.js/sidebar.js index dda1f1f..e9a4a1b 100644 --- a/resources/skins.vector.js/sidebar.js +++ b/resources/skins.vector.js/sidebar.js @@ -79,8 +79,7 @@ function init( window ) { button = window.document.getElementById( SIDEBAR_BUTTON_ID ); initCheckboxHack( checkbox, button ); - - if ( mw.config.get( 'wgUserName' ) ) { + if ( mw.config.get( 'wgUserName' ) && !mw.config.get( 'wgVectorDisableSidebarPersistence' ) ) { bindSidebarClickEvent( checkbox, button ); } } diff --git a/skin.json b/skin.json index eacab0e..6da39c8 100644 --- a/skin.json +++ b/skin.json @@ -37,7 +37,8 @@ "PreferencesFormPreSave": "Vector\\Hooks::onPreferencesFormPreSave", "SkinTemplateNavigation": "Vector\\Hooks::onSkinTemplateNavigation", "LocalUserCreated": "Vector\\Hooks::onLocalUserCreated", - "OutputPageBodyAttributes": "Vector\\Hooks::onOutputPageBodyAttributes" + "OutputPageBodyAttributes": "Vector\\Hooks::onOutputPageBodyAttributes", + "MakeGlobalVariablesScript": "Vector\\Hooks::onMakeGlobalVariablesScript" }, "@note": "When modifying skins.vector.styles definition, make sure the installer still works", "ResourceModules": { @@ -164,6 +165,10 @@ "VectorLayoutMaxWidth": { "value": false, "description": "@var boolean Enables the max-width layout for the latest version of Vector. This is intended to be a very short-lived feature flag whose sole purpose is to derisk the deployment of T246420. It should be removed (and made the default) as quickly as possible." + }, + "VectorDisableSidebarPersistence": { + "value": false, + "description": "@var boolean Temporary feature flag that disables saving the sidebar expanded/collapsed state as a user-preference (triggered via clicking the main menu icon). This is intended as a temporary kill-switch in the event that the DB is overloaded with writes to the user_options table." } }, "ServiceWiringFiles": [