From a04fc71f30645b54840fa059f746c9504d969649 Mon Sep 17 00:00:00 2001 From: Ammar Abdulhamid Date: Thu, 18 Jun 2020 13:52:00 +0100 Subject: [PATCH] Vector: Use OutputPageBodyAttributes hook to add body attributes This means dropping usage of Skin::addToBodyAttributes method from Skin to pave way for its deprecation/removal. The parent method is no-op, so this will not create duplicate with the hook Bug: T255698 Change-Id: Ieeccdd9ec3fdb3e3fc1a3016cfa87e0b8364aa3a --- includes/Hooks.php | 19 +++++++++++++++++++ includes/SkinVector.php | 12 ------------ skin.json | 3 ++- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index af1605d..9da54ce 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -6,6 +6,7 @@ use HTMLForm; use MediaWiki\MediaWikiServices; use OutputPage; use RequestContext; +use Skin; use SkinTemplate; use SkinVector; use User; @@ -178,6 +179,24 @@ class Hooks { $user->setOption( Constants::PREF_KEY_SKIN_VERSION, $default ); } + /** + * Called when OutputPage::headElement is creating the body tag to allow skins + * and extensions to add attributes they might need to the body of the page. + * + * @param OutputPage $out + * @param Skin $sk + * @param string[] &$bodyAttrs + */ + public static function onOutputPageBodyAttributes( OutputPage $out, Skin $sk, &$bodyAttrs ) { + $skinVersionLookup = new SkinVersionLookup( + $out->getRequest(), $sk->getUser(), self::getServiceConfig() + ); + + if ( $skinVersionLookup->isLegacy() ) { + $bodyAttrs['class'] .= ' skin-vector-legacy'; + } + } + /** * Get a configuration variable such as `Constants::CONFIG_KEY_SHOW_SKIN_PREFERENCES`. * diff --git a/includes/SkinVector.php b/includes/SkinVector.php index a3dbcce..043d9c5 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -63,18 +63,6 @@ class SkinVector extends SkinTemplate { } } - /** - * Called by OutputPage::headElement when it is creating the - * `` tag. Overrides method in Skin class. - * @param OutputPage $out - * @param array &$bodyAttrs - */ - public function addToBodyAttributes( $out, &$bodyAttrs ) { - if ( $this->isLegacy() ) { - $bodyAttrs['class'] .= ' skin-vector-legacy'; - } - } - /** * @inheritDoc * @return array diff --git a/skin.json b/skin.json index 4579504..ea108fc 100644 --- a/skin.json +++ b/skin.json @@ -36,7 +36,8 @@ "GetPreferences": "Vector\\Hooks::onGetPreferences", "PreferencesFormPreSave": "Vector\\Hooks::onPreferencesFormPreSave", "SkinTemplateNavigation": "Vector\\Hooks::onSkinTemplateNavigation", - "LocalUserCreated": "Vector\\Hooks::onLocalUserCreated" + "LocalUserCreated": "Vector\\Hooks::onLocalUserCreated", + "OutputPageBodyAttributes": "Vector\\Hooks::onOutputPageBodyAttributes" }, "@note": "When modifying skins.vector.styles definition, make sure the installer still works", "ResourceModules": {