Use 'BeforePageDisplay' instead of 'OutputPageBeforeHTML' for once-per-page things

Also fix a CSS selector to handle content added in multiple
'OutputPageBeforeHTML' hook calls.

Bug: T323376
Bug: T323833
Change-Id: I480d9bf544d61f0cb7bfd04cadfbf053e7e1b70e
This commit is contained in:
Bartosz Dziewoński 2022-11-18 16:07:49 +01:00
parent e0be640c35
commit 8452f94cf9
2 changed files with 36 additions and 36 deletions

View file

@ -163,6 +163,39 @@ class PageHooks implements
");"
) );
}
if ( $output->getSkin()->getSkinName() === 'minerva' ) {
$title = $output->getTitle();
if (
HookUtils::isFeatureEnabledForOutput( $output, HookUtils::NEWTOPICTOOL ) &&
// Only add the button if "New section" tab would be shown in a normal skin.
HookUtils::shouldShowNewSectionTab( $output->getContext() )
) {
$output->enableOOUI();
$output->addModuleStyles( [
// For speechBubbleAdd
'oojs-ui.styles.icons-alerts',
] );
$output->addBodyClasses( 'ext-discussiontools-init-new-topic-opened' );
// Minerva doesn't show a new topic button by default, unless the MobileFrontend
// talk page feature is enabled, but we shouldn't depend on code from there.
$output->addHTML( Html::rawElement( 'div',
[ 'class' => 'ext-discussiontools-init-new-topic' ],
( new ButtonWidget( [
'classes' => [ 'ext-discussiontools-init-new-topic-button' ],
'href' => $title->getLinkURL( [ 'action' => 'edit', 'section' => 'new' ] ),
'icon' => 'speechBubbleAdd',
'label' => $output->getContext()->msg( 'skin-action-addsection' )->text(),
'flags' => [ 'progressive', 'primary' ],
'infusable' => true,
] ) )
// For compatibility with Minerva click tracking (T295490)
->setAttributes( [ 'data-event-name' => 'talkpage.add-topic' ] )
) );
}
}
}
/**
@ -180,9 +213,8 @@ class PageHooks implements
// But that hook doesn't provide parameters that we need to render correctly
// (including the page title, interface language, and current user).
if ( strpos( $text, "class=\"mw-talkpageheader\"" ) !== false ) {
return;
}
// This hook can be executed more than once per page view if the page content is composed from
// multiple sources!
$isMobile = false;
if ( ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) {
@ -272,39 +304,6 @@ class PageHooks implements
}
}
if ( $output->getSkin()->getSkinName() === 'minerva' ) {
$title = $output->getTitle();
if (
HookUtils::isFeatureEnabledForOutput( $output, HookUtils::NEWTOPICTOOL ) &&
// Only add the button if "New section" tab would be shown in a normal skin.
HookUtils::shouldShowNewSectionTab( $output->getContext() )
) {
$output->enableOOUI();
$output->addModuleStyles( [
// For speechBubbleAdd
'oojs-ui.styles.icons-alerts',
] );
$output->addBodyClasses( 'ext-discussiontools-init-new-topic-opened' );
// Minerva doesn't show a new topic button by default, unless the MobileFrontend
// talk page feature is enabled, but we shouldn't depend on code from there.
$text .= Html::rawElement( 'div',
[ 'class' => 'ext-discussiontools-init-new-topic' ],
( new ButtonWidget( [
'classes' => [ 'ext-discussiontools-init-new-topic-button' ],
'href' => $title->getLinkURL( [ 'action' => 'edit', 'section' => 'new' ] ),
'icon' => 'speechBubbleAdd',
'label' => $output->getContext()->msg( 'skin-action-addsection' )->text(),
'flags' => [ 'progressive', 'primary' ],
'infusable' => true,
] ) )
// For compatibility with Minerva click tracking (T295490)
->setAttributes( [ 'data-event-name' => 'talkpage.add-topic' ] )
);
}
}
return true;
}

View file

@ -734,6 +734,7 @@ h1, h2, h3, h4, h5, h6 {
// stylelint-disable-next-line selector-class-pattern
.skin-minerva.ns-talk.ext-discussiontools-replytool-enabled {
// .mw-body-content selector prevents this applying to content in the preview (T318758)
.mw-body-content > .mf-section-0,
.mw-body-content > .mw-parser-output > .mf-section-0 {
> *:not( .ext-discussiontools-emptystate ) {
display: none;