Merge "Clean up spacing of doc comments"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 8efce10..b7341e3 100644 (file)
@@ -54,7 +54,8 @@ class OutputPage extends ContextSource {
        protected $mCanonicalUrl = false;
 
        /**
-        * @var string The contents of <h1> */
+        * @var string The contents of <h1>
+        */
        private $mPageTitle = '';
 
        /**
@@ -3047,8 +3048,8 @@ class OutputPage extends ContextSource {
 
                // This library is intended to run on older browsers that MediaWiki no longer
                // supports as Grade A. For these Grade C browsers, we provide an experience
-               // using only HTML and CSS. Where standards-compliant browsers are able to style
-               // unknown HTML elements without issue, old IE ignores these styles.
+               // using only HTML and CSS. But, where standards-compliant browsers are able to
+               // style unknown HTML elements without issue, old IE ignores these styles.
                // The html5shiv library fixes that.
                // Use an IE conditional comment to serve the script only to old IE
                $shivUrl = $config->get( 'ResourceBasePath' ) . '/resources/lib/html5shiv/html5shiv.js';
@@ -3710,43 +3711,54 @@ class OutputPage extends ContextSource {
         */
        protected function buildExemptModules() {
                $chunks = [];
-               // Things that go after the ResourceLoaderDynamicStyles marker
-               $append = [];
 
-               // We want site, private and user styles to override dynamically added styles from
-               // general modules, but we want dynamically added styles to override statically added
-               // style modules. So the order has to be:
-               // - page style modules (formatted by ResourceLoaderClientHtml::getHeadHtml())
-               // - dynamically loaded styles (added by mw.loader before ResourceLoaderDynamicStyles)
-               // - ResourceLoaderDynamicStyles marker
-               // - site/private/user styles
+               // Requirements:
+               // - Within modules provided by the software (core, skin, extensions),
+               //   styles from skin stylesheets should be overridden by styles
+               //   from modules dynamically loaded with JavaScript.
+               // - Styles from site-specific, private, and user modules should override
+               //   both of the above.
+               //
+               // The effective order for stylesheets must thus be:
+               // 1. Page style modules, formatted server-side by ResourceLoaderClientHtml.
+               // 2. Dynamically-loaded styles, inserted client-side by mw.loader.
+               // 3. Styles that are site-specific, private or from the user, formatted
+               //    server-side by this function.
+               //
+               // The 'ResourceLoaderDynamicStyles' marker helps JavaScript know where
+               // point #2 is.
 
                // Add legacy styles added through addStyle()/addInlineStyle() here
                $chunks[] = implode( '', $this->buildCssLinksArray() ) . $this->mInlineStyles;
 
-               $chunks[] = Html::element(
-                       'meta',
-                       [ 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ]
-               );
-
+               // Things that go after the ResourceLoaderDynamicStyles marker
+               $append = [];
                $separateReq = [ 'site.styles', 'user.styles' ];
                foreach ( $this->rlExemptStyleModules as $group => $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,
+                       if ( $moduleNames ) {
+                               $append[] = $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)
+                                       $append[] = $this->makeResourceLoaderLink( $name,
+                                               ResourceLoaderModule::TYPE_STYLES
+                                       );
+                               }
                        }
                }
+               if ( $append ) {
+                       $chunks[] = Html::element(
+                               'meta',
+                               [ 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ]
+                       );
+                       $chunks = array_merge( $chunks, $append );
+               }
 
-               return self::combineWrappedStrings( array_merge( $chunks, $append ) );
+               return self::combineWrappedStrings( $chunks );
        }
 
        /**