Index: trunk/extensions/ApiSandbox/SpecialApiSandbox.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class SpecialApiSandbox extends SpecialPage { |
5 | | - |
| 5 | + private $apiQuery; |
6 | 6 | /** |
7 | 7 | * Constructor |
8 | 8 | */ |
— | — | @@ -53,24 +53,32 @@ |
54 | 54 | global $wgEnableWriteAPI; |
55 | 55 | |
56 | 56 | $apiMain = new ApiMain( new FauxRequest( array() ), $wgEnableWriteAPI ); |
57 | | - $apiQuery = new ApiQuery( $apiMain, 'query' ); |
58 | | - $formats = array_flip( array_filter( array_keys( $apiMain->getFormats() ), |
59 | | - 'SpecialApiSandbox::filterFormats' ) ); |
| 57 | + $this->apiQuery = new ApiQuery( $apiMain, 'query' ); |
| 58 | + $formats = array_filter( array_keys( $apiMain->getFormats() ), |
| 59 | + 'SpecialApiSandbox::filterFormats' ); |
| 60 | + sort( $formats ); |
| 61 | + $modules = array_keys( $apiMain->getModules() ); |
| 62 | + sort( $modules ); |
| 63 | + $queryModules = array_merge( |
| 64 | + $this->getQueryModules( 'prop' ), |
| 65 | + $this->getQueryModules( 'list' ), |
| 66 | + $this->getQueryModules( 'meta' ) |
| 67 | + ); |
60 | 68 | |
61 | 69 | $s = '<table class="api-sandbox-options"> |
62 | 70 | <tbody> |
63 | 71 | '; |
64 | 72 | $s .= '<tr><td class="api-sandbox-label"><label for="api-sandbox-format">format=</label></td><td class="api-sandbox-value">' |
65 | | - . $this->getSelect( 'format', $formats, 'json' ) |
66 | | - . '</td><td></td></tr> |
| 73 | + . self::getSelect( 'format', $formats, 'json' ) |
| 74 | + . '</td><td></td></tr> |
67 | 75 | '; |
68 | 76 | $s .= '<tr><td class="api-sandbox-label"><label for="api-sandbox-action">action=</label></td><td class="api-sandbox-value">' |
69 | | - . $this->getSelect( 'action', $apiMain->getModules() ) |
70 | | - . '</td><td id="api-sandbox-help" rowspan="2"></td></tr> |
| 77 | + . self::getSelect( 'action', $modules ) |
| 78 | + . '</td><td id="api-sandbox-help" rowspan="2"></td></tr> |
71 | 79 | '; |
72 | | - $s .= '<tr id="api-sandbox-prop-row" style="display: none"><td class="api-sandbox-label">' |
73 | | - . '<label for="api-sandbox-prop">prop=</label></td><td class="api-sandbox-value">' |
74 | | - . $this->getSelect( 'prop', $apiQuery->getModules() ) |
| 80 | + $s .= '<tr id="api-sandbox-query-row" style="display: none"><td class="api-sandbox-label">' |
| 81 | + . '</td><td class="api-sandbox-value">' |
| 82 | + . self::getSelect( 'query', $queryModules ) |
75 | 83 | . '</td></tr> |
76 | 84 | </table> |
77 | 85 | <div id="api-sandbox-further-inputs"></div> |
— | — | @@ -86,35 +94,65 @@ |
87 | 95 | return $s; |
88 | 96 | } |
89 | 97 | |
90 | | - private function getSelect( $name, $items, $default = false ) { |
91 | | - $items = array_keys( $items ); |
92 | | - sort( $items ); |
| 98 | + private function getQueryModules( $type ) { |
| 99 | + $res = array(); |
| 100 | + $params = $this->apiQuery->getAllowedParams(); |
| 101 | + foreach ( $params[$type][ApiBase::PARAM_TYPE] as $module ) { |
| 102 | + $res[] = array( |
| 103 | + 'value' => "$type=$module", |
| 104 | + 'text' => /* */ "\xc2\xa0\xc2\xa0\xc2\xa0$type=$module", |
| 105 | + ); |
| 106 | + } |
| 107 | + sort( $res ); |
| 108 | + array_unshift( $res, |
| 109 | + array( |
| 110 | + 'value' => '-', |
| 111 | + 'text' => wfMessage( "apisb-query-$type" )->parse(), |
| 112 | + 'attributes' => array( 'disabled' => 'disabled' ) |
| 113 | + ) |
| 114 | + ); |
| 115 | + |
| 116 | + return $res; |
| 117 | + } |
| 118 | + |
| 119 | + private static function getSelect( $name, $items, $default = false ) { |
93 | 120 | $s = Html::openElement( 'select', array( |
94 | 121 | 'class' => 'api-sandbox-input', |
95 | 122 | 'name' => $name, |
96 | 123 | 'id' => "api-sandbox-$name" ) |
97 | 124 | ); |
98 | 125 | if ( $default === false ) { |
99 | | - $s .= "\n\t" . Html::element( 'option', |
100 | | - array( 'value' => '-', 'selected' => 'selected' ), |
101 | | - wfMessage( "apisb-select-$name" )->text() |
| 126 | + $s .= "\n\t" . self::option( '-', wfMessage( "apisb-select-$name" )->text(), |
| 127 | + array( 'selected' => 'selected' ) |
102 | 128 | ); |
103 | 129 | } |
104 | 130 | foreach ( $items as $item ) { |
105 | | - $attributes = array( 'value' => $item ); |
106 | | - if ( $item === $default ) { |
| 131 | + $attributes = array(); |
| 132 | + if ( is_array( $item ) ) { |
| 133 | + $value = $item['value']; |
| 134 | + $text = $item['text']; |
| 135 | + $attributes = isset( $item['attributes'] ) ? $item['attributes'] : array(); |
| 136 | + } else { |
| 137 | + $value = $text = $item; |
| 138 | + } |
| 139 | + if ( $value === $default ) { |
107 | 140 | $attributes['selected'] = 'selected'; |
108 | 141 | } |
109 | | - $s .= "\n\t" . Html::element( 'option', $attributes, $item ); |
| 142 | + $s .= "\n\t" . self::option( $value, $text, $attributes ); |
110 | 143 | } |
111 | 144 | $s .= "\n" . Html::closeElement( 'select' ) . "\n"; |
112 | 145 | return $s; |
113 | 146 | } |
114 | 147 | |
| 148 | + private static function option( $value, $text, $attributes = array() ) { |
| 149 | + $attributes['value'] = $value; |
| 150 | + return Html::element( 'option', $attributes, $text ); |
| 151 | + } |
| 152 | + |
115 | 153 | private function openFieldset( $name ) { |
116 | | - return "\n" . Html::openElement( 'fieldset', array( 'id' => "api-sandbox-$name" ) ) |
117 | | - . "\n\t" . Html::rawElement( 'legend', array(), wfMessage( "apisb-$name" )->parse() ) |
118 | | - . "\n"; |
| 154 | + return "\n" . Html::openElement( 'fieldset', array( 'id' => "api-sandbox-$name" ) ) |
| 155 | + . "\n\t" . Html::rawElement( 'legend', array(), wfMessage( "apisb-$name" )->parse() ) |
| 156 | + . "\n"; |
119 | 157 | } |
120 | 158 | |
121 | 159 | /** |
Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js |
— | — | @@ -8,8 +8,8 @@ |
9 | 9 | // page elements |
10 | 10 | var $format = $( '#api-sandbox-format' ), |
11 | 11 | $action = $( '#api-sandbox-action' ), |
12 | | - $prop = $( '#api-sandbox-prop' ), |
13 | | - $propRow = $( '#api-sandbox-prop-row' ), |
| 12 | + $query = $( '#api-sandbox-query' ), |
| 13 | + $queryRow = $( '#api-sandbox-query-row' ), |
14 | 14 | $help = $( '#api-sandbox-help' ), |
15 | 15 | $further = $( '#api-sandbox-further-inputs' ), |
16 | 16 | $submit = $( '#api-sandbox-submit' ), |
— | — | @@ -47,13 +47,13 @@ |
48 | 48 | ); |
49 | 49 | |
50 | 50 | $action.change( updateBasics ); |
51 | | - $prop.change( updateBasics ); |
| 51 | + $query.change( updateBasics ); |
52 | 52 | |
53 | 53 | $submit.click( function() { |
54 | 54 | var url = apiPhp + '?action=' + $action.val(), |
55 | 55 | info = currentInfo; // in case it changes later |
56 | 56 | if ( $action.val() == 'query' ) { |
57 | | - url += '&prop=' + $prop.val(); |
| 57 | + url += '&' + $query.val(); |
58 | 58 | } |
59 | 59 | url += '&format=' + $format.val(); |
60 | 60 | var params = ''; |
— | — | @@ -145,15 +145,16 @@ |
146 | 146 | $submit.removeAttr( 'disabled' ); |
147 | 147 | } |
148 | 148 | |
149 | | - function getQueryInfo( action, prop ) { |
| 149 | + function getQueryInfo( action, query ) { |
150 | 150 | var isQuery = action == 'query'; |
151 | | - if ( action == '-' || ( isQuery && prop == '-' ) ) { |
| 151 | + if ( action == '-' || ( isQuery && query == '-' ) ) { |
152 | 152 | $submit.attr( 'disabled', 'disabled' ); |
153 | 153 | return; |
154 | 154 | } |
| 155 | + query = query.replace( /^.*=/, '' ); |
155 | 156 | var cached; |
156 | 157 | if ( isQuery ) { |
157 | | - cached = propCache[prop]; |
| 158 | + cached = propCache[query]; |
158 | 159 | } else { |
159 | 160 | cached = actionCache[action]; |
160 | 161 | } |
— | — | @@ -164,7 +165,7 @@ |
165 | 166 | action: 'paraminfo' |
166 | 167 | }; |
167 | 168 | if (isQuery ) { |
168 | | - data.querymodules = prop; |
| 169 | + data.querymodules = query; |
169 | 170 | } else { |
170 | 171 | data.modules = action; |
171 | 172 | } |
— | — | @@ -269,16 +270,16 @@ |
270 | 271 | |
271 | 272 | function updateBasics() { |
272 | 273 | var a = $action.val(), |
273 | | - p = $prop.val(), |
| 274 | + q = $query.val(), |
274 | 275 | isQuery = a == 'query'; |
275 | 276 | if ( isQuery ) { |
276 | | - $propRow.show(); |
| 277 | + $queryRow.show(); |
277 | 278 | } else { |
278 | | - $propRow.hide(); |
| 279 | + $queryRow.hide(); |
279 | 280 | } |
280 | 281 | $further.text( '' ); |
281 | 282 | $help.text( '' ); |
282 | | - getQueryInfo( a, p ); |
| 283 | + getQueryInfo( a, q ); |
283 | 284 | } |
284 | 285 | |
285 | 286 | }); |
\ No newline at end of file |
Index: trunk/extensions/ApiSandbox/ApiSandbox.i18n.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | 'apisb-request-url' => 'Request URL:', |
15 | 15 | 'apisb-request-post' => 'POST data:', |
16 | 16 | 'apisb-select-action' => 'Select action', |
17 | | - 'apisb-select-prop' => 'Select property', |
| 17 | + 'apisb-select-query' => 'What to query?', |
18 | 18 | 'apisb-select-value' => 'Select value', |
19 | 19 | 'apisb-loading' => 'Loading...', |
20 | 20 | 'apisb-load-error' => 'Error loading API description', |
— | — | @@ -21,4 +21,7 @@ |
22 | 22 | 'apisb-namespaces-error' => 'Error loading namespaces', |
23 | 23 | 'apisb-ns-main' => '(Main)', |
24 | 24 | 'apisb-submit' => 'Make request', |
| 25 | + 'apisb-query-prop' => 'Properties', |
| 26 | + 'apisb-query-list' => 'Lists', |
| 27 | + 'apisb-query-meta' => 'Meta information', |
25 | 28 | ); |
\ No newline at end of file |