Don't rely on ParserOutput::getTOCHTML() to determine if ToC is present

ParserOutput::getTOCHTML() is being deprecated, and all skins are now
generating the TOC from the TOCData returned by
ParserOutput::getTOCData().  The SHOW_TOC flag was introduced in core
to determine if the TOC should be shown, but Vector-2022 *may* begin to
use other heuristics to determine whether to show the TOC (T315862).
We're conservatively going to process the TOC as long as there is
TOC present to process.

Bug: T328072
Change-Id: I38b439c6752157dbee9b09c9f5443a740dbaabf4
This commit is contained in:
C. Scott Ananian 2023-01-26 16:16:05 -05:00 committed by Bartosz Dziewoński
parent c9deff179f
commit 086ce6550f
2 changed files with 12 additions and 12 deletions

View file

@ -62,17 +62,19 @@ class CommentFormatter {
// Enhance the table of contents in supporting skins (vector-2022)
// Only do the work if the HTML would be shown. It looks like we can only check this
// by checking whether the HTML for the normal TOC has been generated. Code in
// OutputPage::addParserOutputMetadata does the same.
if ( $pout->getTOCHTML() ) {
// If the TOC HTML has been generated, then the parser cache is already split by user
// language (because of the "Contents" header in the TOC), so we can render text in user
// language as well. If that behavior in core changes, then we'll have to change this to
// happen in a post-processing step (like all other transformations) to avoid splitting it.
// Only do the work if the ToC is present
// (Note that skins may decide to show the ToC even if
// "not recommended" (ie, the SHOW_TOC flag is false); see
// T315862.
if ( $pout->getTOCData() != null ) {
// The TOC generation no longer splits the parser cache
// by user language, but the call below to
// getUserLangObj() will do so.
// FIXME: change this to happen in a post-processing
// step (like all other transformations) to avoid
// splitting the cache.
$lang = $parser->getOptions()->getUserLangObj();
$sections = $pout->getTOCData() === null ? [] :
$pout->getTOCData()->getSections();
$sections = $pout->getTOCData()->getSections();
foreach ( $sections as $item ) {
$key = str_replace( '_', ' ', $item->anchor );
// Unset if we did not format this section as a topic container

View file

@ -14,8 +14,6 @@ class ApiParseDiscussionToolsTest extends ApiTestCase {
* @covers \MediaWiki\Extension\DiscussionTools\CommentFormatter::addDiscussionTools
*/
public function testApiParseSections() {
$this->markTestSkipped( 'T328072' );
$params = [
'action' => 'parse',
'title' => 'Talk:Test',