r38139 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38138‎ | r38139 | r38140 >
Date:16:54, 28 July 2008
Author:ialex
Status:old
Tags:
Comment:
Some tweaks for r38116:
* Ported Modern too, MediaWiki:Common.css and MediaWiki:Modern.css are missing in that skin
* Don't throw E_NOTICE if $wgUseSiteCss is false

Also prettify two things:
* Align <head> items at two tabs for SkinTemplate skins
* Use an array for query string for MediaWiki:Common.css, MediaWiki:<skin>.css and gen=css
Modified paths:
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/skins/Modern.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SkinTemplate.php
@@ -142,7 +142,7 @@
143143 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
144144 global $wgMaxCredits, $wgShowCreditsIfMax;
145145 global $wgPageShowWatchingUsers;
146 - global $wgUseTrackbacks;
 146+ global $wgUseTrackbacks, $wgUseSiteJs;
147147 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
148148
149149 wfProfileIn( __METHOD__ );
@@ -282,8 +282,7 @@
283283 $tpl->setRef( 'usercss', $this->usercss);
284284 $tpl->setRef( 'userjs', $this->userjs);
285285 $tpl->setRef( 'userjsprev', $this->userjsprev);
286 - global $wgUseSiteJs;
287 - if ($wgUseSiteJs) {
 286+ if( $wgUseSiteJs ) {
288287 $jsCache = $this->loggedin ? '&smaxage=0' : '';
289288 $tpl->set( 'jsvarurl',
290289 self::makeUrl('-',
@@ -330,7 +329,7 @@
331330
332331 wfProfileIn( __METHOD__."-stuff3" );
333332 $tpl->setRef( 'newtalk', $ntl );
334 - $tpl->setRef( 'skin', $this);
 333+ $tpl->setRef( 'skin', $this );
335334 $tpl->set( 'logo', $this->logoText() );
336335 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
337336 $wgArticle and 0 != $wgArticle->getID() )
@@ -961,44 +960,63 @@
962961 }
963962
964963 /**
 964+ * Callback to get args for CSS query string, a bit like wfArrayTpCGI, but
 965+ * does not escape args
 966+ *
 967+ * @param $val
 968+ * @param $key
 969+ */
 970+ static function cssWalkCallback( &$val, $key ){
 971+ $val = "$key=$val";
 972+ }
 973+
 974+ /**
965975 * @private
966976 */
967977 function setupUserCss() {
 978+ global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
 979+
968980 wfProfileIn( __METHOD__ );
969981
970 - global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
971 -
972 - $usercss = '';
973 - $siteargs = '&maxage=' . $wgSquidMaxage;
 982+ $siteargs = array(
 983+ 'action' => 'raw',
 984+ 'maxage' => $wgSquidMaxage,
 985+ );
974986 if( $this->loggedin ) {
975987 // Ensure that logged-in users' generated CSS isn't clobbered
976988 // by anons' publicly cacheable generated CSS.
977 - $siteargs .= '&smaxage=0';
978 - $siteargs .= '&ts=' . $wgUser->mTouched;
 989+ $siteargs['smaxage'] = '0';
 990+ $siteargs['ts'] = $wgUser->mTouched;
979991 }
980992
981 - # If we use the site's dynamic CSS, throw that in, too
 993+ // If we use the site's dynamic CSS, throw that in, too
982994 // Per-site custom styles
983995 if ( $wgUseSiteCss ) {
984 - $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
985 - $skinquery = '';
986 - if (($us = $wgRequest->getVal('useskin', '')) !== '')
987 - $skinquery = "&useskin=$us";
988 -
989 - $this->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) );
990 - $this->addStyle( self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ),
 996+ $query = array(
 997+ 'usemsgcache' => 'yes',
 998+ 'ctype' => 'text/css',
 999+ 'smaxage' => $wgSquidMaxage
 1000+ ) + $siteargs;
 1001+ array_walk( $query, array( __CLASS__, 'cssWalkCallback' ) );
 1002+ $queryString = implode( '&', $query );
 1003+ $this->addStyle( self::makeNSUrl( 'Common.css', $queryString, NS_MEDIAWIKI ) );
 1004+ $this->addStyle( self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $queryString, NS_MEDIAWIKI ),
9911005 'screen' );
9921006 }
9931007
9941008 // Per-user styles based on preferences
995 - $this->addStyle( self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ), 'screen' );
 1009+ $siteargs['gen'] = 'css';
 1010+ if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' )
 1011+ $siteargs['useskin'] = $us;
 1012+ array_walk( $siteargs, array( __CLASS__, 'cssWalkCallback' ) );
 1013+ $this->addStyle( self::makeUrl( '-', implode( '&', $siteargs ) ), 'screen' );
9961014
9971015 // Per-user custom style pages
9981016 if ( $wgAllowUserCss && $this->loggedin ) {
9991017 $action = $wgRequest->getVal('action');
10001018
10011019 # if we're previewing the CSS page, use it
1002 - if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
 1020+ if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
10031021 $previewCss = $wgRequest->getText('wpTextbox1');
10041022
10051023 /// @fixme properly escape the cdata!
@@ -1115,13 +1133,11 @@
11161134 * These will be applied to various media & IE conditionals.
11171135 */
11181136 protected function buildCssLinks() {
1119 - global $wgContLang;
1120 -
11211137 foreach( $this->styles as $file => $options ) {
11221138 $links[] = $this->styleLink( $file, $options );
11231139 }
11241140
1125 - return implode( "\n", $links );
 1141+ return implode( "\n\t\t", $links );
11261142 }
11271143
11281144 protected function styleLink( $style, $options ) {
Index: trunk/phase3/includes/Skin.php
@@ -280,14 +280,14 @@
281281 static function makeVariablesScript( $data ) {
282282 global $wgJsMimeType;
283283
284 - $r = "<script type= \"$wgJsMimeType\">/*<![CDATA[*/\n";
 284+ $r = array( "<script type= \"$wgJsMimeType\">/*<![CDATA[*/" );
285285 foreach ( $data as $name => $value ) {
286286 $encValue = Xml::encodeJsVar( $value );
287 - $r .= "var $name = $encValue;\n";
 287+ $r[] = "var $name = $encValue;";
288288 }
289 - $r .= "/*]]>*/</script>\n";
 289+ $r[] = "/*]]>*/</script>\n";
290290
291 - return $r;
 291+ return implode( "\n\t\t", $r );
292292 }
293293
294294 /**
Index: trunk/phase3/skins/MonoBook.php
@@ -75,7 +75,7 @@
7676 <meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" />
7777 <?php $this->html('headlinks') ?>
7878 <title><?php $this->text('pagetitle') ?></title>
79 -<?php $this->html('csslinks') ?>
 79+ <?php $this->html('csslinks') ?>
8080
8181 <!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js?<?php echo $GLOBALS['wgStyleVersion'] ?>"></script>
8282 <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
Index: trunk/phase3/skins/Modern.php
@@ -21,15 +21,18 @@
2222 * skin L&F.
2323 */
2424 function getPoweredBy() {
25 - global $wgVersion;
 25+ global $wgVersion;
2626 return "<div class='mw_poweredby'>Powered by MediaWiki $wgVersion</div>";
2727 }
2828
2929 function initPage( &$out ) {
30 - SkinTemplate::initPage( $out );
 30+ Skin::initPage( $out );
3131 $this->skinname = 'modern';
3232 $this->stylename = 'modern';
3333 $this->template = 'ModernTemplate';
 34+
 35+ $this->addStyle( 'common/shared.css', 'screen' );
 36+ $this->addStyle( 'modern/print.css', 'print' );
3437 }
3538 }
3639
@@ -69,8 +72,8 @@
7073 @import "<?php $this->text('stylepath') ?>/common/shared.css?<?php echo $GLOBALS['wgStyleVersion'] ?>";
7174 @import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/main.css?<?php echo $GLOBALS['wgStyleVersion'] ?>";
7275 /*]]>*/</style>
73 - <?php } ?>
74 - <link rel="stylesheet" type="text/css" <?php if(empty($this->data['printable']) ) { ?>media="print"<?php } ?> href="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/print.css?<?php echo $GLOBALS['wgStyleVersion'] ?>" />
 76+ <?php }
 77+ $this->html('csslinks') ?>
7578 <!--[if lt IE 7]><meta http-equiv="imagetoolbar" content="no" /><![endif]-->
7679
7780 <?php print Skin::makeGlobalVariablesScript( $this->data ); ?>

Follow-up revisions

RevisionCommit summaryAuthorDate
r38143* (bug 14954) Fix regression in Modern and Simple skins...brion19:09, 28 July 2008
r40697(bug 15543) fix for r38139: don't include $wgUser->mTouched and smaxage=0 in ...ialex12:12, 10 September 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r38116Start on some cleanup of how CSS stylesheets are loaded. Initially addressing...brion05:09, 28 July 2008

Status & tagging log