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
$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;
+ }
}
/**
*/
function addParserOutput( $parserOutput ) {
$this->addParserOutputMetadata( $parserOutput );
- $parserOutput->setTOCEnabled( $this->mEnableTOC );
// Touch section edit links only if not previously disabled
if ( $parserOutput->getEditSectionTokens() ) {
}
/**
- * 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
*/
$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 ) {
$modules['content'][] = 'jquery.makeCollapsible';
}
+ if ( $out->isTOCEnabled() ) {
+ $modules['content'][] = 'mediawiki.toc';
+ }
+
// Add various resources if required
if ( $wgUseAjax && $wgEnableAPI ) {
if ( $wgEnableWriteAPI && $user->isLoggedIn()