Merge "Correctly show related articles on desktop" into dev

This commit is contained in:
jenkins-bot 2015-12-02 02:08:08 +00:00 committed by Gerrit Code Review
commit 9794dd499b
3 changed files with 43 additions and 40 deletions

View file

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

View file

@ -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;
}
}

View file

@ -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;
}
}