Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js |
— | — | @@ -12,7 +12,26 @@ |
13 | 13 | var further = $( '#api-sandbox-further-inputs' ); |
14 | 14 | var actionCache = []; |
15 | 15 | var propCache = []; |
| 16 | + var namespaces = []; |
16 | 17 | |
| 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 | + |
17 | 36 | function isset( x ) { |
18 | 37 | return typeof x != 'undefined'; |
19 | 38 | } |
— | — | @@ -21,8 +40,8 @@ |
22 | 41 | element.html( mw.msg( 'apisb-loading' ) ); // @todo: |
23 | 42 | } |
24 | 43 | |
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 ) ) ); |
27 | 46 | } |
28 | 47 | |
29 | 48 | function parseParamInfo( data ) { |
— | — | @@ -31,7 +50,7 @@ |
32 | 51 | || ( !isset( data.paraminfo.modules ) && !isset( data.paraminfo.querymodules ) ) |
33 | 52 | ) |
34 | 53 | { |
35 | | - showLoadError( further ); |
| 54 | + showLoadError( further, 'apisb-load-error' ); |
36 | 55 | return; |
37 | 56 | } |
38 | 57 | if ( isset( data.paraminfo.modules ) ) { |
— | — | @@ -41,7 +60,6 @@ |
42 | 61 | propCache[data.paraminfo.querymodules[0].name] = data.paraminfo.querymodules[0]; |
43 | 62 | createInputs( propCache[data.paraminfo.querymodules[0].name] ); |
44 | 63 | } |
45 | | - |
46 | 64 | } |
47 | 65 | |
48 | 66 | function getQueryInfo( action, prop ) { |
— | — | @@ -107,15 +125,18 @@ |
108 | 126 | switch ( param.type ) { |
109 | 127 | case 'limit': |
110 | 128 | value = 10; |
| 129 | + case 'user': |
| 130 | + case 'timestamp': |
111 | 131 | case 'integer': |
112 | 132 | case 'string': |
113 | | - case 'user': |
114 | 133 | s = '<input class="api-sandbox-input" id="param-' + name + '" value="' + value + '"/>'; |
115 | 134 | break; |
116 | 135 | case 'bool': |
117 | 136 | case 'boolean': |
118 | 137 | s = '<input id="param-' + name + '" type="checkbox"/>'; |
119 | 138 | break; |
| 139 | + case 'namespace': |
| 140 | + param.type = namespaces; |
120 | 141 | default: |
121 | 142 | if ( typeof param.type == 'object' ) { |
122 | 143 | var id = 'param-' + name; |
— | — | @@ -144,11 +165,13 @@ |
145 | 166 | selected = []; |
146 | 167 | } |
147 | 168 | 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 ) { |
150 | 173 | attrs.selected = 'selected'; |
151 | 174 | } |
152 | | - s += '\n' + mw.html.element( 'option', attrs, values[i] ); |
| 175 | + s += '\n' + mw.html.element( 'option', attrs, face ); |
153 | 176 | } |
154 | 177 | s = mw.html.element( 'select', attributes, new mw.html.Raw( s ) ); |
155 | 178 | return s; |
Index: trunk/extensions/ApiSandbox/ApiSandbox.i18n.php |
— | — | @@ -15,4 +15,6 @@ |
16 | 16 | 'apisb-select-value' => 'Select value', |
17 | 17 | 'apisb-loading' => 'Loading...', |
18 | 18 | 'apisb-load-error' => 'Error loading API description', |
| 19 | + 'apisb-namespaces-error' => 'Error loading namespaces', |
| 20 | + 'apisb-ns-main' => '(Main)', |
19 | 21 | ); |
\ No newline at end of file |
Index: trunk/extensions/ApiSandbox/ApiSandbox.php |
— | — | @@ -28,5 +28,10 @@ |
29 | 29 | 'styles' => 'ext.apiSandbox.css', |
30 | 30 | 'localBasePath' => dirname( __FILE__ ), |
31 | 31 | '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' ), |
33 | 38 | ); |