r104753 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104752‎ | r104753 | r104754 >
Date:21:27, 30 November 2011
Author:reedy
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/REL1_18/phase3 (modified) (history)
  • /branches/REL1_18/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/resources/mediawiki/mediawiki.js
@@ -1133,9 +1133,17 @@
11341134 * Returns <div><img src="&lt;"/></div>
11351135 */
11361136 this.element = function( name, attrs, contents ) {
1137 - var s = '<' + name;
 1137+ var v, s = '<' + name;
11381138 for ( var attrName in attrs ) {
1139 - s += ' ' + attrName + '="' + this.escape( attrs[attrName] ) + '"';
 1139+ v = attrs[attrName];
 1140+ // Convert name=true, to name=name
 1141+ if ( v === true ) {
 1142+ v = attrName;
 1143+ // Skip name=false
 1144+ } else if ( v === false ) {
 1145+ continue;
 1146+ }
 1147+ s += ' ' + attrName + '="' + this.escape( '' + v ) + '"';
11401148 }
11411149 if ( contents === undefined || contents === null ) {
11421150 // Self close tag
@@ -1144,20 +1152,29 @@
11451153 }
11461154 // Regular open tag
11471155 s += '>';
1148 - if ( typeof contents === 'string' ) {
1149 - // Escaped
1150 - s += this.escape( contents );
1151 - } else if ( contents instanceof this.Raw ) {
1152 - // Raw HTML inclusion
1153 - s += contents.value;
1154 - } else if ( contents instanceof this.Cdata ) {
1155 - // CDATA
1156 - if ( /<\/[a-zA-z]/.test( contents.value ) ) {
1157 - throw new Error( 'mw.html.element: Illegal end tag found in CDATA' );
1158 - }
1159 - s += contents.value;
1160 - } else {
1161 - throw new Error( 'mw.html.element: Invalid type of contents' );
 1156+ switch ( typeof contents ) {
 1157+ case 'string':
 1158+ // Escaped
 1159+ s += this.escape( contents );
 1160+ break;
 1161+ case 'number':
 1162+ case 'boolean':
 1163+ // Convert to string
 1164+ s += '' + contents;
 1165+ break;
 1166+ default:
 1167+ if ( contents instanceof this.Raw ) {
 1168+ // Raw HTML inclusion
 1169+ s += contents.value;
 1170+ } else if ( contents instanceof this.Cdata ) {
 1171+ // CDATA
 1172+ if ( /<\/[a-zA-z]/.test( contents.value ) ) {
 1173+ throw new Error( 'mw.html.element: Illegal end tag found in CDATA' );
 1174+ }
 1175+ s += contents.value;
 1176+ } else {
 1177+ throw new Error( 'mw.html.element: Invalid type of contents' );
 1178+ }
11621179 }
11631180 s += '</' + name + '>';
11641181 return s;
Property changes on: branches/REL1_18/phase3
___________________________________________________________________
Modified: svn:mergeinfo
11651182 Merged /trunk/phase3:r96307,96310

Follow-up revisions

RevisionCommit summaryAuthorDate
r1047541.18wmf1 Merge r104753reedy21:29, 30 November 2011
r104785release-notes for r104753...krinkle23:31, 30 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96307mediawiki.html: mediawiki.html: Add support for numbers and booleans...krinkle21:51, 5 September 2011
r96310mediawiki.html: Attribute values may also be numbers (rather than boolean or ...krinkle23:10, 5 September 2011

Status & tagging log