r86957 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86956‎ | r86957 | r86958 >
Date:17:50, 26 April 2011
Author:maxsem
Status:ok
Tags:
Comment:
Also prettify action's help, handle *-bulleted lists properly
Modified paths:
  • /trunk/extensions/ApiSandbox/ext.apiSandbox.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js
@@ -76,22 +76,26 @@
7777 }
7878 }
7979
 80+ function smartEscape( s ) {
 81+ s = mw.html.escape( s );
 82+ if ( s.indexOf( '\n ' ) >= 0 ) {
 83+ s = s.replace( /^(.*?)((?:\n\s+\*?[^\n]*)+)(.*?)$/m, '$1<ul>$2</ul>$3' );
 84+ s = s.replace( /\n\s+\*?([^\n]*)/g, '\n<li>$1</li>' );
 85+ }
 86+ s = s.replace( /\n(?!<)/, '\n<br/>' );
 87+ return s;
 88+ }
 89+
8090 function createInputs( info ) {
81 - help.text( info.description );
 91+ help.html( smartEscape( info.description ) );
8292 var s = '<table class="api-sandbox-options">\n<tbody>';
8393 for ( var i = 0; i < info.parameters.length; i++ ) {
8494 var param = info.parameters[i];
8595 var name = info.prefix + param.name;
86 - var desc = mw.html.escape( param.description );
87 - if ( desc.indexOf( '\n ' ) >= 0 ) {
88 - desc = desc.replace( /^(.*?)((?:\n\s+[^\n]*)+)(.*?)$/m, '$1<ul>$2</ul>$3' );
89 - desc = desc.replace( /\n\s+([^\n]*)/g, '\n<li>$1</li>' );
90 - }
91 - desc = desc.replace( /\n(?!<)/, '\n<br/>' );
9296
9397 s += '<tr><td class="api-sandbox-label"><label for="param-' + name + '">' + name + '=</label></td>'
9498 + '<td class="api-sandbox-value">' + input( param, name )
95 - + '</td><td>' + desc + '</td></tr>';
 99+ + '</td><td>' + smartEscape( param.description ) + '</td></tr>';
96100 }
97101 s += '\n</tbody>\n</table>\n';
98102 further.html( s );

Status & tagging log