Merge "Remove custom sidebar config"

This commit is contained in:
jenkins-bot 2023-03-31 23:28:01 +00:00 committed by Gerrit Code Review
commit 206138f241
7 changed files with 1 additions and 224 deletions

View file

@ -44,28 +44,11 @@ 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
*/
public const PREF_KEY_SKIN = 'skin';
/**
* @var string
*/
public const PREF_KEY_SIDEBAR_VISIBLE = 'VectorSidebarVisible';
// These are used in the Feature Management System.
/**
* Also known as `$wgFullyInitialised`. Set to true in core/includes/Setup.php.
@ -88,11 +71,6 @@ final class Constants {
*/
public const FEATURE_LANGUAGE_IN_HEADER = 'LanguageInHeader';
/**
* @var string
*/
public const CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE = 'VectorDisableSidebarPersistence';
/**
* @var string
*/

View file

@ -625,20 +625,13 @@ class Hooks implements
}
/**
* Adds the persistent sidebar hidden API preference.
* Adds Vector specific user preferences that can only be accessed via API.
*
* @param User $user User whose preferences are being modified.
* @param array[] &$prefs Preferences description array, to be fed to a HTMLForm object.
*/
public function onGetPreferences( $user, &$prefs ): void {
$config = MediaWikiServices::getInstance()->getMainConfig();
$vectorPrefs = [
Constants::PREF_KEY_SIDEBAR_VISIBLE => [
'type' => 'api',
'default' => $config->get(
Constants::CONFIG_KEY_DEFAULT_SIDEBAR_VISIBLE_FOR_AUTHORISED_USER
),
],
Constants::PREF_KEY_PAGE_TOOLS_PINNED => [
'type' => 'api'
],
@ -724,12 +717,6 @@ class Hooks implements
$config = $out->getConfig();
$user = $out->getUser();
if ( $user->isRegistered() && self::isSkinVersionLegacy( $skinName ) ) {
$vars[ 'wgVectorDisableSidebarPersistence' ] =
$config->get(
Constants::CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE
);
}
// Must be exposed to CentralNotice banners via mw.config
$vars[ 'wgVector2022PreviewPages' ] = $config->get( 'Vector2022PreviewPages' );
}

View file

@ -243,35 +243,6 @@ class SkinVector22 extends SkinMustache {
return $original;
}
/**
* Determines wheather the initial state of sidebar is visible on not
*
* @return bool
*/
private function isMainMenuVisible(): bool {
$skin = $this->getSkin();
if ( $skin->getUser()->isRegistered() ) {
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
$userPrefSidebarState = $userOptionsLookup->getOption(
$skin->getUser(),
Constants::PREF_KEY_SIDEBAR_VISIBLE
);
$defaultLoggedinSidebarState = $this->getConfig()->get(
Constants::CONFIG_KEY_DEFAULT_SIDEBAR_VISIBLE_FOR_AUTHORISED_USER
);
// If the sidebar user preference has been set, return that value,
// if not, then the default sidebar state for logged-in users.
return ( $userPrefSidebarState !== null )
? (bool)$userPrefSidebarState
: $defaultLoggedinSidebarState;
}
return $this->getConfig()->get(
Constants::CONFIG_KEY_DEFAULT_SIDEBAR_VISIBLE_FOR_ANONYMOUS_USER
);
}
/**
* Pulls the page tools menu out of $sidebar into $pageToolsMenu
*
@ -493,7 +464,6 @@ class SkinVector22 extends SkinMustache {
'is-language-in-content' => $this->isLanguagesInContent(),
'has-buttons-in-content-top' => $this->isLanguagesInContentAt( 'top' ) || $hasAddTopicButton,
'is-language-in-content-bottom' => $this->isLanguagesInContentAt( 'bottom' ),
'is-main-menu-visible' => $this->isMainMenuVisible(),
// Cast empty string to null
'html-subtitle' => $parentData['html-subtitle'] === '' ? null : $parentData['html-subtitle']
] );

View file

@ -23,8 +23,6 @@
MenuDefinition data-portlets.data-views
MenuDefinition data-portlets.data-actions
object data-search-box. See SearchBox.mustache for documentation.
boolean is-main-menu-visible For users that want to see the sidebar on initial render, this should be
true.
string msg-vector-action-toggle-sidebar The label used by the sidebar button.
string msg-vector-main-menu-tooltip The title attribute for the main menu icon.
object data-main-menu. See MainMenu.mustache for documentation.

View file

@ -1,143 +0,0 @@
/**
* JavaScript enhancement to persist the sidebar state for logged-in users.
*
*/
/** @interface MwApi */
var /** @type {MwApi} */api,
SIDEBAR_BUTTON_ID = 'mw-sidebar-button',
debounce = require( /** @type {string} */ ( 'mediawiki.util' ) ).debounce,
SIDEBAR_CHECKBOX_ID = 'mw-sidebar-checkbox',
SIDEBAR_PREFERENCE_NAME = 'VectorSidebarVisible';
/**
* Checks if persistent is enabled at current time.
* When a user is using a browser with a screen resolution of < 1000 it is assumed
* that it is preferred that the sidebar remains closed across page views, as otherwise
* it gets in the way of reading. More context at T316191.
*
* @return {boolean}
*/
function isPersistentEnabled() {
return window.innerWidth >= 1000;
}
/**
* Execute a debounced API request to save the sidebar user preference.
* The request is meant to fire 1000 milliseconds after the last click on
* the sidebar button.
*
* @param {HTMLInputElement} checkbox
* @param {number} timeout duration
* @param {boolean} shouldTriggerResize whether a resize event is needed.
* @return {any}
*/
function saveSidebarState( checkbox, timeout, shouldTriggerResize ) {
return debounce( function () {
api = api || new mw.Api();
api.saveOption( SIDEBAR_PREFERENCE_NAME, checkbox.checked ? 1 : 0 );
if ( !shouldTriggerResize ) {
return;
}
// Trigger a resize event so other parts of the page can adapt:
var event;
if ( typeof Event === 'function' ) {
event = new Event( 'resize' );
} else {
// IE11
event = window.document.createEvent( 'UIEvents' );
event.initUIEvent( 'resize', true, false, window, 0 );
}
window.dispatchEvent( event );
}, timeout );
}
/**
* Bind the event handler that saves the sidebar state to the click event
* on the sidebar button.
*
* @param {HTMLElement|null} checkbox
* @param {HTMLElement|null} button
*/
function bindSidebarClickEvent( checkbox, button ) {
if ( checkbox instanceof HTMLInputElement && button ) {
var handler = saveSidebarState( checkbox, 1000, true );
checkbox.addEventListener( 'input', function () {
if ( isPersistentEnabled() ) {
handler();
}
} );
}
}
var /** @type {boolean} */ wasCollapsedDuringResize = false;
/**
* Collapses the sidebar if screen resolution too small.
*
* @param {HTMLInputElement} checkbox
*/
function collapseSidebar( checkbox ) {
if ( checkbox.checked ) {
wasCollapsedDuringResize = true;
checkbox.checked = false;
saveSidebarState( checkbox, 0, false )();
}
}
/**
* Expands the sidebar when the window is resized if it was previously collapsed.
*
* @param {HTMLInputElement} checkbox
*/
function expandSidebar( checkbox ) {
if ( wasCollapsedDuringResize && !checkbox.checked ) {
wasCollapsedDuringResize = false;
checkbox.checked = true;
saveSidebarState( checkbox, 0, false )();
}
}
function init() {
var checkbox = /** @type {HTMLInputElement|null} */ (
window.document.getElementById( SIDEBAR_CHECKBOX_ID )
),
button = window.document.getElementById( SIDEBAR_BUTTON_ID );
if ( mw.config.get( 'wgUserName' ) && !mw.config.get( 'wgVectorDisableSidebarPersistence' ) ) {
bindSidebarClickEvent( checkbox, button );
}
// If the user has resized their window, an open sidebar will be taking up lots of space
// so we should disable it.
// When this happens the user must expand it again manually, to avoid conflicts with multiple
// open windows (for example when an editor is viewing 2 articles side by side).
if ( checkbox ) {
var mediaQuery = window.matchMedia( '(max-width: 999px)' );
var onMediaQueryChangeCollapse = function ( /** @type {MediaQueryListEvent} */ event ) {
if ( event.matches ) {
// @ts-ignore we checked it already.
collapseSidebar( checkbox );
} else {
// @ts-ignore we checked it already.
expandSidebar( checkbox );
}
};
if ( mediaQuery.matches ) {
collapseSidebar( checkbox );
}
if ( mediaQuery.addEventListener ) {
mediaQuery.addEventListener( 'change', onMediaQueryChangeCollapse );
} else {
// Before Safari 14, MediaQueryList is based on EventTarget,
// so you must use addListener() and removeListener() to observe media query lists.
mediaQuery.addListener( onMediaQueryChangeCollapse );
}
}
}
module.exports = {
init: init
};

View file

@ -2,7 +2,6 @@ var languageButton = require( './languageButton.js' ),
echo = require( './echo.js' ),
initSearchLoader = require( './searchLoader.js' ).initSearchLoader,
dropdownMenus = require( './dropdownMenus.js' ).dropdownMenus,
sidebarPersistence = require( './sidebarPersistence.js' ),
watchstar = require( './watchstar.js' ),
// @ts-ignore
menuTabs = require( './menuTabs.js' ),
@ -72,7 +71,6 @@ function addNamespacesGadgetSupport() {
*/
function main( window ) {
enableCssAnimations( window.document );
sidebarPersistence.init();
checkbox.init( window.document );
initSearchLoader( document );
languageButton();

View file

@ -407,7 +407,6 @@
"resources/skins.vector.js/watchstar.js",
"resources/skins.vector.js/dropdownMenus.js",
"resources/skins.vector.js/checkbox.js",
"resources/skins.vector.js/sidebarPersistence.js",
"resources/skins.vector.js/languageButton.js",
"resources/skins.vector.js/echo.js",
"resources/skins.vector.js/searchLoader.js",
@ -549,12 +548,6 @@
"showDescription": true
}
},
"VectorDefaultSidebarVisibleForAuthorisedUser": {
"value": true
},
"VectorDefaultSidebarVisibleForAnonymousUser": {
"value": false
},
"VectorLanguageInHeader": {
"value": {
"logged_in": true,
@ -605,10 +598,6 @@
"value": true,
"description": "@var boolean Temporary feature flag that promotes the 'Add topic' link in the views menu, to a button in the page title bar."
},
"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."
},
"VectorTableOfContentsBeginning": {
"value": true,
"description": "@var boolean Temporary feature flag that controls link to beginning of article."