r86975 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86974‎ | r86975 | r86976 >
Date:19:25, 26 April 2011
Author:maxsem
Status:ok
Tags:
Comment:
Support for types 'timestamp' and 'namespace'
Modified paths:
  • /trunk/extensions/ApiSandbox/ApiSandbox.i18n.php (modified) (history)
  • /trunk/extensions/ApiSandbox/ApiSandbox.php (modified) (history)
  • /trunk/extensions/ApiSandbox/ext.apiSandbox.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js
@@ -12,7 +12,26 @@
1313 var further = $( '#api-sandbox-further-inputs' );
1414 var actionCache = [];
1515 var propCache = [];
 16+ var namespaces = [];
1617
 18+ // load namespaces
 19+ $.getJSON( mw.config.get( 'wgScriptPath' ) + '/api' + mw.config.get( 'wgScriptExtension' ),
 20+ { format: 'json', action: 'query', meta: 'siteinfo', siprop: 'namespaces' },
 21+ function( data ) {
 22+ if ( isset( data.query ) && isset( data.query.namespaces ) ) {
 23+ for ( var id in data.query.namespaces ) {
 24+ var ns = data.query.namespaces[id]['*'];
 25+ if ( ns == '' ) {
 26+ ns = mw.msg( 'apisb-ns-main' );
 27+ }
 28+ namespaces.push( { key: id, value: ns } );
 29+ }
 30+ } else {
 31+ showLoadError( further, 'apisb-namespaces-error' );
 32+ }
 33+ }
 34+ );
 35+
1736 function isset( x ) {
1837 return typeof x != 'undefined';
1938 }
@@ -21,8 +40,8 @@
2241 element.html( mw.msg( 'apisb-loading' ) ); // @todo:
2342 }
2443
25 - function showLoadError( element ) {
26 - element.html( '<span style="error">' + mw.msg( 'apisb-load-error' ) + '</span>' );
 44+ function showLoadError( element, message ) {
 45+ element.html( mw.html.element( 'span', { 'class': 'error' }, mw.msg( message ) ) );
2746 }
2847
2948 function parseParamInfo( data ) {
@@ -31,7 +50,7 @@
3251 || ( !isset( data.paraminfo.modules ) && !isset( data.paraminfo.querymodules ) )
3352 )
3453 {
35 - showLoadError( further );
 54+ showLoadError( further, 'apisb-load-error' );
3655 return;
3756 }
3857 if ( isset( data.paraminfo.modules ) ) {
@@ -41,7 +60,6 @@
4261 propCache[data.paraminfo.querymodules[0].name] = data.paraminfo.querymodules[0];
4362 createInputs( propCache[data.paraminfo.querymodules[0].name] );
4463 }
45 -
4664 }
4765
4866 function getQueryInfo( action, prop ) {
@@ -107,15 +125,18 @@
108126 switch ( param.type ) {
109127 case 'limit':
110128 value = 10;
 129+ case 'user':
 130+ case 'timestamp':
111131 case 'integer':
112132 case 'string':
113 - case 'user':
114133 s = '<input class="api-sandbox-input" id="param-' + name + '" value="' + value + '"/>';
115134 break;
116135 case 'bool':
117136 case 'boolean':
118137 s = '<input id="param-' + name + '" type="checkbox"/>';
119138 break;
 139+ case 'namespace':
 140+ param.type = namespaces;
120141 default:
121142 if ( typeof param.type == 'object' ) {
122143 var id = 'param-' + name;
@@ -144,11 +165,13 @@
145166 selected = [];
146167 }
147168 for ( var i = 0; i < values.length; i++ ) {
148 - var attrs = { value: values[i] };
149 - if ( $.inArray( values[i], selected ) >= 0 ) {
 169+ var value = typeof values[i] == 'object' ? values[i].key : values[i];
 170+ var face = typeof values[i] == 'object' ? values[i].value : values[i];
 171+ var attrs = { 'value': value };
 172+ if ( $.inArray( value, selected ) >= 0 ) {
150173 attrs.selected = 'selected';
151174 }
152 - s += '\n' + mw.html.element( 'option', attrs, values[i] );
 175+ s += '\n' + mw.html.element( 'option', attrs, face );
153176 }
154177 s = mw.html.element( 'select', attributes, new mw.html.Raw( s ) );
155178 return s;
Index: trunk/extensions/ApiSandbox/ApiSandbox.i18n.php
@@ -15,4 +15,6 @@
1616 'apisb-select-value' => 'Select value',
1717 'apisb-loading' => 'Loading...',
1818 'apisb-load-error' => 'Error loading API description',
 19+ 'apisb-namespaces-error' => 'Error loading namespaces',
 20+ 'apisb-ns-main' => '(Main)',
1921 );
\ No newline at end of file
Index: trunk/extensions/ApiSandbox/ApiSandbox.php
@@ -28,5 +28,10 @@
2929 'styles' => 'ext.apiSandbox.css',
3030 'localBasePath' => dirname( __FILE__ ),
3131 'remoteExtPath' => 'ApiSandbox',
32 - 'messages' => array( 'apisb-loading', 'apisb-load-error', 'apisb-select-value' ),
 32+ 'messages' => array(
 33+ 'apisb-loading',
 34+ 'apisb-load-error',
 35+ 'apisb-select-value',
 36+ 'apisb-namespaces-error',
 37+ 'apisb-ns-main' ),
3338 );

Status & tagging log