Some tweaks for r38116:
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Mon, 28 Jul 2008 16:54:06 +0000 (16:54 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Mon, 28 Jul 2008 16:54:06 +0000 (16:54 +0000)
* 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

includes/Skin.php
includes/SkinTemplate.php
skins/Modern.php
skins/MonoBook.php

index a9e44ab..5fcaf68 100644 (file)
@@ -280,14 +280,14 @@ class Skin extends Linker {
        static function makeVariablesScript( $data ) {
                global $wgJsMimeType;
 
-               $r = "<script type= \"$wgJsMimeType\">/*<![CDATA[*/\n";
+               $r = array( "<script type= \"$wgJsMimeType\">/*<![CDATA[*/" );
                foreach ( $data as $name => $value ) {
                        $encValue = Xml::encodeJsVar( $value );
-                       $r .= "var $name = $encValue;\n";
+                       $r[] = "var $name = $encValue;";
                }
-               $r .= "/*]]>*/</script>\n";
+               $r[] = "/*]]>*/</script>\n";
 
-               return $r;
+               return implode( "\n\t\t", $r );
        }
 
        /**
index ac56d0f..886809a 100644 (file)
@@ -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 ) {
index 32581b1..a5fba0b 100644 (file)
@@ -21,15 +21,18 @@ class SkinModern extends SkinTemplate {
         * skin L&F.
         */
        function getPoweredBy() {
-       global  $wgVersion;
+               global  $wgVersion;
                return "<div class='mw_poweredby'>Powered by MediaWiki $wgVersion</div>";
        }
 
        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 "<?php $this->text('stylepath') ?>/common/shared.css?<?php echo $GLOBALS['wgStyleVersion'] ?>";
                        @import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/main.css?<?php echo $GLOBALS['wgStyleVersion'] ?>";
                /*]]>*/</style>
-               <?php } ?>
-               <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'] ?>" />
+               <?php }
+               $this->html('csslinks') ?>
                <!--[if lt IE 7]><meta http-equiv="imagetoolbar" content="no" /><![endif]-->
                
                <?php print Skin::makeGlobalVariablesScript( $this->data ); ?>
index edf85ac..a96a147 100644 (file)
@@ -75,7 +75,7 @@ class MonoBookTemplate extends QuickTemplate {
                <meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" />
                <?php $this->html('headlinks') ?>
                <title><?php $this->text('pagetitle') ?></title>
-<?php $this->html('csslinks') ?>
+               <?php $this->html('csslinks') ?>
 
                <!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js?<?php echo $GLOBALS['wgStyleVersion'] ?>"></script>
                <meta http-equiv="imagetoolbar" content="no" /><![endif]-->