diff --git a/i18n/en.json b/i18n/en.json index f35556d..7397c82 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -56,5 +56,9 @@ "mobile-frontend-user-page-talk": "Talk", "mobile-frontend-user-page-uploads": "Uploads", "skinname-minerva": "MinervaNeue", - "minerva-skin-desc": "A responsive mobile first skin" + "minerva-skin-desc": "A responsive mobile first skin", + "skin-minerva-mobile-option-MinervaShowCategoriesButton": "Categories", + "skin-minerva-mobile-option-MinervaShowCategoriesButton-description": "View categories of pages", + "skin-minerva-mobile-option-MinervaEnableBackToTop": "Jump to top", + "skin-minerva-mobile-option-MinervaEnableBackToTop-description": "Jump to top of the current page using a floating button" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 20d35ec..60b8fbc 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -65,5 +65,9 @@ "mobile-frontend-user-page-talk": "Text of the link to the user's talk page\n{{Identical|Talk}}", "mobile-frontend-user-page-uploads": "Text of the link to the user's uploads page\n{{Identical|Upload}}", "skinname-minerva": "{{name}}", - "minerva-skin-desc": "{{desc|name=Minerva Neue|url=https://www.mediawiki.org/wiki/Skin:Minerva_Neue|what=skin}}" + "minerva-skin-desc": "{{desc|name=Minerva Neue|url=https://www.mediawiki.org/wiki/Skin:Minerva_Neue|what=skin}}", + "skin-minerva-mobile-option-MinervaShowCategoriesButton": "Label for categories mobile web beta feature.", + "skin-minerva-mobile-option-MinervaShowCategoriesButton-description": "Description label for categories mobile web beta feature.", + "skin-minerva-mobile-option-MinervaEnableBackToTop": "Label for jump to top mobile web beta feature", + "skin-minerva-mobile-option-MinervaEnableBackToTop-description": "Description label for jump to top mobile web beta feature" } diff --git a/includes/Minerva.hooks.php b/includes/Minerva.hooks.php index c65d939..ec4bf96 100644 --- a/includes/Minerva.hooks.php +++ b/includes/Minerva.hooks.php @@ -27,6 +27,40 @@ class MinervaHooks { $lessVars['wgMinervaApplyKnownTemplateHacks'] = $config->get( 'MinervaApplyKnownTemplateHacks' ); } + /** + * Register mobile web beta features + * @see https://www.mediawiki.org/wiki/ + * Extension:MobileFrontend/MobileFrontendFeaturesRegistration + * + * @param MobileFrontend\Features\FeaturesManager $featureManager + * @return bool + */ + public static function onMobileFrontendFeaturesRegistration( $featureManager ) { + $config = MediaWikiServices::getInstance()->getConfigFactory() + ->makeConfig( 'minerva' ); + + try { + $featureManager->registerFeature( + new MobileFrontend\Features\Feature( + 'MinervaShowCategoriesButton', + 'skin-minerva', + $config->get( 'MinervaShowCategoriesButton' ) + ) + ); + $featureManager->registerFeature( + new MobileFrontend\Features\Feature( + 'MinervaEnableBackToTop', + 'skin-minerva', + $config->get( 'MinervaEnableBackToTop' ) + ) + ); + } catch ( RuntimeException $e ) { + // features already registered... + // due to a bug it's possible for this to run twice + // https://phabricator.wikimedia.org/T165068 + } + } + /** * Skin registration callback. */ @@ -132,13 +166,19 @@ class MinervaHooks { ) { // setSkinOptions is not available if ( $skin instanceof SkinMinerva ) { + $featureManager = \MediaWiki\MediaWikiServices::getInstance() + ->getService( 'MobileFrontend.FeaturesManager' ); + + $isBeta = $mobileContext->isBetaGroupMember(); $skin->setSkinOptions( [ SkinMinerva::OPTIONS_MOBILE_BETA - => $mobileContext->isBetaGroupMember(), + => $isBeta, + SkinMinerva::OPTION_CATEGORIES - => $mobileContext->getConfigVariable( 'MinervaShowCategoriesButton' ), + => $featureManager->isFeatureAvailableInContext( 'MinervaShowCategoriesButton', + $mobileContext ), SkinMinerva::OPTION_BACK_TO_TOP - => $mobileContext->getConfigVariable( 'MinervaEnableBackToTop' ), + => $featureManager->isFeatureAvailableInContext( 'MinervaEnableBackToTop', $mobileContext ), SkinMinerva::OPTION_TOGGLING => true, SkinMinerva::OPTION_MOBILE_OPTIONS => true, ] ); diff --git a/skin.json b/skin.json index 731044f..fc11007 100644 --- a/skin.json +++ b/skin.json @@ -15,6 +15,9 @@ "minerva": "GlobalVarConfig::newInstance" }, "Hooks": { + "MobileFrontendFeaturesRegistration": [ + "MinervaHooks::onMobileFrontendFeaturesRegistration" + ], "RequestContextCreateSkinMobile": [ "MinervaHooks::onRequestContextCreateSkinMobile" ], @@ -504,10 +507,12 @@ ], "MinervaAlwaysShowLanguageButton": true, "MinervaShowCategoriesButton": { + "prefix": "skin-minerva-", "base": false, "beta": true }, "MinervaEnableBackToTop": { + "prefix": "skin-minerva-", "base": false, "beta": true }