r54734 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54733‎ | r54734 | r54735 >
Date:19:23, 10 August 2009
Author:brion
Status:ok
Tags:
Comment:
Reverting r54695 'Remove extraneous type="" for CSS/JS in HTML 5'
This creates massive code duplication, checking a var and either including or not including the type attribute. Instead, this should be consolidated into functions in the Xml class for building <style>, <script>, or <link rel="stylesheet"> elements.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -109,12 +109,7 @@
110110 * addStyle() and draws from the /skins folder.
111111 */
112112 public function addExtensionStyle( $url ) {
113 - global $wgHtml5;
114 - $linkarr = array( 'rel' => 'stylesheet', 'href' => $url );
115 - if ( !$wgHtml5 ) {
116 - # type attribute is mandatory in XHTML 1.0 Transitional
117 - $linkarr['type'] = 'text/css';
118 - }
 113+ $linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
119114 array_push( $this->mExtStyles, $linkarr );
120115 }
121116
@@ -123,7 +118,7 @@
124119 * @param string $file filename in skins/common or complete on-server path (/foo/bar.js)
125120 */
126121 function addScriptFile( $file ) {
127 - global $wgStylePath, $wgStyleVersion, $wgJsMimeType, $wgScript, $wgUser, $wgHtml5;
 122+ global $wgStylePath, $wgStyleVersion, $wgJsMimeType, $wgScript, $wgUser;
128123 global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgEnableScriptLoader, $wgScriptPath;
129124
130125 if( substr( $file, 0, 1 ) == '/' ) {
@@ -168,11 +163,15 @@
169164 }
170165
171166 // if the script loader did not find a way to add the script than add using addScript
172 - $attrs = array( 'src' => wfAppendQuery( $path, $this->getURIDparam() ) );
173 - if ( !$wgHtml5 ) {
174 - $attrs['type'] = $wgJsMimeType;
175 - }
176 - $this->addScript( Xml::element( 'script', $attrs, '', false ) );
 167+ $this->addScript(
 168+ Xml::element( 'script',
 169+ array(
 170+ 'type' => $wgJsMimeType,
 171+ 'src' => wfAppendQuery( $path, $this->getURIDparam() ),
 172+ ),
 173+ '', false
 174+ )
 175+ );
177176 }
178177
179178 /**
@@ -181,8 +180,7 @@
182181 * different page load types (edit, upload, view, etc)
183182 */
184183 function addCoreScripts2Top(){
185 - global $wgEnableScriptLoader, $wgStyleVersion, $wgJSAutoloadLocalClasses,
186 - $wgJsMimeType, $wgScriptPath, $wgEnableJS2system, $wgHtml5;
 184+ global $wgEnableScriptLoader, $wgStyleVersion, $wgJSAutoloadLocalClasses, $wgJsMimeType, $wgScriptPath, $wgEnableJS2system;
187185 //@@todo we should deprecate wikibits in favor of mv_embed and native jQuery functions
188186
189187 if( $wgEnableJS2system ){
@@ -197,11 +195,12 @@
198196 $so = '';
199197 foreach( $core_classes as $s ){
200198 if( isset( $wgJSAutoloadLocalClasses[$s] ) ){
201 - $attrs = array( 'src' => "{$wgScriptPath}/{$wgJSAutoloadLocalClasses[$s]}?" . $this->getURIDparam() );
202 - if ( !$wgHtml5 ) {
203 - $attrs['type'] = $wgJsMimeType;
204 - }
205 - $so.= Xml::element( 'script', $attrs, '', false );
 199+ $so.= Xml::element( 'script', array(
 200+ 'type' => $wgJsMimeType,
 201+ 'src' => "{$wgScriptPath}/{$wgJSAutoloadLocalClasses[$s]}?" . $this->getURIDparam()
 202+ ),
 203+ '', false
 204+ );
206205 }
207206 }
208207 $this->mScripts = $so . $this->mScripts;
@@ -214,7 +213,7 @@
215214 */
216215 function addScriptClass( $js_class ){
217216 global $wgDebugJavaScript, $wgJSAutoloadLocalClasses, $wgJSAutoloadClasses,
218 - $wgJsMimeType, $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath, $wgHtml5;
 217+ $wgJsMimeType, $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath;
219218
220219 if( isset( $wgJSAutoloadClasses[$js_class] ) || isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
221220 if( $wgEnableScriptLoader ){
@@ -229,12 +228,16 @@
230229 }else if( isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
231230 $path.= $wgJSAutoloadLocalClasses[$js_class];
232231 }
233 - $urlAppend = ( $wgDebugJavaScript) ? time() : $wgStyleVersion;
234 - $attrs = array( 'src' => "$path?$urlAppend" );
235 - if ( !$wgHtml5 ) {
236 - $attrs['type'] = $wgJsMimeType;
237 - }
238 - $this->addScript( Xml::element( 'script', $attrs, '', false ) );
 232+ $urlApend = ( $wgDebugJavaScript) ? time() : $wgStyleVersion;
 233+ $this->addScript(
 234+ Xml::element( 'script',
 235+ array(
 236+ 'type' => $wgJsMimeType,
 237+ 'src' => "$path?" . $urlApend,
 238+ ),
 239+ '', false
 240+ )
 241+ );
239242 }
240243 return true;
241244 }
@@ -247,7 +250,7 @@
248251 * @param $forcClassAry Boolean: false by default
249252 */
250253 function getScriptLoaderJs( $forceClassAry = false ){
251 - global $wgJsMimeType, $wgStyleVersion, $wgRequest, $wgDebugJavaScript, $wgHtml5;
 254+ global $wgJsMimeType, $wgStyleVersion, $wgRequest, $wgDebugJavaScript;
252255
253256 if( !$forceClassAry ){
254257 $class_list = implode( ',', $this->mScriptLoaderClassList );
@@ -265,11 +268,14 @@
266269
267270 //generate the unique request param (combine with the most recent revision id of any wiki page with the $wgStyleVersion var)
268271
269 - $attrs = array( 'src' => wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&".$this->getURIDparam() );
270 - if ( !$wgHtml5 ) {
271 - $attrs['type'] = $wgJsMimeType;
272 - }
273 - return Xml::element( 'script', $attrs, '', false );
 272+
 273+ return Xml::element( 'script',
 274+ array(
 275+ 'type' => $wgJsMimeType,
 276+ 'src' => wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&".$this->getURIDparam(),
 277+ ),
 278+ '', false
 279+ );
274280 }
275281
276282 function getURIDparam(){
@@ -298,9 +304,8 @@
299305 * @param string $script JavaScript text, no <script> tags
300306 */
301307 function addInlineScript( $script ) {
302 - global $wgJsMimeType, $wgHtml5;
303 - $this->mScripts .= "\t\t<script" . ($wgHtml5 ? '' : " type=\"$wgJsMimeType\"")
304 - . ">/*<![CDATA[*/\n\t\t$script\n\t\t/*]]>*/</script>\n";
 308+ global $wgJsMimeType;
 309+ $this->mScripts .= "\t\t<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n\t\t$script\n\t\t/*]]>*/</script>\n";
305310 }
306311
307312 function getScript() {
@@ -1935,24 +1940,8 @@
19361941 return "\t" . implode( "\n\t", $links );
19371942 }
19381943
1939 - /**
1940 - * Return a <link rel="stylesheet"> with the given parameters.
1941 - *
1942 - * @param $style string Relative or absolute URL. If $style begins with
1943 - * '/', 'http:', or 'https:' it's used for the href as-is. Otherwise,
1944 - * it's assumed to refer to some file within $wgStylePath, so the URL
1945 - * used is "$wgStylePath/$style?$wgStyleVersion".
1946 - * @param $options array Associative array with the following possible
1947 - * keys:
1948 - * 'dir': 'rtl' or 'ltr'. If the site language direction doesn't match
1949 - * this, the empty string is returned.
1950 - * 'media': Contents of the media attribute (will be mangled a bit,
1951 - * e.g. 'screen' -> 'screen,projection' so Opera fullscreen works)
1952 - * 'condition': Wrap in an IE conditional comment, e.g., 'lt IE 7'.
1953 - * @return string Raw HTML
1954 - */
19551944 protected function styleLink( $style, $options ) {
1956 - global $wgRequest, $wgHtml5;
 1945+ global $wgRequest;
19571946
19581947 if( isset( $options['dir'] ) ) {
19591948 global $wgContLang;
@@ -1981,11 +1970,9 @@
19821971
19831972 $attribs = array(
19841973 'rel' => 'stylesheet',
1985 - 'href' => $url );
1986 - if ( !$wgHtml5 ) {
1987 - $attribs['type'] = 'text/css';
1988 - }
1989 - if ( $media ) {
 1974+ 'href' => $url,
 1975+ 'type' => 'text/css' );
 1976+ if( $media ) {
19901977 $attribs['media'] = $media;
19911978 }
19921979
Index: trunk/phase3/includes/Skin.php
@@ -333,10 +333,9 @@
334334 }
335335
336336 static function makeVariablesScript( $data ) {
337 - global $wgJsMimeType, $wgHtml5;
 337+ global $wgJsMimeType;
338338
339 - $r = array( "<script" . ( $wgHtml5 ? '' : " type=\"$wgJsMimeType\"" )
340 - . ">/*<![CDATA[*/" );
 339+ $r = array( "<script type=\"$wgJsMimeType\">/*<![CDATA[*/" );
341340 foreach ( $data as $name => $value ) {
342341 $encValue = Xml::encodeJsVar( $value );
343342 $r[] = "var $name = $encValue;";
Index: trunk/phase3/RELEASE-NOTES
@@ -198,7 +198,6 @@
199199 numbers outside the permitted ranges), etc.
200200 ** The summary attribute has been removed from tables of contents. summary is
201201 obsolete in HTML 5 and wasn't useful here anyway.
202 -** Remove unnecessary type="" for CSS/JS in HTML 5 output
203202 * New hook SpecialRandomBeforeSQL allows extensions to modify or replace the SQL
204203 query used in Special:Random and subclasses, deprecating the $wgExtraRandompageSQL
205204 config variable

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r54695Remove extraneous type="" for CSS/JS in HTML 5...simetrical02:06, 10 August 2009

Status & tagging log