From 768a07ec6cf07d8b0801b9d19ee8bb6cb6996a34 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Tue, 26 Oct 2021 14:34:05 -0700 Subject: [PATCH] Add sticky header edit feature flag Can be disabled via &vectorstickyheaderedit=0 or configuration change. This will allow us to fine tune the edit features without blocking deploying the existing feature. Bug: T294383 Change-Id: Ic282ea4f2ff0108eeaa154c8a77e4e5fd30daeae --- includes/Constants.php | 20 ++++++++++++++++++ includes/ServiceWiring.php | 23 +++++++++++++++++++++ includes/SkinVector.php | 24 ++++++++++++++-------- resources/skins.vector.es6/stickyHeader.js | 11 ++++++++-- skin.json | 7 +++++++ 5 files changed, 74 insertions(+), 11 deletions(-) diff --git a/includes/Constants.php b/includes/Constants.php index 041ae2b..fc2131f 100644 --- a/includes/Constants.php +++ b/includes/Constants.php @@ -171,21 +171,41 @@ final class Constants { */ public const QUERY_PARAM_STICKY_HEADER = 'vectorstickyheader'; + /** + * @var string + */ + public const QUERY_PARAM_STICKY_HEADER_EDIT = 'vectorstickyheaderedit'; + /** * @var string */ public const CONFIG_STICKY_HEADER = 'VectorStickyHeader'; + /** + * @var string + */ + public const CONFIG_STICKY_HEADER_EDIT = 'VectorStickyHeaderEdit'; + /** * @var string */ public const REQUIREMENT_STICKY_HEADER = 'StickyHeader'; + /** + * @var string + */ + public const REQUIREMENT_STICKY_HEADER_EDIT = 'StickyHeaderEdit'; + /** * @var string */ public const FEATURE_STICKY_HEADER = 'StickyHeader'; + /** + * @var string + */ + public const FEATURE_STICKY_HEADER_EDIT = 'StickyHeaderEdit'; + /** * The `mediawiki.searchSuggest` protocol piece of the SearchSatisfaction instrumention reads * the value of an element with the "data-search-loc" attribute and set the event's diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 1d436dd..6d944b0 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -167,6 +167,19 @@ return [ ) ); + $featureManager->registerRequirement( + new OverridableConfigRequirement( + $services->getMainConfig(), + $context->getUser(), + $context->getRequest(), + null, + Constants::CONFIG_STICKY_HEADER_EDIT, + Constants::REQUIREMENT_STICKY_HEADER_EDIT, + Constants::QUERY_PARAM_STICKY_HEADER_EDIT, + null + ) + ); + $featureManager->registerFeature( Constants::FEATURE_STICKY_HEADER, [ @@ -176,6 +189,16 @@ return [ ] ); + $featureManager->registerFeature( + Constants::FEATURE_STICKY_HEADER_EDIT, + [ + Constants::REQUIREMENT_FULLY_INITIALISED, + Constants::REQUIREMENT_LATEST_SKIN_VERSION, + Constants::REQUIREMENT_STICKY_HEADER, + Constants::REQUIREMENT_STICKY_HEADER_EDIT, + ] + ); + return $featureManager; } ]; diff --git a/includes/SkinVector.php b/includes/SkinVector.php index 8745bd5..7f5aa3e 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -376,11 +376,20 @@ class SkinVector extends SkinMustache { /** * Generate data needed to generate the sticky header. - * Lack of i18n is intentional and will be done as part of follow up work. * @param array $searchBoxData + * @param bool $includeEditIcons * @return array */ - private function getStickyHeaderData( $searchBoxData ): array { + private function getStickyHeaderData( $searchBoxData, $includeEditIcons ): array { + $btns = [ + self::TALK_ICON, + self::HISTORY_ICON, + ]; + if ( $includeEditIcons ) { + $btns[] = self::EDIT_WIKITEXT_ICON; + $btns[] = self::EDIT_PROTECTED_ICON; + $btns[] = self::EDIT_VE_ICON; + } return [ 'data-primary-action' => !$this->shouldHideLanguages() ? $this->getULSButtonData() : null, 'data-button-start' => [ @@ -391,13 +400,7 @@ class SkinVector extends SkinMustache { 'class' => 'vector-sticky-header-search-toggle', ], 'data-search' => $searchBoxData, - 'data-buttons' => [ - self::TALK_ICON, - self::HISTORY_ICON, - self::EDIT_WIKITEXT_ICON, - self::EDIT_PROTECTED_ICON, - self::EDIT_VE_ICON - ] + 'data-buttons' => $btns, ]; } @@ -452,6 +455,9 @@ class SkinVector extends SkinMustache { false, false, 'vector-sticky-search-form' + ), + VectorServices::getFeatureManager()->isFeatureEnabled( + Constants::FEATURE_STICKY_HEADER_EDIT ) ) : false, ] ); diff --git a/resources/skins.vector.es6/stickyHeader.js b/resources/skins.vector.es6/stickyHeader.js index 0a4e9ef..04f471d 100644 --- a/resources/skins.vector.es6/stickyHeader.js +++ b/resources/skins.vector.es6/stickyHeader.js @@ -133,11 +133,14 @@ function prepareEditIcons( disableStickyHeader ) { const - primaryEditSticky = toHTMLElement( + primaryEditStickyElement = header.querySelector( + '#ca-ve-edit-sticky-header' + ), + primaryEditSticky = primaryEditStickyElement ? toHTMLElement( header.querySelector( '#ca-ve-edit-sticky-header' ) - ), + ) : null, protectedSticky = toHTMLElement( header.querySelector( '#ca-viewsource-sticky-header' @@ -149,6 +152,10 @@ function prepareEditIcons( ) ); + // If no primary edit icon is present the feature is disabled. + if ( !primaryEditSticky ) { + return; + } if ( !primaryEdit ) { removeNode( protectedSticky ); removeNode( wikitextSticky ); diff --git a/skin.json b/skin.json index 3eede44..3dfeb20 100644 --- a/skin.json +++ b/skin.json @@ -357,6 +357,13 @@ }, "description": "@var array Enables a persistent header that allows quick access to user links, editing tools, search and other links while scrolling down a page" }, + "VectorStickyHeaderEdit": { + "value": { + "logged_in": true, + "logged_out": false + }, + "description": "@var array Enables the edit icons if $wgVectorStickyHeader is true." + }, "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."