From 72fecd41f2b7441bc26c779575bbdfc19a407fe8 Mon Sep 17 00:00:00 2001 From: Clare Ming Date: Tue, 14 Dec 2021 12:58:54 -0700 Subject: [PATCH] Add feature flag for sticky table of contents - Add TOC feature requirement. - Update data for SkinVector. - Add TOC template. Bug: T297610 Change-Id: I90bc5e21ba187ac9dd74d5e97763834795a0545b --- includes/Constants.php | 20 +++++++++++++++++ includes/ServiceWiring.php | 24 +++++++++++++++++++++ includes/SkinVector.php | 12 +++++++++++ includes/templates/TableOfContents.mustache | 3 +++ includes/templates/skin.mustache | 3 +++ skin.json | 7 ++++++ 6 files changed, 69 insertions(+) create mode 100644 includes/templates/TableOfContents.mustache diff --git a/includes/Constants.php b/includes/Constants.php index bae1c63..cf62adb 100644 --- a/includes/Constants.php +++ b/includes/Constants.php @@ -296,6 +296,26 @@ final class Constants { */ public const FEATURE_LANGUAGE_ALERT_IN_SIDEBAR = 'LanguageAlertInSidebar'; + /** + * @var string + */ + public const REQUIREMENT_TABLE_OF_CONTENTS = 'TableOfContents'; + + /** + * @var string + */ + public const CONFIG_TABLE_OF_CONTENTS = 'VectorTableOfContents'; + + /** + * @var string + */ + public const QUERY_PARAM_TABLE_OF_CONTENTS = 'tableofcontents'; + + /** + * @var string + */ + public const FEATURE_TABLE_OF_CONTENTS = 'TableOfContents'; + /** * This class is for namespacing constants only. Forbid construction. * @throws FatalError diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index ab9e243..d1f95eb 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -191,6 +191,30 @@ return [ ] ); + // Feature: T297610: Table of Contents + // ================================ + $featureManager->registerRequirement( + new OverridableConfigRequirement( + $services->getMainConfig(), + $context->getUser(), + $context->getRequest(), + null, + Constants::CONFIG_TABLE_OF_CONTENTS, + Constants::REQUIREMENT_TABLE_OF_CONTENTS, + Constants::QUERY_PARAM_TABLE_OF_CONTENTS, + null + ) + ); + + $featureManager->registerFeature( + Constants::FEATURE_TABLE_OF_CONTENTS, + [ + Constants::REQUIREMENT_FULLY_INITIALISED, + Constants::REQUIREMENT_LATEST_SKIN_VERSION, + Constants::REQUIREMENT_TABLE_OF_CONTENTS + ] + ); + // Feature: Use Wvui Search // ================================ $featureManager->registerRequirement( diff --git a/includes/SkinVector.php b/includes/SkinVector.php index 67b36bf..8a2be3e 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -461,6 +461,16 @@ class SkinVector extends SkinMustache { return $featureManager->isFeatureEnabled( Constants::FEATURE_LANGUAGE_ALERT_IN_SIDEBAR ); } + /** + * Determines if the Table of Contents should be visible. + * + * @return bool + */ + private function isTableOfContentsVisible(): bool { + $featureManager = VectorServices::getFeatureManager(); + return $featureManager->isFeatureEnabled( Constants::FEATURE_TABLE_OF_CONTENTS ); + } + /** * @inheritDoc */ @@ -498,6 +508,8 @@ class SkinVector extends SkinMustache { 'is-language-in-content-top' => $this->isLanguagesInContentAt( 'top' ), 'is-language-in-content-bottom' => $this->isLanguagesInContentAt( 'bottom' ), + 'is-vector-table-of-contents-visible' => $this->isTableOfContentsVisible(), + 'data-search-box' => $this->getSearchData( $parentData['data-search-box'], !$this->isLegacy(), diff --git a/includes/templates/TableOfContents.mustache b/includes/templates/TableOfContents.mustache new file mode 100644 index 0000000..3f5478c --- /dev/null +++ b/includes/templates/TableOfContents.mustache @@ -0,0 +1,3 @@ +
+ +
diff --git a/includes/templates/skin.mustache b/includes/templates/skin.mustache index 101c08a..e7e77a3 100644 --- a/includes/templates/skin.mustache +++ b/includes/templates/skin.mustache @@ -43,6 +43,9 @@ {{#sidebar-visible}}checked{{/sidebar-visible}}> {{>Header}} + +{{#is-vector-table-of-contents-visible}}{{>TableOfContents}}{{/is-vector-table-of-contents-visible}} +
{{>Navigation}}
diff --git a/skin.json b/skin.json index d09128b..7e37621 100644 --- a/skin.json +++ b/skin.json @@ -420,6 +420,13 @@ "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." + }, + "VectorTableOfContents": { + "value": { + "logged_in": false, + "logged_out": false + }, + "description": "@var When `VectorTableOfContents` is enabled, the sticky table of contents is shown." } }, "ServiceWiringFiles": [