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
This commit is contained in:
Baha 2016-09-16 10:36:05 -04:00 committed by Bmansurov
parent 613ed40d23
commit 9c1404ce99
3 changed files with 36 additions and 16 deletions

View file

@ -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"

View file

@ -64,6 +64,34 @@ class FooterHooks {
return $type === 'revision' || $diff || $oldId || $isSpecialMobileDiff;
}
/**
* 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.
*
@ -74,13 +102,12 @@ class FooterHooks {
* <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 @@ class FooterHooks {
$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;

View file

@ -6,3 +6,4 @@ $wgRelatedArticlesShowInSidebar = true;
$wgRelatedArticlesUseCirrusSearch = true;
$wgRelatedArticlesOnlyUseCirrusSearch = false;
$wgMFEnableBeta = true;
$wgRelatedArticlesFooterBlacklistedSkins = [ 'minerva' ];