From 05cdcc09c86e392c3a512269ba24c7b6f0ebd2d2 Mon Sep 17 00:00:00 2001 From: Piotr Miazga Date: Fri, 2 Aug 2019 16:23:28 +0200 Subject: [PATCH] Hygiene: SkinOptions should know what are AMC options Do not hardcode special handling of Options in other places than SkinOptions. SkinOptions should be only one place that knows all interpedences. Change-Id: I9ad8c1560332665dbcd88ccc7105fb253a2f41b9 --- includes/SkinOptions.php | 22 ++++++++++++++++++++++ includes/skins/SkinMinerva.php | 13 ++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/includes/SkinOptions.php b/includes/SkinOptions.php index bcbb45fcf..f0b9d134a 100644 --- a/includes/SkinOptions.php +++ b/includes/SkinOptions.php @@ -109,4 +109,26 @@ final class SkinOptions { return false; } + /** + * Check if user enabled any of the options bundled in the AMC mode + * + * @todo this shouldn't exist, each option should provide it's own logic/styles/js modules + * + * @return bool + */ + public function isAnyAMCOptionEnabled() { + $keys = [ + self::AMC_MODE, + self::TALK_AT_TOP, + self::HISTORY_IN_PAGE_ACTIONS, + self::TOOLBAR_SUBMENU, + self::TABS_ON_SPECIALS + ]; + foreach ( $keys as $key ) { + if ( $this->skinOptions[$key] ) { + return true; + } + } + return false; + } } diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php index b68c7b60b..515c0f0d9 100644 --- a/includes/skins/SkinMinerva.php +++ b/includes/skins/SkinMinerva.php @@ -938,20 +938,11 @@ class SkinMinerva extends SkinTemplate { $styles[] = 'skins.minerva.icons.loggedin'; } - $keys = [ - SkinOptions::AMC_MODE, - SkinOptions::TALK_AT_TOP, - SkinOptions::HISTORY_IN_PAGE_ACTIONS, - SkinOptions::TOOLBAR_SUBMENU, - SkinOptions::TABS_ON_SPECIALS - ]; - $includeAMCStyles = array_reduce( $keys, function ( $val, $key ) { - return $val || $this->skinOptions->get( $key ); - }, false ); - if ( $includeAMCStyles ) { + if ( $this->skinOptions->isAnyAMCOptionEnabled() ) { $styles[] = 'skins.minerva.amc.styles'; $styles[] = 'wikimedia.ui'; } + if ( $this->skinOptions->get( SkinOptions::AMC_MODE ) ) { // ToolbarBuilder is reusing the Contributions icon in toolbar @see T224735 $styles[] = 'skins.minerva.mainMenu.icons';