Jdlrobson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/396485 )

Change subject: POC: List everything that's in beta (feature management FTW)
......................................................................

POC: List everything that's in beta (feature management FTW)

Bug: T182362
Change-Id: I4b1bc734c6a9b8f5d6cf1de7bab5586d333afbe1
---
M extension.json
M includes/MobileContext.php
M includes/MobileFrontend.hooks.php
M includes/specials/SpecialMobileOptions.php
4 files changed, 95 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/85/396485/1

diff --git a/extension.json b/extension.json
index 97895e4..82e2c8e 100644
--- a/extension.json
+++ b/extension.json
@@ -1204,9 +1204,35 @@
                ]
        },
        "config": {
-               "MFEnableFontChanger": {
-                       "base": false,
-                       "beta": true
+               "MFFeatures": {
+                       "MFEnableFontChanger": {
+                               "base": false,
+                               "beta": true
+                       },
+                       "MFShowFirstParagraphBeforeInfobox": {
+                               "base": true,
+                               "beta": true
+                       },
+                       "MFLazyLoadImages": {
+                               "base": true,
+                               "beta": true
+                       },
+                       "MFLazyLoadReferences": {
+                               "base": false,
+                               "beta": true
+                       },
+                       "MFDisplayWikibaseDescriptions": {
+                               "base": false,
+                               "beta": true,
+                               "search": false,
+                               "nearby": false,
+                               "watchlist": false,
+                               "tagline": false
+                       },
+                       "MFExpandAllSectionsUserOption": {
+                               "base": false,
+                               "beta": true
+                       }
                },
                "MFContentProviderClass": 
"MobileFrontend\\ContentProviders\\DefaultContentProvider",
                "MFMwApiContentProviderBaseUri": 
"https://en.wikipedia.org/w/api.php";,
@@ -1249,19 +1275,7 @@
                                ".nomobile"
                        ]
                },
-               "MFShowFirstParagraphBeforeInfobox": {
-                       "base": true,
-                       "beta": true
-               },
-               "MFLazyLoadImages": {
-                       "base": true,
-                       "beta": true
-               },
                "MFLazyLoadSkipSmallImages": false,
-               "MFLazyLoadReferences": {
-                       "base": false,
-                       "beta": true
-               },
                "MFNoMobileCategory": false,
                "MFNoMobilePages": [],
                "MFSpecialPageTaglines": {
@@ -1301,17 +1315,7 @@
                "MFCollapseSectionsByDefault": true,
                "MFPhotoUploadWiki": null,
                "MFPhotoUploadEndpoint": "",
-               "MFExpandAllSectionsUserOption": {
-                       "base": false,
-                       "beta": true
-               },
                "MFUseWikibase": false,
-               "MFDisplayWikibaseDescriptions": {
-                       "search": false,
-                       "nearby": false,
-                       "watchlist": false,
-                       "tagline": false
-               },
                "MFRSSFeedLink": false,
                "MFSchemaEditSampleRate": 0.0625,
                "MFStripResponsiveImages": true,
diff --git a/includes/MobileContext.php b/includes/MobileContext.php
index 4f4e6af..bafaa4d 100644
--- a/includes/MobileContext.php
+++ b/includes/MobileContext.php
@@ -179,13 +179,17 @@
         *
         * @param string $variableName
         * @return mixed|null
+        * @deprecated - use isFeatureEnabled
         * @throws ConfigException If the config variable doesn't exist
         *
         * @TODO Should this be renamed, e.g. `getFlag`, or extracted?
         */
        public function getConfigVariable( $variableName ) {
                $configVariable = $this->getMFConfig()->get( $variableName ) ?: 
[];
+               return $this->isFeatureEnabledInContext( $configVariable );
+       }
 
+       private function isFeatureEnabledInContext( $configVariable ) {
                if ( !is_array( $configVariable ) ) {
                        return $configVariable;
                }
@@ -198,12 +202,39 @@
                return null;
        }
 
+       public function getFeatureConfiguration( $variableName ) {
+               $features = $this->getMFConfig()->get( 'MFFeatures' );
+               try {
+                       $bwCompatibleFeature = $this->getMFConfig()->get( 
$variableName ) ?: [];
+               } catch ( ConfigException $e ) {
+                       $bwCompatibleFeature = false;
+               }
+
+               if ( $bwCompatibleFeature ) {
+                       $feature = $bwCompatibleFeature;
+                       // @todo: Log that config needs updating
+               } elseif ( isset( $features[$variableName] ) ) {
+                       $feature = $features[$variableName];
+               }
+               return $feature;
+       }
+
+       public function isFeatureEnabled( $variableName ) {
+               $feature = $this->getFeatureConfiguration( $variableName );
+
+               if ( $feature ) {
+                       return $this->isFeatureEnabledInContext( $feature );
+               } else {
+                       return false;
+               }
+       }
+
        /**
         * Checks whether references should be lazy loaded for the current user
         * @return bool
         */
        public function isLazyLoadReferencesEnabled() {
-               return $this->getConfigVariable( 'MFLazyLoadReferences' );
+               return $this->isFeatureEnabled( 'MFLazyLoadReferences' );
        }
 
        /**
@@ -211,7 +242,7 @@
         * @return bool
         */
        public function isLazyLoadImagesEnabled() {
-               return $this->getConfigVariable( 'MFLazyLoadImages' );
+               return $this->isFeatureEnabled( 'MFLazyLoadImages' );
        }
 
        /**
@@ -221,7 +252,7 @@
         */
        public function shouldShowFirstParagraphBeforeInfobox() {
                if ( $this->showFirstParagraphBeforeInfobox === null ) {
-                       $this->showFirstParagraphBeforeInfobox = 
$this->getConfigVariable(
+                       $this->showFirstParagraphBeforeInfobox = 
$this->isFeatureEnabled(
                                'MFShowFirstParagraphBeforeInfobox' );
                }
                return $this->showFirstParagraphBeforeInfobox;
@@ -1158,8 +1189,7 @@
         *  `wgMFDisplayWikibaseDescriptions` configuration variable for detail
         */
        public function shouldShowWikibaseDescriptions( $feature ) {
-               $config = $this->getMFConfig();
-               $displayWikibaseDescriptions = $config->get( 
'MFDisplayWikibaseDescriptions' );
+               $displayWikibaseDescriptions = $this->getFeatureConfiguration( 
'MFDisplayWikibaseDescriptions' );
 
                if ( !isset( $displayWikibaseDescriptions[ $feature ] ) ) {
                        throw new DomainException(
@@ -1168,7 +1198,7 @@
                }
 
                if (
-                       $this->isBetaGroupMember() ||
+                       $this->isFeatureEnabled( 
'MFDisplayWikibaseDescriptions' ) &&
                        ( $config->get( 'MFUseWikibase' ) && 
$displayWikibaseDescriptions[ $feature ] )
                ) {
                        return true;
diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index ea88c97..16efa00 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -447,7 +447,9 @@
         */
        private static function getWikibaseStaticConfigVars( MobileContext 
$context ) {
                $config = $context->getMFConfig();
-               $features = array_keys( $config->get( 
'MFDisplayWikibaseDescriptions' ) );
+               $feature = $context->getFeatureConfiguration( 
'MFDisplayWikibaseDescriptions' );
+               $features = array_keys( $feature );
+               // @todo: remove stable/beta
                $result = [ 'wgMFDisplayWikibaseDescriptions' => [] ];
 
                foreach ( $features as $feature ) {
@@ -1193,9 +1195,9 @@
 
                // Accesses getBetaGroupMember so does not belong in 
onResourceLoaderGetConfigVars
                $vars['wgMFExpandAllSectionsUserOption'] =
-                       $context->getConfigVariable( 
'MFExpandAllSectionsUserOption' );
+                       $context->isFeatureEnabled( 
'MFExpandAllSectionsUserOption' );
 
-               $vars['wgMFEnableFontChanger'] = $context->getConfigVariable( 
'MFEnableFontChanger' );
+               $vars['wgMFEnableFontChanger'] = $context->isFeatureEnabled( 
'MFEnableFontChanger' );
                $vars += self::getWikibaseStaticConfigVars( $context );
 
                return true;
diff --git a/includes/specials/SpecialMobileOptions.php 
b/includes/specials/SpecialMobileOptions.php
index 21f2432..6dc29c2 100644
--- a/includes/specials/SpecialMobileOptions.php
+++ b/includes/specials/SpecialMobileOptions.php
@@ -72,6 +72,7 @@
        private function addSettingsForm() {
                $out = $this->getOutput();
                $context = MobileContext::singleton();
+               $features = $context->getConfig()->get( 'MFFeatures' );
                $user = $this->getUser();
 
                $out->setPageTitle( $this->msg( 
'mobile-frontend-main-menu-settings-heading' ) );
@@ -110,6 +111,30 @@
                                        'id' => 'beta-field',
                                ]
                        );
+                       foreach( $features as $key => $feature ) {
+                               if ( !$feature['base'] && $feature['beta'] ) {
+                                       $fields[] = new OOUI\FieldLayout(
+                                               new OOUI\CheckboxInputWidget( [
+                                                       'name' => 'enableBeta',
+                                                       'infusable' => true,
+                                                       'selected' => 
$context->isBetaGroupMember(),
+                                                       'id' => 
'enable-beta-toggle',
+                                                       'value' => '1',
+                                               ] ),
+                                               [
+                                                       'label' => new 
OOUI\LabelWidget( [
+                                                               'label' => new 
OOUI\HtmlSnippet(
+                                                                       
Html::rawElement( 'div', [],
+                                                                               
Html::element( 'strong', [], wfMessage( 'mobile-frontend-mobile-option-' . $key 
) ) .
+                                                                               
Html::element( 'div', [ 'class' => 'option-description' ],
+                                                                               
        wfMessage( 'mobile-frontend-mobile-option-' . $key . '-description' ) )
+                                                                       )
+                                                               ),
+                                                       ] )
+                                               ]
+                                       );
+                               }
+                       }
                }
 
                $fields[] = new OOUI\ButtonInputWidget( [

-- 
To view, visit https://gerrit.wikimedia.org/r/396485
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4b1bc734c6a9b8f5d6cf1de7bab5586d333afbe1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: specialpages
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to