mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-12-18 11:00:58 +00:00
Pages that do not exist shouldn't output related articles
Bug: T308078 Change-Id: Ie86ea03e4529e74cc5d9f71c973a5ab738ca499b
This commit is contained in:
parent
2665e3c319
commit
4d883cf58a
|
@ -78,6 +78,26 @@ class Hooks {
|
||||||
return empty( $skins ) || in_array( $skinName, $skins );
|
return empty( $skins ) || in_array( $skinName, $skins );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can the page show related articles?
|
||||||
|
*
|
||||||
|
* @param Skin $skin
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private static function hasRelatedArticles( Skin $skin ): bool {
|
||||||
|
$out = $skin->getOutput();
|
||||||
|
$title = $out->getContext()->getTitle();
|
||||||
|
$action = $out->getRequest()->getText( 'action', 'view' );
|
||||||
|
return $title->inNamespace( NS_MAIN ) &&
|
||||||
|
// T120735
|
||||||
|
$action === 'view' &&
|
||||||
|
!$title->isMainPage() &&
|
||||||
|
$title->exists() &&
|
||||||
|
!self::isDisambiguationPage( $title ) &&
|
||||||
|
!self::isDiffPage( $out ) &&
|
||||||
|
self::isReadMoreAllowedOnSkin( $out->getUser(), $out->getSkin() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the <code>BeforePageDisplay</code> hook.
|
* Handler for the <code>BeforePageDisplay</code> hook.
|
||||||
*
|
*
|
||||||
|
@ -100,18 +120,7 @@ class Hooks {
|
||||||
* @return bool Always <code>true</code>
|
* @return bool Always <code>true</code>
|
||||||
*/
|
*/
|
||||||
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
|
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
|
||||||
$title = $out->getContext()->getTitle();
|
if ( self::hasRelatedArticles( $skin ) ) {
|
||||||
$action = $out->getRequest()->getText( 'action', 'view' );
|
|
||||||
|
|
||||||
if (
|
|
||||||
$title->inNamespace( NS_MAIN ) &&
|
|
||||||
// T120735
|
|
||||||
$action === 'view' &&
|
|
||||||
!$title->isMainPage() &&
|
|
||||||
!self::isDisambiguationPage( $title ) &&
|
|
||||||
!self::isDiffPage( $out ) &&
|
|
||||||
self::isReadMoreAllowedOnSkin( $out->getUser(), $skin )
|
|
||||||
) {
|
|
||||||
$out->addModules( [ 'ext.relatedArticles.readMore.bootstrap' ] );
|
$out->addModules( [ 'ext.relatedArticles.readMore.bootstrap' ] );
|
||||||
$out->addModuleStyles( [ 'ext.relatedArticles.styles' ] );
|
$out->addModuleStyles( [ 'ext.relatedArticles.styles' ] );
|
||||||
}
|
}
|
||||||
|
@ -214,6 +223,8 @@ class Hooks {
|
||||||
* @param Skin $skin
|
* @param Skin $skin
|
||||||
*/
|
*/
|
||||||
public static function onSkinAfterContent( &$data, Skin $skin ) {
|
public static function onSkinAfterContent( &$data, Skin $skin ) {
|
||||||
|
if ( self::hasRelatedArticles( $skin ) ) {
|
||||||
$data .= \Html::element( 'div', [ 'class' => 'read-more-container' ] );
|
$data .= \Html::element( 'div', [ 'class' => 'read-more-container' ] );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue