Pages that do not exist shouldn't output related articles

Bug: T308078
Change-Id: Ie86ea03e4529e74cc5d9f71c973a5ab738ca499b
This commit is contained in:
Jon Robson 2022-05-10 15:11:51 -07:00 committed by Jdlrobson
parent 2665e3c319
commit 4d883cf58a

View file

@ -78,6 +78,26 @@ class Hooks {
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.
*
@ -100,18 +120,7 @@ class Hooks {
* @return bool Always <code>true</code>
*/
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
$title = $out->getContext()->getTitle();
$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 )
) {
if ( self::hasRelatedArticles( $skin ) ) {
$out->addModules( [ 'ext.relatedArticles.readMore.bootstrap' ] );
$out->addModuleStyles( [ 'ext.relatedArticles.styles' ] );
}
@ -214,6 +223,8 @@ class Hooks {
* @param Skin $skin
*/
public static function onSkinAfterContent( &$data, Skin $skin ) {
$data .= \Html::element( 'div', [ 'class' => 'read-more-container' ] );
if ( self::hasRelatedArticles( $skin ) ) {
$data .= \Html::element( 'div', [ 'class' => 'read-more-container' ] );
}
}
}