From 391d9ba50909acac84333d3f5aa061027823643a Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Fri, 13 Aug 2021 11:21:52 -0700 Subject: [PATCH] [refactor] Clean up responsive handling There is no need for this to be in the constructor. Separate into its own function that inherits from parent class and existing parent method isResponsive. Change-Id: I60d155ec9db99ccfe0b74271dee76275a8a6986c --- includes/SkinVector.php | 30 ++++++++++++++++++------------ skin.json | 1 + 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/includes/SkinVector.php b/includes/SkinVector.php index 166d1d01..ed874515 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -87,18 +87,6 @@ class SkinVector extends SkinMustache { $options['styles'] = [ 'skins.vector.styles.legacy' ]; $options['template'] = 'skin-legacy'; } else { - // For historic reasons, the viewport is added when Vector is loaded on the mobile - // domain. This is only possible for 3rd parties or by useskin parameter as there is - // no preference for changing mobile skin. - $responsive = $this->getConfig()->get( 'VectorResponsive' ); - if ( ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) { - $mobFrontContext = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' ); - if ( $mobFrontContext->shouldDisplayMobileView() ) { - $responsive = true; - } - } - $options['responsive'] = $responsive; - if ( $this->shouldConsolidateUserLinks() ) { $options['link'] = [ 'text-wrapper' => [ 'tag' => 'span' ] ]; } @@ -435,6 +423,24 @@ class SkinVector extends SkinMustache { return Constants::SEARCH_BOX_INPUT_LOCATION_MOVED; } + /** + * @inheritDoc + */ + public function isResponsive() { + // Check it's enabled by user preference and configuration + $responsive = parent::isResponsive() && $this->getConfig()->get( 'VectorResponsive' ); + // For historic reasons, the viewport is added when Vector is loaded on the mobile + // domain. This is only possible for 3rd parties or by useskin parameter as there is + // no preference for changing mobile skin. Only need to check if $responsive is falsey. + if ( !$responsive && ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) { + $mobFrontContext = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' ); + if ( $mobFrontContext->shouldDisplayMobileView() ) { + return true; + } + } + return $responsive; + } + /** * Determines whether or not the search input should expand when focused * before WVUI search is loaded. In WVUI, the search input expands to diff --git a/skin.json b/skin.json index d097b164..7349c916 100644 --- a/skin.json +++ b/skin.json @@ -24,6 +24,7 @@ "scripts": [ "skins.vector.js" ], + "responsive": true, "styles": [ "mediawiki.ui.button", "skins.vector.styles",