Index: trunk/extensions/ApiSandbox/SpecialApiSandbox.php |
— | — | @@ -25,16 +25,28 @@ |
26 | 26 | $this->setHeaders(); |
27 | 27 | $out->addModules( 'ext.apiSandbox' ); |
28 | 28 | |
29 | | - $out->addHTML( '<noscript>' . wfMessage( 'apisb-no-js' )->escaped() . '</noscript> |
| 29 | + $out->addHTML( '<noscript>' . wfMessage( 'apisb-no-js' )->parse() . '</noscript> |
30 | 30 | <div id="api-sandbox-content" style="display: none">' ); |
31 | 31 | $out->addWikiMsg( 'apisb-intro' ); |
32 | | - $out->addHTML( $this->openFieldset( 'parameters' ) |
33 | | - . $this->getInputs() . ' |
34 | | -</fieldset> |
35 | | -' . $this->openFieldset( 'result' ) . ' |
36 | | -</fieldset>' ); |
| 32 | + $out->addHTML( $this->openFieldset( 'parameters' ) |
| 33 | + . $this->getInputs() |
| 34 | + . '</fieldset>' |
| 35 | + . $this->openFieldset( 'result' ) |
| 36 | + . '<table class="api-sandbox-result-container"><tbody> |
| 37 | +' |
| 38 | + . '<tr><td class="api-sandbox-result-label"><label for="api-sandbox-url">' |
| 39 | + . wfMessage( 'apisb-request-url' )->parse() . '</label></td>' |
| 40 | + . '<td><input id="api-sandbox-url" readonly="readonly" /></td></tr> |
| 41 | +' |
| 42 | + . '<tr id="api-sandbox-post-row"><td class="api-sandbox-result-label"><label for="api-sandbox-post">' |
| 43 | + . wfMessage( 'apisb-request-post' )->parse() . '</label></td>' |
| 44 | + . '<td><input id="api-sandbox-post" readonly="readonly" /></td></tr> |
| 45 | +' |
| 46 | + . '<tr><td colspan="2"><div id="api-sandbox-output"></div></td></tr>' |
| 47 | + . "\n</tbody></table>" |
| 48 | + . "\n</fieldset>" ); |
37 | 49 | |
38 | | - $out->addHTML( '</div>' ); # <div id="api-sandbox-content"> |
| 50 | + $out->addHTML( "\n</div>" ); # <div id="api-sandbox-content"> |
39 | 51 | } |
40 | 52 | |
41 | 53 | private function getInputs() { |
— | — | @@ -46,9 +58,11 @@ |
47 | 59 | $s = '<table class="api-sandbox-options"> |
48 | 60 | <tbody> |
49 | 61 | <tr><td class="api-sandbox-label"><label for="api-sandbox-action">action=</label></td><td class="api-sandbox-value">' |
50 | | - . $this->getSelect( 'action', $apiMain->getModules() ) . '</td><td id="api-sandbox-help" rowspan="2"></td></tr> |
| 62 | + . $this->getSelect( 'action', $apiMain->getModules() ) |
| 63 | + . '</td><td id="api-sandbox-help" rowspan="2"></td></tr> |
51 | 64 | '; |
52 | | - $s .= '<tr id="api-sandbox-prop-row" style="display: none"><td class="api-sandbox-label"><label for="api-sandbox-prop">prop=</label></td><td class="api-sandbox-value">' |
| 65 | + $s .= '<tr id="api-sandbox-prop-row" style="display: none"><td class="api-sandbox-label">' |
| 66 | + . '<label for="api-sandbox-prop">prop=</label></td><td class="api-sandbox-value">' |
53 | 67 | . $this->getSelect( 'prop', $apiQuery->getModules() ) |
54 | 68 | . '</td></tr> |
55 | 69 | </table> |
— | — | @@ -61,14 +75,18 @@ |
62 | 76 | 'value' => wfMessage( 'apisb-submit' )->text(), |
63 | 77 | 'disabled' => 'disabled', |
64 | 78 | ) |
65 | | - ); |
| 79 | + ) . "\n"; |
66 | 80 | return $s; |
67 | 81 | } |
68 | 82 | |
69 | 83 | private function getSelect( $name, $items ) { |
70 | 84 | $items = array_keys( $items ); |
71 | 85 | sort( $items ); |
72 | | - $s = Html::openElement( 'select', array( 'class' => 'api-sandbox-input', 'name' => $name, 'id' => "api-sandbox-$name" ) ); |
| 86 | + $s = Html::openElement( 'select', array( |
| 87 | + 'class' => 'api-sandbox-input', |
| 88 | + 'name' => $name, |
| 89 | + 'id' => "api-sandbox-$name" ) |
| 90 | + ); |
73 | 91 | $s .= "\n\t" . Html::element( 'option', |
74 | 92 | array( 'value' => '-', 'selected' => 'selected' ), |
75 | 93 | wfMessage( "apisb-select-$name" )->text() |
Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js |
— | — | @@ -11,12 +11,18 @@ |
12 | 12 | var help = $( '#api-sandbox-help' ); |
13 | 13 | var further = $( '#api-sandbox-further-inputs' ); |
14 | 14 | var submit = $( '#api-sandbox-submit' ); |
| 15 | + var requestUrl = $( '#api-sandbox-url' ); |
| 16 | + var requestPost = $( '#api-sandbox-post' ); |
| 17 | + var output = $( '#api-sandbox-output' ); |
| 18 | + var postRow = $( '#api-sandbox-post-row' ); |
15 | 19 | var actionCache = []; |
16 | 20 | var propCache = []; |
17 | 21 | var namespaces = []; |
| 22 | + var currentInfo = {}; |
| 23 | + var apiPhp = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api' + mw.config.get( 'wgScriptExtension' ); |
18 | 24 | |
19 | 25 | // load namespaces |
20 | | - $.getJSON( mw.config.get( 'wgScriptPath' ) + '/api' + mw.config.get( 'wgScriptExtension' ), |
| 26 | + $.getJSON( apiPhp, |
21 | 27 | { format: 'json', action: 'query', meta: 'siteinfo', siprop: 'namespaces' }, |
22 | 28 | function( data ) { |
23 | 29 | if ( isset( data.query ) && isset( data.query.namespaces ) ) { |
— | — | @@ -36,6 +42,59 @@ |
37 | 43 | } |
38 | 44 | ); |
39 | 45 | |
| 46 | + action.change( updateBasics ); |
| 47 | + prop.change( updateBasics ); |
| 48 | + |
| 49 | + submit.click( function() { |
| 50 | + var url = apiPhp + '?action=' + action.val(); |
| 51 | + if ( action.val() == 'query' ) { |
| 52 | + url += '&prop=' + prop.val(); |
| 53 | + } |
| 54 | + url += '&format=json'; // @todo: |
| 55 | + var params = ''; |
| 56 | + for ( var i = 0; i < currentInfo.parameters.length; i++ ) { |
| 57 | + var param = currentInfo.parameters[i]; |
| 58 | + var name = currentInfo.prefix + param.name; |
| 59 | + var value = $( '#param-' + name ).val(); |
| 60 | + if ( param.value == '' |
| 61 | + && ( param.type != 'boolean' && param.type != 'bool' ) |
| 62 | + && !isset( param.required ) ) |
| 63 | + { |
| 64 | + value = null; |
| 65 | + } |
| 66 | + if ( typeof value != 'undefined' ) { |
| 67 | + params += '&' + name + '=' + encodeURIComponent( value ); |
| 68 | + } |
| 69 | + } |
| 70 | + showLoading( output ); |
| 71 | + if ( isset( currentInfo.mustbeposted ) ) { |
| 72 | + requestUrl.val( url ); |
| 73 | + requestPost.val( params ); |
| 74 | + postRow.show(); |
| 75 | + } else { |
| 76 | + requestUrl.val( url + params ); |
| 77 | + postRow.hide(); |
| 78 | + } |
| 79 | + url = url.replace( /(&format=[^&]+)/, '$1fm' ); |
| 80 | + var data = { |
| 81 | + url: url, |
| 82 | + data: params, |
| 83 | + dataType: 'text', |
| 84 | + type: isset( currentInfo.mustbeposted ) ? 'POST' : 'GET', |
| 85 | + success: function( data ) { |
| 86 | + data = data.match( /<pre>[\s\S]*<\/pre>/ )[0]; |
| 87 | + output.html( data ); |
| 88 | + }, |
| 89 | + error: function( jqXHR, textStatus, errorThrown ) { |
| 90 | + output.text( 'FAIL' ); |
| 91 | + } |
| 92 | + }; |
| 93 | + $.ajax( data ); |
| 94 | + }); |
| 95 | + |
| 96 | + /** |
| 97 | + * Shamelessly borrowed from PHP |
| 98 | + */ |
40 | 99 | function isset( x ) { |
41 | 100 | return typeof x != 'undefined'; |
42 | 101 | } |
— | — | @@ -83,7 +142,7 @@ |
84 | 143 | showLoading( further ); |
85 | 144 | var data = { |
86 | 145 | format: 'json', |
87 | | - action: 'paraminfo', |
| 146 | + action: 'paraminfo' |
88 | 147 | }; |
89 | 148 | if (isQuery ) { |
90 | 149 | data.querymodules = prop; |
— | — | @@ -113,6 +172,7 @@ |
114 | 173 | } |
115 | 174 | |
116 | 175 | function createInputs( info ) { |
| 176 | + currentInfo = info; |
117 | 177 | help.html( smartEscape( info.description ) ); |
118 | 178 | var s = '<table class="api-sandbox-options">\n<tbody>'; |
119 | 179 | for ( var i = 0; i < info.parameters.length; i++ ) { |
— | — | @@ -128,7 +188,7 @@ |
129 | 189 | } |
130 | 190 | |
131 | 191 | function input( param, name ) { |
132 | | - var s = param.type; |
| 192 | + var s; |
133 | 193 | var value = ''; |
134 | 194 | switch ( param.type ) { |
135 | 195 | case 'limit': |
— | — | @@ -155,7 +215,9 @@ |
156 | 216 | } else { |
157 | 217 | s = select( param.type, attributes, true ); |
158 | 218 | } |
159 | | - } |
| 219 | + } else { |
| 220 | + s = mw.html.element( 'code', [], mw.msg( 'parentheses', param.type ) ); |
| 221 | + } |
160 | 222 | } |
161 | 223 | return s; |
162 | 224 | } |
— | — | @@ -199,8 +261,4 @@ |
200 | 262 | getQueryInfo( a, p ); |
201 | 263 | } |
202 | 264 | |
203 | | - action.change( updateBasics ); |
204 | | - prop.change( updateBasics ); |
205 | | - |
206 | | - |
207 | 265 | }); |
\ No newline at end of file |
Index: trunk/extensions/ApiSandbox/ApiSandbox.i18n.php |
— | — | @@ -10,6 +10,8 @@ |
11 | 11 | 'apisb-api-disabled' => 'API is disabled on this site.', |
12 | 12 | 'apisb-parameters' => 'Parameters', |
13 | 13 | 'apisb-result' => 'Result', |
| 14 | + 'apisb-request-url' => 'Request URL:', |
| 15 | + 'apisb-request-post' => 'POST data:', |
14 | 16 | 'apisb-select-action' => 'Select action', |
15 | 17 | 'apisb-select-prop' => 'Select property', |
16 | 18 | 'apisb-select-value' => 'Select value', |
Index: trunk/extensions/ApiSandbox/ApiSandbox.php |
— | — | @@ -33,5 +33,7 @@ |
34 | 34 | 'apisb-load-error', |
35 | 35 | 'apisb-select-value', |
36 | 36 | 'apisb-namespaces-error', |
37 | | - 'apisb-ns-main' ), |
| 37 | + 'apisb-ns-main', |
| 38 | + 'parentheses', |
| 39 | + ), |
38 | 40 | ); |
Index: trunk/extensions/ApiSandbox/ext.apiSandbox.css |
— | — | @@ -9,12 +9,30 @@ |
10 | 10 | font-family: monospace; |
11 | 11 | } |
12 | 12 | |
| 13 | +td.api-sandbox-result-label { |
| 14 | + width: 12em; |
| 15 | +} |
| 16 | + |
13 | 17 | td.api-sandbox-value { |
14 | 18 | width: 18em; |
15 | 19 | vertical-align: top; |
16 | 20 | overflow: auto; |
17 | 21 | } |
18 | 22 | |
19 | | -.api-sandbox-input { |
| 23 | +table.api-sandbox-result-container { |
| 24 | + width: 100%; |
| 25 | +} |
| 26 | + |
| 27 | +#api-sandbox-input { |
20 | 28 | width: 17em; |
21 | | -} |
\ No newline at end of file |
| 29 | +} |
| 30 | + |
| 31 | +#api-sandbox-url, #api-sandbox-post { |
| 32 | + width: 100%; |
| 33 | +} |
| 34 | + |
| 35 | +#api-sandbox-output { |
| 36 | + width: 100%; |
| 37 | + height: 15em; |
| 38 | + overflow: scroll; |
| 39 | +} |