jenkins-bot has submitted this change and it was merged.

Change subject: Allow blacklisting skins for showing ReadMore in footer
......................................................................


Allow blacklisting skins for showing ReadMore in footer

Introduce a new config variable `RelatedArticlesFooterBlacklistedSkins`
to control skins that are allowed to show ReadMore in the footer.
As before Minerva beta mode is always allowed to show.

Depends-on: I366c8656a0f14a7069053b2e6199caac20471ea4
Depends-on: Ie4ac3c11e81eeea9f5b4a7161a64477cb5d60f07
Bug: T144047
Change-Id: I1663ab25083d9d907f288e60d506831bebb67945
---
M extension.json
M includes/FooterHooks.php
M tests/browser/LocalSettings.php
3 files changed, 36 insertions(+), 16 deletions(-)

Approvals:
  Jdlrobson: Looks good to me, approved
  Bmansurov: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index fe94e6b..1a7c8bb 100644
--- a/extension.json
+++ b/extension.json
@@ -95,7 +95,9 @@
                "RelatedArticlesShowInFooter": false,
                "RelatedArticlesUseCirrusSearch": false,
                "RelatedArticlesOnlyUseCirrusSearch": false,
-               "RelatedArticlesLoggingSamplingRate": 0.01
+               "RelatedArticlesLoggingSamplingRate": 0.01,
+               "@RelatedArticlesFooterBlacklistedSkins": "List of skin names 
(e.g. 'minerva') where related articles won't be shown in the footer. If absent 
related articles will show in stable on Minerva or beta on all other skins.",
+               "RelatedArticlesFooterBlacklistedSkins": []
        },
        "ConfigRegistry": {
                "RelatedArticles": "GlobalVarConfig::newInstance"
diff --git a/includes/FooterHooks.php b/includes/FooterHooks.php
index fea198c..7872220 100644
--- a/includes/FooterHooks.php
+++ b/includes/FooterHooks.php
@@ -65,6 +65,34 @@
        }
 
        /**
+        * Is ReadMore allowed on skin?
+        *
+        * The feature is allowed on all skins as long as they are not 
blacklisted
+        * in the configuration variable 
`RelatedArticlesFooterBlacklistedSkins`.
+        * On desktop, the beta feature needs to be enabled by the user as well.
+        *
+        * @param User $user
+        * @param Skin $skin
+        * @return bool
+        */
+       private static function isReadMoreAllowedOnSkin( User $user, Skin $skin 
) {
+               $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'RelatedArticles' );
+               $blacklistedSkins = $config->get( 
'RelatedArticlesFooterBlacklistedSkins' );
+               $skinName = $skin->getSkinName();
+               $isBlacklistedSkin = in_array( $skinName, $blacklistedSkins );
+
+               if ( !$isBlacklistedSkin ) {
+                       // Minerva has its own beta mode and doesn't use the 
BetaFeatures extension.
+                       if ( $skinName === 'minerva' ) {
+                               return true;
+                       }
+                       return class_exists( 'BetaFeatures' ) && 
BetaFeatures::isFeatureEnabled( $user, 'read-more' );
+               }
+
+               return false;
+       }
+
+       /**
         * Handler for the <code>BeforePageDisplay</code> hook.
         *
         * Adds the <code>ext.relatedArticles.readMore.bootstrap</code> module
@@ -74,13 +102,12 @@
         *   <li><code>$wgRelatedArticlesShowInFooter</code> is truthy</li>
         *   <li>On mobile, the output is being rendered with
         *     <code>SkinMinervaBeta<code></li>
-        *   <li>On desktop, the beta feature has been enabled</li>
         *   <li>The page is in mainspace</li>
         *   <li>The action is 'view'</li>
         *   <li>The page is not the Main Page</li>
         *   <li>The page is not a disambiguation page</li>
         *   <li>The page is not a diff page</li>
-        *   <li>The skin is not Minerva stable</li>
+        *   <li>The feature is allowed on the skin (see 
isReadMoreAllowedOnSkin() above)</li>
         * </ol>
         *
         * @param OutputPage $out
@@ -101,20 +128,10 @@
                        $action === 'view' &&
                        !$title->isMainPage() &&
                        !self::isDisambiguationPage( $title ) &&
-                       !self::isDiffPage( $out )
+                       !self::isDiffPage( $out ) &&
+                       self::isReadMoreAllowedOnSkin( $out->getUser(), $skin )
                ) {
-                       if (
-                               // FIXME: right now both Minerva stable and 
beta report their names as 'minerva'
-                               get_class( $skin ) === 'SkinMinervaBeta' ||
-                               (
-                                       // any skin except minerva stable
-                                       $skin->getSkinName() !== 'minerva' &&
-                                       class_exists( 'BetaFeatures' ) &&
-                                       BetaFeatures::isFeatureEnabled( 
$out->getUser(), 'read-more' )
-                               )
-                       ) {
-                               $out->addModules( [ 
'ext.relatedArticles.readMore.bootstrap' ] );
-                       }
+                       $out->addModules( [ 
'ext.relatedArticles.readMore.bootstrap' ] );
                }
 
                return true;
diff --git a/tests/browser/LocalSettings.php b/tests/browser/LocalSettings.php
index e4b1902..fb1e67c 100644
--- a/tests/browser/LocalSettings.php
+++ b/tests/browser/LocalSettings.php
@@ -6,3 +6,4 @@
 $wgRelatedArticlesUseCirrusSearch = true;
 $wgRelatedArticlesOnlyUseCirrusSearch = false;
 $wgMFEnableBeta = true;
+$wgRelatedArticlesFooterBlacklistedSkins = [ 'minerva' ];

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1663ab25083d9d907f288e60d506831bebb67945
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/RelatedArticles
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: Jhobs <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to