Remove extraneous type="" for CSS/JS in HTML 5
authorAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 10 Aug 2009 02:06:19 +0000 (02:06 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 10 Aug 2009 02:06:19 +0000 (02:06 +0000)
Removed in a bunch of places, but of course there are zillions left!
This is one of the things that would be a lot easier if we could just
drop support for non-HTML 5 output.

RELEASE-NOTES
includes/OutputPage.php
includes/Skin.php

index c311be2..beefaf1 100644 (file)
@@ -198,6 +198,7 @@ this. Was used when mwEmbed was going to be an extension.
    numbers outside the permitted ranges), etc.
 ** The summary attribute has been removed from tables of contents.  summary is
    obsolete in HTML 5 and wasn't useful here anyway.
+** Remove unnecessary type="" for CSS/JS in HTML 5 output
 * New hook SpecialRandomBeforeSQL allows extensions to modify or replace the SQL
   query used in Special:Random and subclasses, deprecating the $wgExtraRandompageSQL
   config variable
index 7c51381..29adb4a 100644 (file)
@@ -109,7 +109,12 @@ class OutputPage {
         *             addStyle() and draws from the /skins folder.
         */
        public function addExtensionStyle( $url ) {
-               $linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
+               global $wgHtml5;
+               $linkarr = array( 'rel' => 'stylesheet', 'href' => $url );
+               if ( !$wgHtml5 ) {
+                       # type attribute is mandatory in XHTML 1.0 Transitional
+                       $linkarr['type'] = 'text/css';
+               }
                array_push( $this->mExtStyles, $linkarr );
        }
 
@@ -118,7 +123,7 @@ class OutputPage {
         * @param string $file filename in skins/common or complete on-server path (/foo/bar.js)
         */
        function addScriptFile( $file ) {
-               global $wgStylePath, $wgStyleVersion, $wgJsMimeType, $wgScript, $wgUser;
+               global $wgStylePath, $wgStyleVersion, $wgJsMimeType, $wgScript, $wgUser, $wgHtml5;
                global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgEnableScriptLoader, $wgScriptPath;
 
                if( substr( $file, 0, 1 ) == '/' ) {
@@ -163,15 +168,11 @@ class OutputPage {
                }
 
                // if the script loader did not find a way to add the script than add using addScript
-               $this->addScript(
-                       Xml::element( 'script',
-                               array(
-                                       'type' => $wgJsMimeType,
-                                       'src' => wfAppendQuery( $path, $this->getURIDparam() ),
-                               ),
-                               '', false
-                       )
-               );
+               $attrs = array( 'src' => wfAppendQuery( $path, $this->getURIDparam() ) );
+               if ( !$wgHtml5 ) {
+                       $attrs['type'] = $wgJsMimeType;
+               }
+               $this->addScript( Xml::element( 'script', $attrs, '', false ) );
        }
 
        /**
@@ -180,7 +181,8 @@ class OutputPage {
         *  different page load types (edit, upload, view, etc)
         */
        function addCoreScripts2Top(){
-               global $wgEnableScriptLoader, $wgStyleVersion, $wgJSAutoloadLocalClasses, $wgJsMimeType, $wgScriptPath, $wgEnableJS2system;
+               global $wgEnableScriptLoader, $wgStyleVersion, $wgJSAutoloadLocalClasses,
+                       $wgJsMimeType, $wgScriptPath, $wgEnableJS2system, $wgHtml5;
                //@@todo we should deprecate wikibits in favor of mv_embed and native jQuery functions
 
                if( $wgEnableJS2system ){
@@ -195,12 +197,11 @@ class OutputPage {
                        $so = '';
                        foreach( $core_classes as $s ){
                                if( isset( $wgJSAutoloadLocalClasses[$s] ) ){
-                                       $so.= Xml::element( 'script', array(
-                                                       'type' => $wgJsMimeType,
-                                                       'src' => "{$wgScriptPath}/{$wgJSAutoloadLocalClasses[$s]}?" . $this->getURIDparam()
-                                               ),
-                                               '', false
-                                       );
+                                       $attrs = array( 'src' => "{$wgScriptPath}/{$wgJSAutoloadLocalClasses[$s]}?" . $this->getURIDparam() );
+                                       if ( !$wgHtml5 ) {
+                                               $attrs['type'] = $wgJsMimeType;
+                                       }
+                                       $so.= Xml::element( 'script', $attrs, '', false );
                                }
                        }
                        $this->mScripts =  $so . $this->mScripts;
@@ -213,7 +214,7 @@ class OutputPage {
         */
        function addScriptClass( $js_class ){
                global $wgDebugJavaScript, $wgJSAutoloadLocalClasses, $wgJSAutoloadClasses,
-                               $wgJsMimeType, $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath;
+                       $wgJsMimeType, $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath, $wgHtml5;
 
                if( isset( $wgJSAutoloadClasses[$js_class] ) || isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
                        if( $wgEnableScriptLoader ){
@@ -228,16 +229,12 @@ class OutputPage {
                                }else if( isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
                                        $path.= $wgJSAutoloadLocalClasses[$js_class];
                                }
-                               $urlApend = ( $wgDebugJavaScript) ? time() : $wgStyleVersion;
-                               $this->addScript(
-                                       Xml::element( 'script',
-                                               array(
-                                                       'type' => $wgJsMimeType,
-                                                       'src' => "$path?" . $urlApend,
-                                               ),
-                                               '', false
-                                       )
-                               );
+                               $urlAppend = ( $wgDebugJavaScript) ? time() : $wgStyleVersion;
+                               $attrs = array( 'src' => "$path?$urlAppend" );
+                               if ( !$wgHtml5 ) {
+                                       $attrs['type'] = $wgJsMimeType;
+                               }
+                               $this->addScript( Xml::element( 'script', $attrs, '', false ) );
                        }
                        return true;
                }
@@ -250,7 +247,7 @@ class OutputPage {
         * @param $forcClassAry Boolean: false by default
         */
        function getScriptLoaderJs( $forceClassAry = false ){
-               global $wgJsMimeType, $wgStyleVersion, $wgRequest, $wgDebugJavaScript;
+               global $wgJsMimeType, $wgStyleVersion, $wgRequest, $wgDebugJavaScript, $wgHtml5;
 
                if( !$forceClassAry ){
                        $class_list = implode( ',', $this->mScriptLoaderClassList );
@@ -268,14 +265,11 @@ class OutputPage {
 
                //generate the unique request param (combine with the most recent revision id of any wiki page with the $wgStyleVersion var)
 
-
-               return Xml::element( 'script',
-                               array(
-                                       'type' => $wgJsMimeType,
-                                       'src' => wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&".$this->getURIDparam(),
-                               ),
-                               '', false
-               );
+               $attrs = array( 'src' => wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&".$this->getURIDparam() );
+               if ( !$wgHtml5 ) {
+                       $attrs['type'] = $wgJsMimeType;
+               }
+               return Xml::element( 'script', $attrs, '', false );
        }
 
        function getURIDparam(){
@@ -304,8 +298,9 @@ class OutputPage {
         * @param string $script JavaScript text, no <script> tags
         */
        function addInlineScript( $script ) {
-               global $wgJsMimeType;
-               $this->mScripts .= "\t\t<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n\t\t$script\n\t\t/*]]>*/</script>\n";
+               global $wgJsMimeType, $wgHtml5;
+               $this->mScripts .= "\t\t<script" . ($wgHtml5 ? '' : " type=\"$wgJsMimeType\"")
+                       . ">/*<![CDATA[*/\n\t\t$script\n\t\t/*]]>*/</script>\n";
        }
 
        function getScript() {
@@ -1940,8 +1935,24 @@ class OutputPage {
                return "\t" . implode( "\n\t", $links );
        }
 
+       /**
+        * Return a <link rel="stylesheet"> with the given parameters.
+        *
+        * @param $style string Relative or absolute URL.  If $style begins with
+        *   '/', 'http:', or 'https:' it's used for the href as-is.  Otherwise,
+        *   it's assumed to refer to some file within $wgStylePath, so the URL
+        *   used is "$wgStylePath/$style?$wgStyleVersion".
+        * @param $options array Associative array with the following possible
+        *   keys:
+        *     'dir': 'rtl' or 'ltr'.  If the site language direction doesn't match
+        *       this, the empty string is returned.
+        *     'media': Contents of the media attribute (will be mangled a bit,
+        *       e.g. 'screen' -> 'screen,projection' so Opera fullscreen works)
+        *     'condition': Wrap in an IE conditional comment, e.g., 'lt IE 7'.
+        * @return string Raw HTML
+        */
        protected function styleLink( $style, $options ) {
-               global $wgRequest;
+               global $wgRequest, $wgHtml5;
 
                if( isset( $options['dir'] ) ) {
                        global $wgContLang;
@@ -1970,9 +1981,11 @@ class OutputPage {
 
                $attribs = array(
                        'rel' => 'stylesheet',
-                       'href' => $url,
-                       'type' => 'text/css' );
-               if( $media ) {
+                       'href' => $url );
+               if ( !$wgHtml5 ) {
+                       $attribs['type'] = 'text/css';
+               }
+               if ( $media ) {
                        $attribs['media'] = $media;
                }
 
index e64cedf..09460c9 100644 (file)
@@ -333,9 +333,10 @@ class Skin extends Linker {
        }
 
        static function makeVariablesScript( $data ) {
-               global $wgJsMimeType;
+               global $wgJsMimeType, $wgHtml5;
 
-               $r = array( "<script type=\"$wgJsMimeType\">/*<![CDATA[*/" );
+               $r = array( "<script" . ( $wgHtml5 ? '' : " type=\"$wgJsMimeType\"" )
+                       . ">/*<![CDATA[*/" );
                foreach ( $data as $name => $value ) {
                        $encValue = Xml::encodeJsVar( $value );
                        $r[] = "var $name = $encValue;";