Skip to content

Commit

Permalink
Add a body class when the small-elements feature is enabled (#300)
Browse files Browse the repository at this point in the history
* Add body class if small-elements feature enabled

* Add a null check

(cherry picked from commit 29464a9)
  • Loading branch information
lens0021 committed Aug 18, 2021
1 parent 6e5e382 commit 982d0b0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Versions and bullets are arranged chronologically from latest to oldest.

## Unreleased

- `fw-legacy-small-elements` class is now added to the body element when the feature is enabled.

## v1.10.0

- Added paddings to the syntaxhighlight box. (https://github.com/femiwiki/FemiwikiSkin/issues/288)
Expand Down
25 changes: 24 additions & 1 deletion includes/SmallElementsHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

namespace MediaWiki\Skins\Femiwiki;

class SmallElementsHooks implements \MediaWiki\Preferences\Hook\GetPreferencesHook {
use MediaWiki\MediaWikiServices;

class SmallElementsHooks implements
\MediaWiki\Preferences\Hook\GetPreferencesHook,
\MediaWiki\Hook\OutputPageBodyAttributesHook
{
/**
* @inheritDoc
*/
Expand All @@ -27,4 +32,22 @@ public function onGetPreferences( $user, &$preferences ) {
$preferences += $newPrefs;
}
}

/**
* @inheritDoc
*/
public function onOutputPageBodyAttributes( $out, $sk, &$bodyAttrs ): void {
$user = $sk->getUser();
$registered = $user->isRegistered();
$config = $sk->getConfig();
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();

if (
( !$registered && $config->get( Constants::CONFIG_KEY_SMALL_ELEMENTS_FOR_ANONYMOUS_USER ) )
|| ( $registered && $userOptionsLookup->getOption( $user, Constants::PREF_KEY_LARGER_ELEMENTS, '0' ) === '0' )
) {
$bodyAttrs['class'] = $bodyAttrs['class'] ?? '';
$bodyAttrs['class'] .= ' fw-legacy-small-elements';
}
}
}
3 changes: 2 additions & 1 deletion skin.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@
"ResourceLoaderGetConfigVars": "MediaWiki\\Skins\\Femiwiki\\Hooks::onResourceLoaderGetConfigVars",
"UserMailerTransformContent": "MediaWiki\\Skins\\Femiwiki\\Hooks::onUserMailerTransformContent",
"SkinTemplateNavigation": "MediaWiki\\Skins\\Femiwiki\\Hooks::onSkinTemplateNavigation",
"GetPreferences": "SmallElements"
"GetPreferences": "SmallElements",
"OutputPageBodyAttributes": "SmallElements"
},
"config": {
"FemiwikiFirebaseKey": { "value": "" },
Expand Down

0 comments on commit 982d0b0

Please sign in to comment.