mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-11-28 02:00:17 +00:00
Merge "Correctly show related articles on desktop" into dev
This commit is contained in:
commit
9794dd499b
|
@ -41,7 +41,7 @@
|
||||||
"RelatedArticles\\Hooks::onUnitTestsList"
|
"RelatedArticles\\Hooks::onUnitTestsList"
|
||||||
],
|
],
|
||||||
"GetBetaFeaturePreferences": [
|
"GetBetaFeaturePreferences": [
|
||||||
"RelatedArticles\\Hooks::onGetBetaFeaturePreferences"
|
"RelatedArticles\\ReadMoreHooks::onGetBetaFeaturePreferences"
|
||||||
],
|
],
|
||||||
"MakeGlobalVariablesScript": [
|
"MakeGlobalVariablesScript": [
|
||||||
"RelatedArticles\\ReadMoreHooks::onMakeGlobalVariablesScript"
|
"RelatedArticles\\ReadMoreHooks::onMakeGlobalVariablesScript"
|
||||||
|
@ -93,6 +93,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
"@RelatedArticlesShowReadMore": "If true, shows ReadMore while hiding related articles from the sidebar on desktop.",
|
||||||
"RelatedArticlesShowReadMore": false,
|
"RelatedArticlesShowReadMore": false,
|
||||||
"RelatedArticlesUseCirrusSearch": false,
|
"RelatedArticlesUseCirrusSearch": false,
|
||||||
"RelatedArticlesOnlyUseCirrusSearch": false,
|
"RelatedArticlesOnlyUseCirrusSearch": false,
|
||||||
|
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
namespace RelatedArticles;
|
namespace RelatedArticles;
|
||||||
|
|
||||||
use BetaFeatures;
|
|
||||||
use ConfigFactory;
|
use ConfigFactory;
|
||||||
use Parser;
|
use Parser;
|
||||||
use Exception;
|
|
||||||
use Title;
|
use Title;
|
||||||
use SkinTemplate;
|
use SkinTemplate;
|
||||||
use BaseTemplate;
|
use BaseTemplate;
|
||||||
|
@ -163,7 +161,7 @@ class Hooks {
|
||||||
$out = $skin->getOutput();
|
$out = $skin->getOutput();
|
||||||
$relatedPages = $out->getProperty( 'RelatedArticles' );
|
$relatedPages = $out->getProperty( 'RelatedArticles' );
|
||||||
|
|
||||||
if ( !Hooks::isAbleToShowRelatedPages( $relatedPages, $out->getUser() ) ) {
|
if ( !Hooks::isInSidebar( $relatedPages, $out->getUser() ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +201,7 @@ class Hooks {
|
||||||
$out = $skinTpl->getSkin()->getOutput();
|
$out = $skinTpl->getSkin()->getOutput();
|
||||||
$relatedPages = $out->getProperty( 'RelatedArticles' );
|
$relatedPages = $out->getProperty( 'RelatedArticles' );
|
||||||
|
|
||||||
if ( !Hooks::isAbleToShowRelatedPages( $relatedPages, $out->getUser() ) ) {
|
if ( !Hooks::isInSidebar( $relatedPages, $out->getUser() ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,53 +252,22 @@ class Hooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetBetaFeaturePreferences hook handler
|
* Check whether there are related articles that can be displayed, or
|
||||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetBetaFeaturePreferences
|
* the ReadMore feature is disabled. The beta feature is used only
|
||||||
*
|
* for enabling ReadMore, so do not take it into account.
|
||||||
* @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.
|
|
||||||
*
|
*
|
||||||
* @param mixed|null $relatedPages
|
* @param mixed|null $relatedPages
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \ConfigException
|
* @throws \ConfigException
|
||||||
*/
|
*/
|
||||||
private static function isAbleToShowRelatedPages( $relatedPages, User $user ) {
|
private static function isInSidebar( $relatedPages, User $user ) {
|
||||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' );
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' );
|
||||||
|
|
||||||
if ( !$relatedPages || $config->get( 'RelatedArticlesShowReadMore' ) ) {
|
if ( !$relatedPages || $config->get( 'RelatedArticlesShowReadMore' ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( class_exists( 'BetaFeatures' ) ) {
|
|
||||||
return BetaFeatures::isFeatureEnabled( $user, 'read-more' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use OutputPage;
|
||||||
use ResourceLoader;
|
use ResourceLoader;
|
||||||
use Skin;
|
use Skin;
|
||||||
use ConfigFactory;
|
use ConfigFactory;
|
||||||
|
use User;
|
||||||
|
|
||||||
class ReadMoreHooks {
|
class ReadMoreHooks {
|
||||||
/**
|
/**
|
||||||
|
@ -181,4 +182,38 @@ class ReadMoreHooks {
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue