From 1874e40d87a4bfe8ccb02cbb36e342f0ac703871 Mon Sep 17 00:00:00 2001 From: Vas Jaremchuk Date: Fri, 12 Jun 2020 15:31:08 +0300 Subject: [PATCH] Drop wgVectorResponsive support from modern Vector Move the body of enableResponsiveMode method into the onBeforePageDisplayMobile hook. Replace BeforePageDisplayMobile hook with BeforePageDisplay hook. Bug: T254378 Change-Id: I63da1b67bf2b85c644e4af196bf894efc4797433 --- .gitignore | 1 + includes/Hooks.php | 30 ++++++++++++++++++++++++------ includes/SkinVector.php | 26 -------------------------- skin.json | 2 +- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 4a987d562..7ae62f2c7 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ Thumbs.db # storybook /.storybook/resolve-less-imports/ /.storybook/integration.less +.vscode diff --git a/includes/Hooks.php b/includes/Hooks.php index 9da54cea7..5af77870c 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -2,6 +2,7 @@ namespace Vector; +use ExtensionRegistry; use HTMLForm; use MediaWiki\MediaWikiServices; use OutputPage; @@ -21,16 +22,33 @@ class Hooks { /** * BeforePageDisplayMobile hook handler * - * Make Vector responsive when operating in mobile mode (useformat=mobile) + * Make Legacy Vector responsive when $wgVectorResponsive = true * - * @see https://www.mediawiki.org/wiki/Extension:MobileFrontend/BeforePageDisplayMobile + * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay * @param OutputPage $out * @param SkinTemplate $sk */ - public static function onBeforePageDisplayMobile( OutputPage $out, $sk ) { - // This makes Vector behave in responsive mode when MobileFrontend is installed - if ( $sk instanceof SkinVector ) { - $sk->enableResponsiveMode(); + public static function onBeforePageDisplay( OutputPage $out, $sk ) { + if ( !$sk instanceof SkinVector ) { + return; + } + + $skinVersionLookup = new SkinVersionLookup( + $out->getRequest(), $sk->getUser(), self::getServiceConfig() + ); + + $mobile = false; + if ( ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) { + + $mobFrontContext = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' ); + $mobile = $mobFrontContext->shouldDisplayMobileView(); + } + + if ( $skinVersionLookup->isLegacy() + && ( $mobile || $sk->getConfig()->get( 'VectorResponsive' ) ) + ) { + $out->addMeta( 'viewport', 'width=device-width, initial-scale=1' ); + $out->addModuleStyles( 'skins.vector.styles.responsive' ); } } diff --git a/includes/SkinVector.php b/includes/SkinVector.php index 6a7db9540..5c2a74498 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -37,32 +37,6 @@ class SkinVector extends SkinTemplate { public $stylename = 'Vector'; public $template = 'VectorTemplate'; - private $responsiveMode = false; - - /** - * Enables the responsive mode - */ - public function enableResponsiveMode() { - if ( !$this->responsiveMode ) { - $out = $this->getOutput(); - $out->addMeta( 'viewport', 'width=device-width, initial-scale=1' ); - $out->addModuleStyles( 'skins.vector.styles.responsive' ); - $this->responsiveMode = true; - } - } - - /** - * Initializes output page and sets up skin-specific parameters - * @param OutputPage $out Object to initialize - */ - public function initPage( OutputPage $out ) { - parent::initPage( $out ); - - if ( $this->getConfig()->get( 'VectorResponsive' ) ) { - $this->enableResponsiveMode(); - } - } - /** * @inheritDoc * @return array diff --git a/skin.json b/skin.json index d5bfe34be..04ae203ea 100644 --- a/skin.json +++ b/skin.json @@ -32,7 +32,7 @@ "vector": "GlobalVarConfig::newInstance" }, "Hooks": { - "BeforePageDisplayMobile": "Vector\\Hooks::onBeforePageDisplayMobile", + "BeforePageDisplay": "Vector\\Hooks::onBeforePageDisplay", "GetPreferences": "Vector\\Hooks::onGetPreferences", "PreferencesFormPreSave": "Vector\\Hooks::onPreferencesFormPreSave", "SkinTemplateNavigation": "Vector\\Hooks::onSkinTemplateNavigation",