resourceloader: Ensure user.styles and site.styles having their own request
[lhc/web/wiklou.git] / includes / OutputPage.php
index e71cf18..e22f42c 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() ) {
@@ -2405,26 +2412,10 @@ class OutputPage extends ContextSource {
                        }
 
                        $sk = $this->getSkin();
-                       // add skin specific modules
-                       $modules = $sk->getDefaultModules();
-
-                       // Enforce various default modules for all pages and all skins
-                       $coreModules = [
-                               // Keep this list as small as possible
-                               'site',
-                               'mediawiki.page.startup',
-                               'mediawiki.user',
-                       ];
-
-                       // Support for high-density display images if enabled
-                       if ( $config->get( 'ResponsiveImages' ) ) {
-                               $coreModules[] = 'mediawiki.hidpi';
-                       }
-
-                       $this->addModules( $coreModules );
-                       foreach ( $modules as $group ) {
+                       foreach ( $sk->getDefaultModules() as $group ) {
                                $this->addModules( $group );
                        }
+
                        MWDebug::addModules( $this );
 
                        // Avoid PHP 7.1 warning of passing $this by reference
@@ -3017,7 +3008,7 @@ class OutputPage extends ContextSource {
                        && $this->userCanPreview();
        }
 
-       private function isUserCssPreview() {
+       protected function isUserCssPreview() {
                return $this->getConfig()->get( 'AllowUserCss' )
                        && $this->getTitle()
                        && $this->getTitle()->isCssSubpage()
@@ -3653,10 +3644,21 @@ class OutputPage extends ContextSource {
                        [ 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ]
                );
 
+               $separateReq = [ 'site.styles', 'user.styles' ];
                foreach ( $this->rlExemptStyleModules as $group => $moduleNames ) {
-                       $chunks[] = $this->makeResourceLoaderLink( $moduleNames,
+                       // Combinable modules
+                       $chunks[] = $this->makeResourceLoaderLink(
+                               array_diff( $moduleNames, $separateReq ),
                                ResourceLoaderModule::TYPE_STYLES
                        );
+
+                       foreach ( array_intersect( $moduleNames, $separateReq ) as $name ) {
+                               // These require their own dedicated request in order to support "@import"
+                               // syntax, which is incompatible with concatenation. (T147667, T37562)
+                               $chunks[] = $this->makeResourceLoaderLink( $name,
+                                       ResourceLoaderModule::TYPE_STYLES
+                               );
+                       }
                }
 
                return self::combineWrappedStrings( array_merge( $chunks, $append ) );
@@ -3918,15 +3920,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
         */