From 18990e6631aea41a013713642e9f6254c3abb055 Mon Sep 17 00:00:00 2001 From: Baha Date: Tue, 1 Dec 2015 08:45:26 +0500 Subject: [PATCH] Correctly show related articles on desktop When $wgRelatedArticlesShowReadMore was false, while deciding whether to show related articles on the sidebar, we used to incorrectly consider whether BetaFeatures was enabled for the user. BetaFeatures should only be used for enabling ReadMore and not for showing related articles on the sidebar. We also used to show the beta features option for ReadMore even when the ReadMore feature was disabled. Now we only show that option if ReadMore is enabled. Also rename isAbleToShowRelatedPages to isInSidebar to make the function less confusing. Bug: T119926 Change-Id: Ia5e44d94bb20660af711772cab7e3a59f98c931f --- extension.json | 3 ++- includes/Hooks.php | 45 +++++--------------------------------- includes/ReadMoreHooks.php | 35 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/extension.json b/extension.json index adf83620..3e61c5a7 100644 --- a/extension.json +++ b/extension.json @@ -41,7 +41,7 @@ "RelatedArticles\\Hooks::onUnitTestsList" ], "GetBetaFeaturePreferences": [ - "RelatedArticles\\Hooks::onGetBetaFeaturePreferences" + "RelatedArticles\\ReadMoreHooks::onGetBetaFeaturePreferences" ], "MakeGlobalVariablesScript": [ "RelatedArticles\\ReadMoreHooks::onMakeGlobalVariablesScript" @@ -93,6 +93,7 @@ } }, "config": { + "@RelatedArticlesShowReadMore": "If true, shows ReadMore while hiding related articles from the sidebar on desktop.", "RelatedArticlesShowReadMore": false, "RelatedArticlesUseCirrusSearch": false, "RelatedArticlesOnlyUseCirrusSearch": false, diff --git a/includes/Hooks.php b/includes/Hooks.php index 0a22c17c..96c15f67 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -2,10 +2,8 @@ namespace RelatedArticles; -use BetaFeatures; use ConfigFactory; use Parser; -use Exception; use Title; use SkinTemplate; use BaseTemplate; @@ -163,7 +161,7 @@ class Hooks { $out = $skin->getOutput(); $relatedPages = $out->getProperty( 'RelatedArticles' ); - if ( !Hooks::isAbleToShowRelatedPages( $relatedPages, $out->getUser() ) ) { + if ( !Hooks::isInSidebar( $relatedPages, $out->getUser() ) ) { return true; } @@ -203,7 +201,7 @@ class Hooks { $out = $skinTpl->getSkin()->getOutput(); $relatedPages = $out->getProperty( 'RelatedArticles' ); - if ( !Hooks::isAbleToShowRelatedPages( $relatedPages, $out->getUser() ) ) { + if ( !Hooks::isInSidebar( $relatedPages, $out->getUser() ) ) { return true; } @@ -254,53 +252,22 @@ class Hooks { } /** - * GetBetaFeaturePreferences hook handler - * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetBetaFeaturePreferences - * - * @param User $user - * @param array $preferences - * - * @return bool - */ - public static function onGetBetaFeaturePreferences( User $user, array &$preferences ) { - $config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' ); - $wgExtensionAssetsPath = $config->get( 'ExtensionAssetsPath' ); - - $preferences['read-more'] = array( - 'label-message' => 'relatedarticles-read-more-beta-feature-title', - 'desc-message' => 'relatedarticles-read-more-beta-feature-description', - 'screenshot' => array( - 'ltr' => "$wgExtensionAssetsPath/RelatedArticles/images/BetaFeatures/wb-readmore-beta-ltr.svg", - 'rtl' => "$wgExtensionAssetsPath/RelatedArticles/images/BetaFeatures/wb-readmore-beta-rtl.svg", - ), - 'info-link' => 'https://www.mediawiki.org/wiki/Reading/Web/Projects/Read_more', - 'discussion-link' => 'https://www.mediawiki.org/wiki/Talk:Reading/Web/Projects/Read_more', - ); - - return true; - } - - /** - * Check whether there are related articles that can be displayed, - * the ReadMore feature is disabled, and the beta feature is - * enabled by the user. Return true if BetaFeatures is not installed. + * Check whether there are related articles that can be displayed, or + * the ReadMore feature is disabled. The beta feature is used only + * for enabling ReadMore, so do not take it into account. * * @param mixed|null $relatedPages * @param User $user * @return bool * @throws \ConfigException */ - private static function isAbleToShowRelatedPages( $relatedPages, User $user ) { + private static function isInSidebar( $relatedPages, User $user ) { $config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' ); if ( !$relatedPages || $config->get( 'RelatedArticlesShowReadMore' ) ) { return false; } - if ( class_exists( 'BetaFeatures' ) ) { - return BetaFeatures::isFeatureEnabled( $user, 'read-more' ); - } - return true; } } diff --git a/includes/ReadMoreHooks.php b/includes/ReadMoreHooks.php index 764d4c1f..c5939b0c 100644 --- a/includes/ReadMoreHooks.php +++ b/includes/ReadMoreHooks.php @@ -7,6 +7,7 @@ use OutputPage; use ResourceLoader; use Skin; use ConfigFactory; +use User; class ReadMoreHooks { /** @@ -181,4 +182,38 @@ class ReadMoreHooks { return true; } + /** + * GetBetaFeaturePreferences hook handler + * The beta feature is for showing ReadMore, not for showing related + * articles in the sidebar. + * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetBetaFeaturePreferences + * + * @param User $user + * @param array $preferences + * + * @return bool + */ + public static function onGetBetaFeaturePreferences( User $user, array &$preferences ) { + $config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' ); + $showReadMore = $config->get( 'RelatedArticlesShowReadMore' ); + + if ( $showReadMore ) { + $wgExtensionAssetsPath = $config->get( 'ExtensionAssetsPath' ); + + $preferences['read-more'] = array( + 'label-message' => 'relatedarticles-read-more-beta-feature-title', + 'desc-message' => 'relatedarticles-read-more-beta-feature-description', + 'screenshot' => array( + 'ltr' => "$wgExtensionAssetsPath/RelatedArticles/images/BetaFeatures/wb-readmore-beta-ltr.svg", + 'rtl' => "$wgExtensionAssetsPath/RelatedArticles/images/BetaFeatures/wb-readmore-beta-rtl.svg", + ), + 'info-link' => 'https://www.mediawiki.org/wiki/Reading/Web/Projects/Read_more', + 'discussion-link' => 'https://www.mediawiki.org/wiki/Talk:Reading/Web/Projects/Read_more', + ); + + } + + return true; + } + }