r55539 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55538‎ | r55539 | r55540 >
Date:21:06, 23 August 2009
Author:simetrical
Status:ok
Tags:
Comment:
Emit CDATA more intelligently

This fixes some possible XML invalidity from r54767: CDATA stuff was
being added only if $wgHtml5 was false, instead of whenever
$wgWellFormedXml is true. Also, it uses CDATA for script as well as
style, but in both cases only uses it if there's a & or < somewhere.
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/Html.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -1,7 +1,6 @@
22 <?php
33
44 class HTMLForm {
5 -
65 static $jsAdded = false;
76
87 /* The descriptor is an array of arrays.
Index: trunk/phase3/includes/Html.php
@@ -256,11 +256,13 @@
257257 * @return string Raw HTML
258258 */
259259 public static function inlineScript( $contents ) {
260 - global $wgHtml5, $wgJsMimeType;
 260+ global $wgHtml5, $wgJsMimeType, $wgWellFormedXml;
261261
262262 $attrs = array();
263263 if ( !$wgHtml5 ) {
264264 $attrs['type'] = $wgJsMimeType;
 265+ }
 266+ if ( $wgWellFormedXml && preg_match( '/[<&]/', $contents ) ) {
265267 $contents = "/*<![CDATA[*/$contents/*]]>*/";
266268 }
267269 return self::rawElement( 'script', $attrs, $contents );
@@ -294,15 +296,15 @@
295297 * @return string Raw HTML
296298 */
297299 public static function inlineStyle( $contents, $media = null ) {
298 - global $wgHtml5;
 300+ global $wgHtml5, $wgWellFormedXml;
299301
300302 $attrs = array();
301303 if ( !$wgHtml5 ) {
302 - # Technically we should probably add CDATA stuff here like with
303 - # scripts, but in practice, stylesheets tend not to have
304 - # problematic characters anyway.
305304 $attrs['type'] = 'text/css';
306305 }
 306+ if ( $wgWellFormedXml && preg_match( '/[<&]/', $contents ) ) {
 307+ $contents = "/*<![CDATA[*/$contents/*]]>*/";
 308+ }
307309 if ( $media !== null ) {
308310 $attrs['media'] = $media;
309311 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r54767For HTML 5, drop type="" attributes for CSS/JS...simetrical00:09, 11 August 2009

Status & tagging log