Another go at extension CSS order
authorAaron Schulz <aaron@users.mediawiki.org>
Sun, 10 Aug 2008 07:14:08 +0000 (07:14 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sun, 10 Aug 2008 07:14:08 +0000 (07:14 +0000)
includes/OutputPage.php
includes/Skin.php
includes/SkinTemplate.php

index e985cb7..9fcac1b 100644 (file)
@@ -7,6 +7,7 @@ if ( ! defined( 'MEDIAWIKI' ) )
  */
 class OutputPage {
        var $mMetatags = array(), $mKeywords = array(), $mLinktags = array();
+       var $mExtStyles = array();
        var $mPagetitle = '', $mBodytext = '', $mDebugtext = '';
        var $mHTMLtitle = '', $mIsarticle = true, $mPrintable = false;
        var $mSubtitle = '', $mRedirect = '', $mStatusCode;
@@ -76,6 +77,11 @@ class OutputPage {
                                        'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion,
                                        'type' => 'text/css' ) );
        }
+       
+       function addExtensionStyle( $url ) {
+               $linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
+               array_push( $this->mExtStyles, $linkarr );
+       }
 
        /**
         * Add a JavaScript file out of skins/common, or a given relative path.
@@ -88,7 +94,6 @@ class OutputPage {
                } else {
                        $path =  "{$wgStylePath}/common/{$file}";
                }
-               $encPath = htmlspecialchars( $path );
                $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$path?$wgStyleVersion\"></script>\n" );
        }
        
@@ -129,6 +134,11 @@ class OutputPage {
                # $linkarr should be an associative array of attributes. We'll escape on output.
                array_push( $this->mLinktags, $linkarr );
        }
+       
+       # Get all links added by extensions
+       function getExtStyle() {
+               return $this->mExtStyles;
+       }
 
        function addMetadataLink( $linkarr ) {
                # note: buggy CC software only reads first "meta" link
@@ -1409,8 +1419,13 @@ class OutputPage {
                $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
 
                $sk = $wgUser->getSkin();
+               // Load order here is key
                $ret .= $sk->getHeadScripts( $this->mAllowUserJs );
                $ret .= $this->mScripts;
+               $ret .= $sk->getSiteStyles();
+               foreach( $this->mExtStyles as $tag ) {
+                       $ret .= Xml::element( 'link', $tag ) . "\n";
+               }
                $ret .= $sk->getUserStyles();
                $ret .= $this->getHeadItems();
 
index f13b75a..39d5c57 100644 (file)
@@ -434,21 +434,30 @@ class Skin extends Linker {
                        $wgRequest->getVal( 'wpEditToken' ) );
        }
 
-       # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
-       function getUserStylesheet() {
-               global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
+       /**
+        * Get the site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
+        */
+       function getSiteStylesheet() {
+               global $wgStylePath, $wgContLang, $wgStyleVersion;
                $sheet = $this->getStylesheet();
                $s = "@import \"$wgStylePath/common/shared.css?$wgStyleVersion\";\n";
                $s .= "@import \"$wgStylePath/common/oldshared.css?$wgStyleVersion\";\n";
                $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
-               if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
+               if( $wgContLang->isRTL() )
+                       $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
+               return "$s\n";
+       }
 
+       /**
+        * Get the user-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
+        */
+       function getUserStylesheet() {
+               global $wgContLang, $wgSquidMaxage, $wgStyleVersion;
                $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
-               $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
-                       '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
-
+               $s = '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n";
+               $s .= '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
                $s .= $this->doGetUserStyles();
-               return $s."\n";
+               return "$s\n";
        }
 
        /**
@@ -478,6 +487,18 @@ class Skin extends Linker {
                return $s;
        }
 
+       /**
+        * Return html code that include site stylesheets
+        */
+       function getSiteStyles() {
+               $s = "<style type='text/css'>\n";
+               $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
+               $s .= $this->getSiteStylesheet();
+               $s .= "/*]]>*/ /* */\n";
+               $s .= "</style>\n";
+               return $s;
+       }
+       
        /**
         * Return html code that include User stylesheets
         */
index 89b0f69..d1b2af6 100644 (file)
@@ -182,7 +182,7 @@ class SkinTemplate extends Skin {
                }
 
                $this->usercss =  $this->userjs = $this->userjsprev = false;
-               $this->setupUserCss();
+               $this->setupUserCss( $out->getExtStyle() );
                $this->setupUserJs( $out->isUserJsAllowed() );
                $this->titletxt = $this->mTitle->getPrefixedText();
                wfProfileOut( __METHOD__."-stuff" );
@@ -966,7 +966,7 @@ class SkinTemplate extends Skin {
        /**
         * @private
         */
-       function setupUserCss() {
+       function setupUserCss( $extCSS = array() ) {
                global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
 
                wfProfileIn( __METHOD__ );
@@ -981,6 +981,11 @@ class SkinTemplate extends Skin {
                        $siteargs['smaxage'] = '0';
                        $siteargs['ts'] = $wgUser->mTouched;
                }
+               
+               // Add any extension CSS
+               foreach( $extCSS as $tag ) {
+                       $this->addStyle( $tag['href'] );
+               }
 
                // If we use the site's dynamic CSS, throw that in, too
                // Per-site custom styles