+ * @param $sk Skin object
+ */
+ public function buildCssLinks( $sk ) {
+ $ret = '';
+ // Add ResourceLoader styles
+ // Split the styles into three groups
+ $styles = array( 'other' => array(), 'user' => array(), 'site' => array() );
+ $resourceLoader = $this->getResourceLoader();
+ foreach ( $this->getModuleStyles() as $name ) {
+ $group = $resourceLoader->getModule( $name )->getGroup();
+ // Modules in groups named "other" or anything different than "user" or "site" will
+ // be placed in the "other" group
+ $styles[isset( $styles[$group] ) ? $group : 'other'][] = $name;
+ }
+
+ // We want site and user styles to override dynamically added styles from modules, but we want
+ // dynamically added styles to override statically added styles from other modules. So the order
+ // has to be other, dynamic, site, user
+ // Add statically added styles for other modules
+ $ret .= $this->makeResourceLoaderLink( $sk, $styles['other'], 'styles' );
+ // Add normal styles added through addStyle()/addInlineStyle() here
+ $ret .= implode( "\n", $this->buildCssLinksArray() ) . $this->mInlineStyles;
+ // Add marker tag to mark the place where the client-side loader should inject dynamic styles
+ // We use a <meta> tag with a made-up name for this because that's valid HTML
+ $ret .= Html::element( 'meta', array( 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ) );
+ // Add site and user styles
+ $ret .= $this->makeResourceLoaderLink(
+ $sk, array_merge( $styles['site'], $styles['user'] ), 'styles'
+ );
+ return $ret;