r72743 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72742‎ | r72743 | r72744 >
Date:20:18, 10 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
ResourceLoaderSiteModule now supports CSS too!
Modified paths:
  • /trunk/phase3/includes/ResourceLoader.php (modified) (history)
  • /trunk/phase3/includes/ResourceLoaderModule.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ResourceLoader.php
@@ -307,8 +307,17 @@
308308
309309 // Output
310310 if ( $context->getOnly() === 'styles' ) {
311 - foreach ( $styles as $media => $style ) {
312 - echo "@media $media {\n$style\n}\n";
 311+ if ( $context->getDebug() ) {
 312+ echo "/* $name */\n";
 313+ foreach ( $styles as $media => $style ) {
 314+ echo "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "\n}\n";
 315+ }
 316+ } else {
 317+ foreach ( $styles as $media => $style ) {
 318+ if ( strlen( $style ) ) {
 319+ echo "@media $media{" . $style . "}";
 320+ }
 321+ }
313322 }
314323 } else if ( $context->getOnly() === 'scripts' ) {
315324 echo $scripts;
Index: trunk/phase3/includes/Skin.php
@@ -646,17 +646,7 @@
647647 // If we use the site's dynamic CSS, throw that in, too
648648 // Per-site custom styles
649649 if ( $wgUseSiteCss ) {
650 - global $wgHandheldStyle;
651 -
652 - $query = wfArrayToCGI( self::getDynamicStylesheetQuery() );
653 - # Site settings must override extension css! (bug 15025)
654 - $out->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) );
655 - $out->addStyle( self::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI ), 'print' );
656 -
657 - if ( $wgHandheldStyle ) {
658 - $out->addStyle( self::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI ), 'handheld' );
659 - }
660 - $out->addStyle( self::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI ) );
 650+ $out->addModuleStyles( 'site' );
661651 }
662652
663653 global $wgAllowUserCssPrefs;
@@ -727,6 +717,7 @@
728718 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
729719 // TODO: Figure out how to best integrate this stuff into ResourceLoader
730720 $out->addStyle( $this->getStylesheet() );
 721+ // TODO: When converting old skins to use ResourceLoader (or removing them) this needs to be reconsidered
731722 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
732723 }
733724
Index: trunk/phase3/includes/ResourceLoaderModule.php
@@ -691,6 +691,8 @@
692692 }
693693
694694 public function getModifiedTime( ResourceLoaderContext $context ) {
 695+ global $wgHandheldStyle;
 696+
695697 if ( isset( $this->modifiedTime[$context->getHash()] ) ) {
696698 return $this->modifiedTime[$context->getHash()];
697699 }
@@ -698,20 +700,28 @@
699701 // HACK: We duplicate the message names from generateUserJs()
700702 // here and weird things (i.e. mtime moving backwards) can happen
701703 // when a MediaWiki:Something.js page is deleted
702 - $jsPages = array( Title::makeTitle( NS_MEDIAWIKI, 'Common.js' ),
703 - Title::makeTitle( NS_MEDIAWIKI, ucfirst( $context->getSkin() ) . '.js' )
 704+ $pages = array(
 705+ Title::makeTitle( NS_MEDIAWIKI, 'Common.js' ),
 706+ Title::makeTitle( NS_MEDIAWIKI, 'Common.css' ),
 707+ Title::makeTitle( NS_MEDIAWIKI, ucfirst( $context->getSkin() ) . '.js' ),
 708+ Title::makeTitle( NS_MEDIAWIKI, ucfirst( $context->getSkin() ) . '.css' ),
 709+ Title::makeTitle( NS_MEDIAWIKI, 'Print.css' ),
 710+
704711 );
 712+ if ( $wgHandheldStyle ) {
 713+ $pages[] = Title::makeTitle( NS_MEDIAWIKI, 'Handheld.css' );
 714+ }
705715
706716 // Do batch existence check
707717 // TODO: This would work better if page_touched were loaded by this as well
708 - $lb = new LinkBatch( $jsPages );
 718+ $lb = new LinkBatch( $pages );
709719 $lb->execute();
710720
711721 $this->modifiedTime = 1; // wfTimestamp() interprets 0 as "now"
712722
713 - foreach ( $jsPages as $jsPage ) {
714 - if ( $jsPage->exists() ) {
715 - $this->modifiedTime = max( $this->modifiedTime, wfTimestamp( TS_UNIX, $jsPage->getTouched() ) );
 723+ foreach ( $pages as $page ) {
 724+ if ( $page->exists() ) {
 725+ $this->modifiedTime = max( $this->modifiedTime, wfTimestamp( TS_UNIX, $page->getTouched() ) );
716726 }
717727 }
718728
@@ -719,7 +729,26 @@
720730 }
721731
722732 public function getStyles( ResourceLoaderContext $context ) {
723 - return array();
 733+ global $wgHandheldStyle;
 734+ $styles = array(
 735+ 'all' => array( 'Common.css', $context->getSkin() . '.css' ),
 736+ 'print' => array( 'Print.css' ),
 737+ );
 738+ if ( $wgHandheldStyle ) {
 739+ $sources['handheld'] = array( 'Handheld.css' );
 740+ }
 741+ foreach ( $styles as $media => $messages ) {
 742+ foreach ( $messages as $i => $message ) {
 743+ $style = wfMsgExt( $message, 'content' );
 744+ if ( !wfEmptyMsg( $message, $style ) ) {
 745+ $styles[$media][$i] = $style;
 746+ }
 747+ }
 748+ }
 749+ foreach ( $styles as $media => $messages ) {
 750+ $styles[$media] = implode( "\n", $messages );
 751+ }
 752+ return $styles;
724753 }
725754 public function getMessages() { return array(); }
726755 public function getLoaderScript() { return ''; }

Follow-up revisions

RevisionCommit summaryAuthorDate
r72758Removed a comment, which should have been removed in r72743tparscal21:27, 10 September 2010
r72929Fixed bug #25147, a regression caused by r72743, where one of the type checks...tparscal19:36, 13 September 2010

Status & tagging log