From c7e00974c7eb1cd33783f4f0354de766e70ce3c1 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 20 May 2017 15:39:40 +0200 Subject: [PATCH] Move loading of mediawiki.toc from Parser to Skin This was the only addModules() call ever to be inside Parser. Introduced in a54ef1a203d. Prior to that, mediawiki.toc had always been loaded by OutputPage (via mediawiki.util; and before that, via wikibits). This patch restores that, and also fixes T130632 by making OutputPage get it from the Skin, instead of hardcoding this somewhere in addParserOutput(). * Remove deprecated method OutputPage::enableTOC(). * Move mEnableTOC to addParserOutputText(). Bug: T130632 Change-Id: Iaad84d241a4c4348c712ac1087a664b8c9c46da4 --- includes/OutputPage.php | 23 +++++++++++------------ includes/parser/Parser.php | 1 - includes/skins/Skin.php | 4 ++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index ff80f1e425..59e694fa2c 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -285,9 +285,9 @@ class OutputPage extends ContextSource { private $mTarget = null; /** - * @var bool Whether parser output should contain table of contents + * @var bool Whether parser output contains a table of contents */ - private $mEnableTOC = true; + private $mEnableTOC = false; /** * @var bool Whether parser output should contain section edit links @@ -1839,6 +1839,14 @@ class OutputPage extends ContextSource { $outputPage = $this; Hooks::run( 'LanguageLinks', [ $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ] ); Hooks::run( 'OutputPageParserOutput', [ &$outputPage, $parserOutput ] ); + + // This check must be after 'OutputPageParserOutput' runs in addParserOutputMetadata + // so that extensions may modify ParserOutput to toggle TOC. + // This cannot be moved to addParserOutputText because that is not + // called by EditPage for Preview. + if ( $parserOutput->getTOCEnabled() && $parserOutput->getTOCHTML() ) { + $this->mEnableTOC = true; + } } /** @@ -1879,7 +1887,6 @@ class OutputPage extends ContextSource { */ function addParserOutput( $parserOutput ) { $this->addParserOutputMetadata( $parserOutput ); - $parserOutput->setTOCEnabled( $this->mEnableTOC ); // Touch section edit links only if not previously disabled if ( $parserOutput->getEditSectionTokens() ) { @@ -3902,15 +3909,7 @@ class OutputPage extends ContextSource { } /** - * Enables/disables TOC, doesn't override __NOTOC__ - * @param bool $flag - * @since 1.22 - */ - public function enableTOC( $flag = true ) { - $this->mEnableTOC = $flag; - } - - /** + * Whether the output has a table of contents * @return bool * @since 1.22 */ diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index ecee0e22d3..b3e37a46c3 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4400,7 +4400,6 @@ class Parser { $toc = Linker::tocList( $toc, $this->mOptions->getUserLangObj() ); $this->mOutput->setTOCHTML( $toc ); $toc = self::TOC_START . $toc . self::TOC_END; - $this->mOutput->addModules( 'mediawiki.toc' ); } if ( $isMain ) { diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index 2cd28b4a8d..1836661933 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -196,6 +196,10 @@ abstract class Skin extends ContextSource { $modules['content'][] = 'jquery.makeCollapsible'; } + if ( $out->isTOCEnabled() ) { + $modules['content'][] = 'mediawiki.toc'; + } + // Add various resources if required if ( $wgUseAjax && $wgEnableAPI ) { if ( $wgEnableWriteAPI && $user->isLoggedIn() -- 2.20.1