r79732 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79731‎ | r79732 | r79733 >
Date:16:58, 6 January 2011
Author:catrope
Status:ok
Tags:
Comment:
Fix bug 26570 (user CSS preview broken) and bug 26555 (styles added with $out->addStyle() are loaded after site/user CSS)

Did this by moving RL <link> generation from getHeadLinks() to buildCssLinks() (Trevor did this earlier), but did it right this time:
* Updated callers for buildCssLinks() parameter list change so stuff doesn't explode
* Considered making buildCssLinks() tolerant of a missing $sk parameter, but decided against this: it's not used in SVN extensions anywhere
* Changed addInlineStyle() to add styles to $this->mInlineStyles instead of $this->mScripts. This unbreaks addInlineStyle(), which was used for CSS previews
* Added styles added through addStyle()/addInlineStyle() in the right place (right after normal RL styles)
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -23,7 +23,7 @@
2424 var $mLastModified = '', $mETag = false;
2525 var $mCategoryLinks = array(), $mCategories = array(), $mLanguageLinks = array();
2626
27 - var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
 27+ var $mScripts = '', $mInlineStyles = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
2828 var $mModules = array(), $mModuleScripts = array(), $mModuleStyles = array(), $mModuleMessages = array();
2929 var $mResourceLoader;
3030 var $mInlineMsg = array();
@@ -2268,12 +2268,9 @@
22692269
22702270 $ret .= implode( "\n", array(
22712271 $this->getHeadLinks( $sk ),
2272 - $this->buildCssLinks(),
2273 - $this->getHeadItems(),
 2272+ $this->buildCssLinks( $sk ),
 2273+ $this->getHeadItems()
22742274 ) );
2275 - if ( $sk->usercss ) {
2276 - $ret .= Html::inlineStyle( $sk->usercss );
2277 - }
22782275
22792276 if ( $wgUseTrackbacks && $this->isArticleRelated() ) {
22802277 $ret .= $this->getTitle()->trackbackRDF();
@@ -2623,29 +2620,6 @@
26242621 }
26252622 }
26262623 }
2627 -
2628 - // Split the styles into three groups
2629 - $styles = array( 'other' => array(), 'user' => array(), 'site' => array() );
2630 - $resourceLoader = $this->getResourceLoader();
2631 - foreach ( $this->getModuleStyles() as $name ) {
2632 - $group = $resourceLoader->getModule( $name )->getGroup();
2633 - // Modules in groups named "other" or anything different than "user" or "site" will
2634 - // be placed in the "other" group
2635 - $styles[isset( $styles[$group] ) ? $group : 'other'][] = $name;
2636 - }
2637 -
2638 - // We want site and user styles to override dynamically added styles from modules, but we want
2639 - // dynamically added styles to override statically added styles from other modules. So the order
2640 - // has to be other, dynamic, site, user
2641 - // Add statically added styles for other modules
2642 - $tags[] = $this->makeResourceLoaderLink( $sk, $styles['other'], 'styles' );
2643 - // Add marker tag to mark the place where the client-side loader should inject dynamic styles
2644 - // We use a <meta> tag with a made-up name for this because that's valid HTML
2645 - $tags[] = Html::element( 'meta', array( 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ) );
2646 - // Add site and user styles
2647 - $tags[] = $this->makeResourceLoaderLink(
2648 - $sk, array_merge( $styles['site'], $styles['user'] ), 'styles'
2649 - );
26502624 return implode( "\n", $tags );
26512625 }
26522626
@@ -2696,15 +2670,42 @@
26972671 * @param $style_css Mixed: inline CSS
26982672 */
26992673 public function addInlineStyle( $style_css ){
2700 - $this->mScripts .= Html::inlineStyle( $style_css );
 2674+ $this->mInlineStyles .= Html::inlineStyle( $style_css );
27012675 }
27022676
27032677 /**
27042678 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
27052679 * These will be applied to various media & IE conditionals.
 2680+ * @param $sk Skin object
27062681 */
2707 - public function buildCssLinks() {
2708 - return implode( "\n", $this->buildCssLinksArray() );
 2682+ public function buildCssLinks( $sk ) {
 2683+ $ret = '';
 2684+ // Add ResourceLoader styles
 2685+ // Split the styles into three groups
 2686+ $styles = array( 'other' => array(), 'user' => array(), 'site' => array() );
 2687+ $resourceLoader = $this->getResourceLoader();
 2688+ foreach ( $this->getModuleStyles() as $name ) {
 2689+ $group = $resourceLoader->getModule( $name )->getGroup();
 2690+ // Modules in groups named "other" or anything different than "user" or "site" will
 2691+ // be placed in the "other" group
 2692+ $styles[isset( $styles[$group] ) ? $group : 'other'][] = $name;
 2693+ }
 2694+
 2695+ // We want site and user styles to override dynamically added styles from modules, but we want
 2696+ // dynamically added styles to override statically added styles from other modules. So the order
 2697+ // has to be other, dynamic, site, user
 2698+ // Add statically added styles for other modules
 2699+ $ret .= $this->makeResourceLoaderLink( $sk, $styles['other'], 'styles' );
 2700+ // Add normal styles added through addStyle()/addInlineStyle() here
 2701+ $ret .= implode( "\n", $this->buildCssLinksArray() ) . $this->mInlineStyles;
 2702+ // Add marker tag to mark the place where the client-side loader should inject dynamic styles
 2703+ // We use a <meta> tag with a made-up name for this because that's valid HTML
 2704+ $ret .= Html::element( 'meta', array( 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ) );
 2705+ // Add site and user styles
 2706+ $ret .= $this->makeResourceLoaderLink(
 2707+ $sk, array_merge( $styles['site'], $styles['user'] ), 'styles'
 2708+ );
 2709+ return $ret;
27092710 }
27102711
27112712 public function buildCssLinksArray() {
Index: trunk/phase3/includes/SkinTemplate.php
@@ -219,7 +219,7 @@
220220 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
221221 $tpl->set( 'html5version', $wgHtml5Version );
222222 $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
223 - $tpl->set( 'csslinks', $out->buildCssLinks() );
 223+ $tpl->set( 'csslinks', $out->buildCssLinks( $this ) );
224224
225225 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
226226 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );

Follow-up revisions

RevisionCommit summaryAuthorDate
r805261.17: MFT r78232, r78253, r79722, r79732, r79785, r79817, r79864, r79891, r79...catrope22:19, 18 January 2011

Status & tagging log