From: Aryeh Gregor Date: Mon, 10 Aug 2009 02:06:19 +0000 (+0000) Subject: Remove extraneous type="" for CSS/JS in HTML 5 X-Git-Tag: 1.31.0-rc.0~40395 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%7B%7B%20url_for%28%27admin_users%27%29%20%7D%7D?a=commitdiff_plain;h=74519a7f56331adaec641add8b5db024d5eca5bb;p=lhc%2Fweb%2Fwiklou.git Remove extraneous type="" for CSS/JS in HTML 5 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. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c311be2419..beefaf1ae2 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 7c51381bf9..29adb4a9af 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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 \n"; + global $wgJsMimeType, $wgHtml5; + $this->mScripts .= "\t\t/**/\n"; } function getScript() { @@ -1940,8 +1935,24 @@ class OutputPage { return "\t" . implode( "\n\t", $links ); } + /** + * Return a 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; } diff --git a/includes/Skin.php b/includes/Skin.php index e64cedf28a..09460c9aea 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -333,9 +333,10 @@ class Skin extends Linker { } static function makeVariablesScript( $data ) { - global $wgJsMimeType; + global $wgJsMimeType, $wgHtml5; - $r = array( "