From 163ae3bd91fc504dcdb080b970891d777f53dc1f Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 28 Jul 2008 16:54:06 +0000 Subject: [PATCH] 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 items at two tabs for SkinTemplate skins * Use an array for query string for MediaWiki:Common.css, MediaWiki:.css and gen=css --- includes/Skin.php | 8 ++--- includes/SkinTemplate.php | 62 ++++++++++++++++++++++++--------------- skins/Modern.php | 11 ++++--- skins/MonoBook.php | 2 +- 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index a9e44ab4d9..5fcaf68152 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -280,14 +280,14 @@ class Skin extends Linker { static function makeVariablesScript( $data ) { global $wgJsMimeType; - $r = "\n"; + $r[] = "/*]]>*/\n"; - return $r; + return implode( "\n\t\t", $r ); } /** diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index ac56d0f89f..886809acde 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -142,7 +142,7 @@ class SkinTemplate extends Skin { global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks; global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; - global $wgUseTrackbacks; + global $wgUseTrackbacks, $wgUseSiteJs; global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames; wfProfileIn( __METHOD__ ); @@ -282,8 +282,7 @@ class SkinTemplate extends Skin { $tpl->setRef( 'usercss', $this->usercss); $tpl->setRef( 'userjs', $this->userjs); $tpl->setRef( 'userjsprev', $this->userjsprev); - global $wgUseSiteJs; - if ($wgUseSiteJs) { + if( $wgUseSiteJs ) { $jsCache = $this->loggedin ? '&smaxage=0' : ''; $tpl->set( 'jsvarurl', self::makeUrl('-', @@ -330,7 +329,7 @@ class SkinTemplate extends Skin { wfProfileIn( __METHOD__."-stuff3" ); $tpl->setRef( 'newtalk', $ntl ); - $tpl->setRef( 'skin', $this); + $tpl->setRef( 'skin', $this ); $tpl->set( 'logo', $this->logoText() ); if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and $wgArticle and 0 != $wgArticle->getID() ) @@ -960,45 +959,64 @@ class SkinTemplate extends Skin { return $this->mTitle->getNamespaceKey(); } + /** + * Callback to get args for CSS query string, a bit like wfArrayTpCGI, but + * does not escape args + * + * @param $val + * @param $key + */ + static function cssWalkCallback( &$val, $key ){ + $val = "$key=$val"; + } + /** * @private */ function setupUserCss() { - wfProfileIn( __METHOD__ ); - global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser; + + wfProfileIn( __METHOD__ ); - $usercss = ''; - $siteargs = '&maxage=' . $wgSquidMaxage; + $siteargs = array( + 'action' => 'raw', + 'maxage' => $wgSquidMaxage, + ); if( $this->loggedin ) { // Ensure that logged-in users' generated CSS isn't clobbered // by anons' publicly cacheable generated CSS. - $siteargs .= '&smaxage=0'; - $siteargs .= '&ts=' . $wgUser->mTouched; + $siteargs['smaxage'] = '0'; + $siteargs['ts'] = $wgUser->mTouched; } - # If we use the site's dynamic CSS, throw that in, too + // If we use the site's dynamic CSS, throw that in, too // Per-site custom styles if ( $wgUseSiteCss ) { - $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage"; - $skinquery = ''; - if (($us = $wgRequest->getVal('useskin', '')) !== '') - $skinquery = "&useskin=$us"; - - $this->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) ); - $this->addStyle( self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ), + $query = array( + 'usemsgcache' => 'yes', + 'ctype' => 'text/css', + 'smaxage' => $wgSquidMaxage + ) + $siteargs; + array_walk( $query, array( __CLASS__, 'cssWalkCallback' ) ); + $queryString = implode( '&', $query ); + $this->addStyle( self::makeNSUrl( 'Common.css', $queryString, NS_MEDIAWIKI ) ); + $this->addStyle( self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $queryString, NS_MEDIAWIKI ), 'screen' ); } // Per-user styles based on preferences - $this->addStyle( self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ), 'screen' ); + $siteargs['gen'] = 'css'; + if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) + $siteargs['useskin'] = $us; + array_walk( $siteargs, array( __CLASS__, 'cssWalkCallback' ) ); + $this->addStyle( self::makeUrl( '-', implode( '&', $siteargs ) ), 'screen' ); // Per-user custom style pages if ( $wgAllowUserCss && $this->loggedin ) { $action = $wgRequest->getVal('action'); # if we're previewing the CSS page, use it - if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) { + if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) { $previewCss = $wgRequest->getText('wpTextbox1'); /// @fixme properly escape the cdata! @@ -1115,13 +1133,11 @@ class SkinTemplate extends Skin { * These will be applied to various media & IE conditionals. */ protected function buildCssLinks() { - global $wgContLang; - foreach( $this->styles as $file => $options ) { $links[] = $this->styleLink( $file, $options ); } - return implode( "\n", $links ); + return implode( "\n\t\t", $links ); } protected function styleLink( $style, $options ) { diff --git a/skins/Modern.php b/skins/Modern.php index 32581b16ed..a5fba0b825 100644 --- a/skins/Modern.php +++ b/skins/Modern.php @@ -21,15 +21,18 @@ class SkinModern extends SkinTemplate { * skin L&F. */ function getPoweredBy() { - global $wgVersion; + global $wgVersion; return "
Powered by MediaWiki $wgVersion
"; } function initPage( &$out ) { - SkinTemplate::initPage( $out ); + Skin::initPage( $out ); $this->skinname = 'modern'; $this->stylename = 'modern'; $this->template = 'ModernTemplate'; + + $this->addStyle( 'common/shared.css', 'screen' ); + $this->addStyle( 'modern/print.css', 'print' ); } } @@ -69,8 +72,8 @@ class ModernTemplate extends QuickTemplate { @import "text('stylepath') ?>/common/shared.css?"; @import "text('stylepath') ?>/text('stylename') ?>/main.css?"; /*]]>*/ - - data['printable']) ) { ?>media="print" href="text('stylepath') ?>/text('stylename') ?>/print.css?" /> + html('csslinks') ?> data ); ?> diff --git a/skins/MonoBook.php b/skins/MonoBook.php index edf85ace19..a96a14785c 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -75,7 +75,7 @@ class MonoBookTemplate extends QuickTemplate { html('headlinks') ?> <?php $this->text('pagetitle') ?> -html('csslinks') ?> + html('csslinks') ?> -- 2.20.1