r104466 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104465‎ | r104466 | r104467 >
Date:18:32, 28 November 2011
Author:maxsem
Status:ok (Comments)
Tags:
Comment:
First batch of CR followup changes: mw.html.element(), scope leak, comments
Modified paths:
  • /trunk/extensions/ApiSandbox/ext.apiSandbox.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js
@@ -26,8 +26,9 @@
2727 var param = this.params[i],
2828 name = this.prefix + param.name;
2929
30 - s += '<tr><td class="api-sandbox-label"><label for="param-' + name + '">' + name + '=</label></td>'
31 - + '<td class="api-sandbox-value">' + this.input( param, name )
 30+ s += '<tr><td class="api-sandbox-label">'
 31+ + mw.html.element( 'label', { 'for': 'param-' + name }, name + '=' )
 32+ + '</td><td class="api-sandbox-value">' + this.input( param, name )
3233 + '</td><td>' + smartEscape( param.description ) + '</td></tr>';
3334 }
3435 s += '\n</tbody>\n</table>\n';
@@ -42,7 +43,7 @@
4344 var desc = smartEscape( this.info.description );
4445 if ( isset( this.info.helpurls ) && isset( this.info.helpurls[0] ) && this.info.helpurls[0] ) {
4546 desc = desc.replace( /^([^\r\n\.]*)/,
46 - '<a target="_blank" href="' + mw.html.escape( this.info.helpurls[0] ) + '">$1</a>'
 47+ mw.html.element( 'a', { 'target': '_blank', 'href': this.info.helpurls[0] }, '$1' )
4748 );
4849 }
4950 $container.html( desc );
@@ -58,12 +59,12 @@
5960 case 'timestamp':
6061 case 'integer':
6162 case 'string':
62 - s = '<input class="api-sandbox-input" id="param-' + name + '" value="' + value + '"/>';
 63+ s = mw.html.element( 'input', { 'class': 'api-sandbox-input', 'id': 'param-' + name, 'value': value } );
6364 break;
6465 case 'bool':
6566 param.type = 'boolean'; // normalisation for later use
6667 case 'boolean':
67 - s = '<input id="param-' + name + '" type="checkbox"/>';
 68+ s = mw.html.element( 'input', { 'id': 'param-' + name, 'type': 'checkbox' } );
6869 break;
6970 case 'namespace':
7071 param.type = namespaces;
@@ -78,7 +79,7 @@
7980 s = this.select( param.type, attributes, true );
8081 }
8182 } else {
82 - s = mw.html.element( 'code', [], mw.msg( 'parentheses', param.type ) );
 83+ s = mw.html.element( 'code', {}, mw.msg( 'parentheses', param.type ) );
8384 }
8485 }
8586 return s;
@@ -127,7 +128,7 @@
128129 if ( $.isArray( value ) ) {
129130 value = value.join( '|' );
130131 }
131 - params += '&' + name + '=' + encodeURIComponent( value );
 132+ params += '&' + encodeURIComponent( name ) + '=' + encodeURIComponent( value );
132133 }
133134 }
134135 return params;
@@ -357,7 +358,7 @@
358359 return;
359360 }
360361 query = query.replace( /^.*=/, '' );
361 - data = {};
 362+ var data = {};
362363 if (isQuery ) {
363364 data.querymodules = query;
364365 } else {
@@ -395,8 +396,9 @@
396397 function smartEscape( s ) {
397398 s = mw.html.escape( s );
398399 if ( s.indexOf( '\n ' ) >= 0 ) {
399 - s = s.replace( /^(.*?)((?:\n\s+\*?[^\n]*)+)(.*?)$/m, '$1<ul>$2</ul>$3' );
400 - s = s.replace( /\n\s+\*?([^\n]*)/g, '\n<li>$1</li>' );
 400+ // turns *-bulleted list into a HTML list
 401+ s = s.replace( /^(.*?)((?:\n\s+\*?[^\n]*)+)(.*?)$/m, '$1<ul>$2</ul>$3' ); // outer tags
 402+ s = s.replace( /\n\s+\*?([^\n]*)/g, '\n<li>$1</li>' ); // <li> around bulleted lines
401403 }
402404 s = s.replace( /\n(?!<)/, '\n<br/>' );
403405 return s;
@@ -426,4 +428,4 @@
427429 $generatorBox.hide();
428430 }
429431
430 -});
\ No newline at end of file
 432+});

Comments

#Comment by Brion VIBBER (talk | contribs)   15:45, 30 November 2011

Looking good! Main high-prio thing I'd still recommend is bumping 'query' to the top of the actions list, so casual explorers will find it first.

Status & tagging log