Merge "Disable table of contents in article body"

This commit is contained in:
jenkins-bot 2021-12-17 00:17:16 +00:00 committed by Gerrit Code Review
commit c6691a191d
4 changed files with 28 additions and 6 deletions

View file

@ -188,6 +188,10 @@ final class OverridableConfigRequirement implements Requirement {
'logged_in' => $thisConfig, 'logged_in' => $thisConfig,
'logged_out' => $thisConfig, 'logged_out' => $thisConfig,
]; ];
} elseif ( array_key_exists( 'default', $thisConfig ) ) {
$thisConfig = [
'default' => $thisConfig['default'],
];
} else { } else {
$thisConfig = [ $thisConfig = [
'logged_in' => $thisConfig['logged_in'] ?? false, 'logged_in' => $thisConfig['logged_in'] ?? false,
@ -196,6 +200,8 @@ final class OverridableConfigRequirement implements Requirement {
} }
// Fallback to config. // Fallback to config.
return $thisConfig[ $this->user->isRegistered() ? 'logged_in' : 'logged_out' ]; return array_key_exists( 'default', $thisConfig ) ?
$thisConfig[ 'default' ] :
$thisConfig[ $this->user->isRegistered() ? 'logged_in' : 'logged_out' ];
} }
} }

View file

@ -198,7 +198,6 @@ return [
Constants::FEATURE_TABLE_OF_CONTENTS, Constants::FEATURE_TABLE_OF_CONTENTS,
[ [
Constants::REQUIREMENT_FULLY_INITIALISED, Constants::REQUIREMENT_FULLY_INITIALISED,
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
Constants::REQUIREMENT_TABLE_OF_CONTENTS Constants::REQUIREMENT_TABLE_OF_CONTENTS
] ]
); );

View file

@ -110,6 +110,18 @@ class SkinVector extends SkinMustache {
*/ */
private const OPT_OUT_LINK_TRACKING_CODE = 'vctw1'; private const OPT_OUT_LINK_TRACKING_CODE = 'vctw1';
/**
* Updates the constructor to conditionally disable table of contents in article
* body.
* Note, the constructor can only check feature flags that do not vary on whether the
* user is logged in e.g. features with the 'default' key set.
* @inheritDoc
*/
public function __construct( array $options ) {
$options['toc'] = !$this->isTableOfContentsVisibleInSidebar();
parent::__construct( $options );
}
/** /**
* Whether or not the legacy version of the skin is being used. * Whether or not the legacy version of the skin is being used.
* *
@ -402,6 +414,12 @@ class SkinVector extends SkinMustache {
public function generateHTML() { public function generateHTML() {
if ( $this->isLegacy() ) { if ( $this->isLegacy() ) {
$this->options['template'] = 'skin-legacy'; $this->options['template'] = 'skin-legacy';
if ( $this->isTableOfContentsVisibleInSidebar() ) {
throw new RuntimeException(
'The table of contents flag cannot safely be applied without ' .
'breaking legacy Vector. Please fix T291098 before applying.'
);
}
} }
return parent::generateHTML(); return parent::generateHTML();
} }
@ -493,7 +511,7 @@ class SkinVector extends SkinMustache {
* *
* @return bool * @return bool
*/ */
private function isTableOfContentsVisible(): bool { private function isTableOfContentsVisibleInSidebar(): bool {
$featureManager = VectorServices::getFeatureManager(); $featureManager = VectorServices::getFeatureManager();
return $featureManager->isFeatureEnabled( Constants::FEATURE_TABLE_OF_CONTENTS ); return $featureManager->isFeatureEnabled( Constants::FEATURE_TABLE_OF_CONTENTS );
} }
@ -535,7 +553,7 @@ class SkinVector extends SkinMustache {
'is-language-in-content-top' => $this->isLanguagesInContentAt( 'top' ), 'is-language-in-content-top' => $this->isLanguagesInContentAt( 'top' ),
'is-language-in-content-bottom' => $this->isLanguagesInContentAt( 'bottom' ), 'is-language-in-content-bottom' => $this->isLanguagesInContentAt( 'bottom' ),
'is-vector-table-of-contents-visible' => $this->isTableOfContentsVisible(), 'is-vector-table-of-contents-visible' => $this->isTableOfContentsVisibleInSidebar(),
'data-search-box' => $this->getSearchData( 'data-search-box' => $this->getSearchData(
$parentData['data-search-box'], $parentData['data-search-box'],

View file

@ -436,8 +436,7 @@
}, },
"VectorTableOfContents": { "VectorTableOfContents": {
"value": { "value": {
"logged_in": false, "default": false
"logged_out": false
}, },
"description": "@var When `VectorTableOfContents` is enabled, the sticky table of contents is shown." "description": "@var When `VectorTableOfContents` is enabled, the sticky table of contents is shown."
} }