Merge "Consistent spacing after colon in apihelp"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 770cf47..a8fc01d 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\Logger\LoggerFactory;
+
 /**
  * This class should be covered by a general architecture document which does
  * not exist as of January 2011.  This is one of the Core classes and should
@@ -591,6 +593,19 @@ class OutputPage extends ContextSource {
         * @return array Array of module names
         */
        public function getModuleStyles( $filter = false, $position = null ) {
+               // T97420
+               $resourceLoader = $this->getResourceLoader();
+
+               foreach ( $this->mModuleStyles as $val ) {
+                       $module = $resourceLoader->getModule( $val );
+
+                       if ( $module instanceof ResourceLoaderModule && $module->isPositionDefault() ) {
+                               $warning = __METHOD__ . ': style module should define its position explicitly: ' . $val . ' ' . get_class( $module );
+                               wfDebugLog( 'resourceloader', $warning );
+                               wfLogWarning( $warning );
+                       }
+               }
+
                return $this->getModules( $filter, $position, 'mModuleStyles' );
        }
 
@@ -823,10 +838,10 @@ class OutputPage extends ContextSource {
                }
 
                # Not modified
-               # Give a 304 response code and disable body output
+               # Give a 304 Not Modified response code and disable body output
                wfDebug( __METHOD__ . ": NOT MODIFIED, $info\n", 'log' );
                ini_set( 'zlib.output_compression', 0 );
-               $this->getRequest()->response()->header( "HTTP/1.1 304 Not Modified" );
+               $this->getRequest()->response()->statusHeader( 304 );
                $this->sendCacheControl();
                $this->disable();
 
@@ -2205,8 +2220,7 @@ class OutputPage extends ContextSource {
                        if ( Hooks::run( "BeforePageRedirect", array( $this, &$redirect, &$code ) ) ) {
                                if ( $code == '301' || $code == '303' ) {
                                        if ( !$config->get( 'DebugRedirects' ) ) {
-                                               $message = HttpStatus::getMessage( $code );
-                                               $response->header( "HTTP/1.1 $code $message" );
+                                               $response->statusHeader( $code );
                                        }
                                        $this->mLastModified = wfTimestamp( TS_RFC2822 );
                                }
@@ -2228,10 +2242,7 @@ class OutputPage extends ContextSource {
 
                        return;
                } elseif ( $this->mStatusCode ) {
-                       $message = HttpStatus::getMessage( $this->mStatusCode );
-                       if ( $message ) {
-                               $response->header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $message );
-                       }
+                       $response->statusHeader( $this->mStatusCode );
                }
 
                # Buffer output; final headers may depend on later processing
@@ -2724,7 +2735,10 @@ class OutputPage extends ContextSource {
         */
        public function getResourceLoader() {
                if ( is_null( $this->mResourceLoader ) ) {
-                       $this->mResourceLoader = new ResourceLoader( $this->getConfig() );
+                       $this->mResourceLoader = new ResourceLoader(
+                               $this->getConfig(),
+                               LoggerFactory::getInstance( 'resourceloader' )
+                       );
                }
                return $this->mResourceLoader;
        }
@@ -2968,8 +2982,10 @@ class OutputPage extends ContextSource {
                // Load embeddable private modules before any loader links
                // This needs to be TYPE_COMBINED so these modules are properly wrapped
                // in mw.loader.implement() calls and deferred until mw.user is available
-               $embedScripts = array( 'user.options', 'user.tokens' );
+               $embedScripts = array( 'user.options' );
                $links[] = $this->makeResourceLoaderLink( $embedScripts, ResourceLoaderModule::TYPE_COMBINED );
+               // Separate user.tokens as otherwise caching will be allowed (T84960)
+               $links[] = $this->makeResourceLoaderLink( 'user.tokens', ResourceLoaderModule::TYPE_COMBINED );
 
                // Scripts and messages "only" requests marked for top inclusion
                $links[] = $this->makeResourceLoaderLink(
@@ -3008,11 +3024,17 @@ class OutputPage extends ContextSource {
                // Scripts "only" requests marked for bottom inclusion
                // If we're in the <head>, use load() calls rather than <script src="..."> tags
                $links = array();
+
                $links[] = $this->makeResourceLoaderLink( $this->getModuleScripts( true, 'bottom' ),
                        ResourceLoaderModule::TYPE_SCRIPTS, /* $useESI = */ false, /* $extraQuery = */ array(),
                        /* $loadCall = */ $inHead
                );
 
+               $links[] = $this->makeResourceLoaderLink( $this->getModuleStyles( true, 'bottom' ),
+                       ResourceLoaderModule::TYPE_STYLES, /* $useESI = */ false, /* $extraQuery = */ array(),
+                       /* $loadCall = */ $inHead
+               );
+
                // Modules requests - let the client calculate dependencies and batch requests as it likes
                // Only load modules that have marked themselves for loading at the bottom
                $modules = $this->getModules( true, 'bottom' );
@@ -3070,6 +3092,9 @@ class OutputPage extends ContextSource {
         * @return string
         */
        function getBottomScripts() {
+               // In case the skin wants to add bottom CSS
+               $this->getSkin()->setupSkinUserCss( $this );
+
                // Optimise jQuery ready event cross-browser.
                // This also enforces $.isReady to be true at </body> which fixes the
                // mw.loader bug in Firefox with using document.write between </body>
@@ -3581,7 +3606,7 @@ class OutputPage extends ContextSource {
                $otherTags = ''; // Tags to append after the normal <link> tags
                $resourceLoader = $this->getResourceLoader();
 
-               $moduleStyles = $this->getModuleStyles();
+               $moduleStyles = $this->getModuleStyles( true, 'top' );
 
                // Per-site custom styles
                $moduleStyles[] = 'site';