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
This commit is contained in:
Ammar Abdulhamid 2020-06-18 13:52:00 +01:00
parent 15a584cc02
commit a04fc71f30
3 changed files with 21 additions and 13 deletions

View File

@ -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`.
*

View File

@ -63,18 +63,6 @@ class SkinVector extends SkinTemplate {
}
}
/**
* Called by OutputPage::headElement when it is creating the
* `<body>` 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

View File

@ -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": {