mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 09:43:30 +00:00
Restore "empty state" on existing but empty talk pages
The previous approach no longer works due to changes in MediaWiki. We must now pass the data between the hook which has access to request state needed to determine if we should show this, and the hook that is capable of showing it in the right place. Bug: T362496 Change-Id: I290422c4249d288badd7c7d25e5e7e435dfd1800
This commit is contained in:
parent
d51585e02f
commit
a38ebc00d8
|
@ -917,15 +917,6 @@ class CommentFormatter {
|
|||
return $pout->getExtensionData( 'DiscussionTools-isEmptyTalkPage' ) === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append content to an empty talk page
|
||||
*/
|
||||
public static function appendToEmptyTalkPage( ParserOutput $pout, string $content ): void {
|
||||
$text = $pout->getRawText();
|
||||
$text .= $content;
|
||||
$pout->setText( $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the talk page has content above the first heading, in the lede section.
|
||||
*/
|
||||
|
|
|
@ -298,6 +298,19 @@ class PageHooks implements
|
|||
}
|
||||
$text = CommentFormatter::postprocessVisualEnhancements( $text, $output, $isMobile );
|
||||
}
|
||||
|
||||
// Append empty state if the OutputPageParserOutput hook decided that we should.
|
||||
// This depends on the order in which the hooks run. Hopefully it doesn't change.
|
||||
if ( $output->getProperty( 'DiscussionTools-emptyStateHtml' ) ) {
|
||||
// Insert before the last </div> tag, which should belong to <div class="mw-parser-output">
|
||||
$idx = strrpos( $text, '</div>' );
|
||||
$text = substr_replace(
|
||||
$text,
|
||||
$output->getProperty( 'DiscussionTools-emptyStateHtml' ),
|
||||
$idx === false ? strlen( $text ) : $idx,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -325,9 +338,11 @@ class PageHooks implements
|
|||
HookUtils::shouldDisplayEmptyState( $output->getContext() )
|
||||
) {
|
||||
$output->enableOOUI();
|
||||
CommentFormatter::appendToEmptyTalkPage(
|
||||
$pout, $this->getEmptyStateHtml( $output->getContext() )
|
||||
);
|
||||
// This must be appended after the content of the page, which wasn't added to OutputPage yet.
|
||||
// Pass it to the OutputPageBeforeHTML hook, so that it may add it at the right time.
|
||||
// This depends on the order in which the hooks run. Hopefully it doesn't change.
|
||||
$output->setProperty( 'DiscussionTools-emptyStateHtml',
|
||||
$this->getEmptyStateHtml( $output->getContext() ) );
|
||||
$output->addBodyClasses( 'ext-discussiontools-emptystate-shown' );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue