Move loading of mediawiki.toc from Parser to Skin
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 20 May 2017 13:39:40 +0000 (15:39 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Sun, 21 May 2017 17:06:43 +0000 (19:06 +0200)
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
includes/parser/Parser.php
includes/skins/Skin.php

index ff80f1e..59e694f 100644 (file)
@@ -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
         */
index ecee0e2..b3e37a4 100644 (file)
@@ -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 ) {
index 2cd28b4..1836661 100644 (file)
@@ -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()