diff --git a/includes/SkinVector.php b/includes/SkinVector.php index 5b1d7676..61232de6 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -117,7 +117,6 @@ abstract class SkinVector extends SkinMustache { ]; private const SEARCH_SHOW_THUMBNAIL_CLASS = 'vector-search-box-show-thumbnail'; private const SEARCH_AUTO_EXPAND_WIDTH_CLASS = 'vector-search-box-auto-expand-width'; - private const STICKY_HEADER_ENABLED_CLASS = 'vector-sticky-header-enabled'; private const CLASS_QUIET_BUTTON = 'mw-ui-button mw-ui-quiet'; private const CLASS_PROGRESSIVE = 'mw-ui-progressive'; private const CLASS_ICON_BUTTON = 'mw-ui-icon mw-ui-icon-element'; @@ -370,30 +369,6 @@ abstract class SkinVector extends SkinMustache { Hooks::onSkinTemplateNavigation( $skin, $content_navigation ); } - /** - * @inheritDoc - */ - public function getHtmlElementAttributes() { - $original = parent::getHtmlElementAttributes(); - - if ( VectorServices::getFeatureManager()->isFeatureEnabled( Constants::FEATURE_STICKY_HEADER ) ) { - // T290518: Add scroll padding to root element when the sticky header is - // enabled. This class needs to be server rendered instead of added from - // JS in order to correctly handle situations where the sticky header - // isn't visible yet but we still need scroll padding applied (e.g. when - // the user navigates to a page with a hash fragment in the URI). For this - // reason, we can't rely on the `vector-sticky-header-visible` class as it - // is added too late. - // - // Please note that this class applies scroll padding which does not work - // when applied to the body tag in Chrome, Safari, and Firefox (and - // possibly others). It must instead be applied to the html tag. - $original['class'] = implode( ' ', [ $original['class'] ?? '', self::STICKY_HEADER_ENABLED_CLASS ] ); - } - - return $original; - } - /** * Generate data needed to generate the sticky header. * @param array $searchBoxData diff --git a/includes/SkinVector22.php b/includes/SkinVector22.php index 88addb2e..e44648fb 100644 --- a/includes/SkinVector22.php +++ b/includes/SkinVector22.php @@ -11,6 +11,7 @@ use MediaWiki\MediaWikiServices; */ class SkinVector22 extends SkinVector { private const TOC_AB_TEST_NAME = 'skin-vector-toc-experiment'; + private const STICKY_HEADER_ENABLED_CLASS = 'vector-sticky-header-enabled'; /** * Updates the constructor to conditionally disable table of contents in article @@ -137,6 +138,30 @@ class SkinVector22 extends SkinVector { return $data; } + /** + * @inheritDoc + */ + public function getHtmlElementAttributes() { + $original = parent::getHtmlElementAttributes(); + + if ( VectorServices::getFeatureManager()->isFeatureEnabled( Constants::FEATURE_STICKY_HEADER ) ) { + // T290518: Add scroll padding to root element when the sticky header is + // enabled. This class needs to be server rendered instead of added from + // JS in order to correctly handle situations where the sticky header + // isn't visible yet but we still need scroll padding applied (e.g. when + // the user navigates to a page with a hash fragment in the URI). For this + // reason, we can't rely on the `vector-sticky-header-visible` class as it + // is added too late. + // + // Please note that this class applies scroll padding which does not work + // when applied to the body tag in Chrome, Safari, and Firefox (and + // possibly others). It must instead be applied to the html tag. + $original['class'] = implode( ' ', [ $original['class'] ?? '', self::STICKY_HEADER_ENABLED_CLASS ] ); + } + + return $original; + } + /** * @return array */