Index: trunk/extensions/ApiSandbox/SpecialApiSandbox.php |
— | — | @@ -40,11 +40,11 @@ |
41 | 41 | . '<table class="api-sandbox-result-container"><tbody> |
42 | 42 | ' |
43 | 43 | . '<tr><th class="api-sandbox-result-label"><label for="api-sandbox-url">' |
44 | | - . wfMessage( 'apisb-request-url' )->parse() . '</label></th>' |
| 44 | + . wfMessage( 'apisb-result-request-url' )->parse() . '</label></th>' |
45 | 45 | . '<td><input id="api-sandbox-url" readonly="readonly" /></td></tr> |
46 | 46 | ' |
47 | 47 | . '<tr id="api-sandbox-post-row"><th class="api-sandbox-result-label"><label for="api-sandbox-post">' |
48 | | - . wfMessage( 'apisb-request-post' )->parse() . '</label></th>' |
| 48 | + . wfMessage( 'apisb-result-request-post' )->parse() . '</label></th>' |
49 | 49 | . '<td><input id="api-sandbox-post" readonly="readonly" /></td></tr> |
50 | 50 | ' |
51 | 51 | . '<tr><td colspan="2"><div id="api-sandbox-output"></div></td></tr>' |
— | — | @@ -62,9 +62,11 @@ |
63 | 63 | |
64 | 64 | $apiMain = new ApiMain( new FauxRequest( array() ), $wgEnableWriteAPI ); |
65 | 65 | $this->apiQuery = new ApiQuery( $apiMain, 'query' ); |
66 | | - $formats = array_filter( array_keys( $apiMain->getFormats() ), |
67 | | - 'SpecialApiSandbox::filterFormats' ); |
| 66 | + |
| 67 | + $formats = array_filter( array_keys( $apiMain->getFormats() ), 'SpecialApiSandbox::filterFormats' ); |
68 | 68 | sort( $formats ); |
| 69 | + $formatOptions = array_combine( $formats, $formats ); |
| 70 | + |
69 | 71 | $modules = array_keys( $apiMain->getModules() ); |
70 | 72 | sort( $modules ); |
71 | 73 | $key = array_search( 'query', $modules ); |
— | — | @@ -72,6 +74,8 @@ |
73 | 75 | array_splice( $modules, $key, 1 ); |
74 | 76 | array_unshift( $modules, 'query' ); |
75 | 77 | } |
| 78 | + $moduleOptions = array_combine( $modules, $modules ); |
| 79 | + |
76 | 80 | $queryModules = array_merge( |
77 | 81 | $this->getQueryModules( 'list' ), |
78 | 82 | $this->getQueryModules( 'prop' ), |
— | — | @@ -89,9 +93,9 @@ |
90 | 94 | <th class="api-sandbox-docs-col">Documentation</th> |
91 | 95 | </tr> |
92 | 96 | <tr> |
93 | | - <td>' . self::getSelect( 'format', $formats, 'json' ) . '</td> |
| 97 | + <td>' . self::getSelect( 'format', $formatOptions, 'json' ) . '</td> |
94 | 98 | <td> |
95 | | - ' . self::getSelect( 'action', $modules ) . ' |
| 99 | + ' . self::getSelect( 'action', $moduleOptions ) . ' |
96 | 100 | <div id="api-sandbox-query-row" style="display: none;"> |
97 | 101 | ' . self::getSelect( 'query', $queryModules ) . ' |
98 | 102 | </div> |
— | — | @@ -117,30 +121,22 @@ |
118 | 122 | * @return array |
119 | 123 | */ |
120 | 124 | private function getQueryModules( $type ) { |
121 | | - $res = array(); |
| 125 | + $options = array(); |
122 | 126 | $params = $this->apiQuery->getAllowedParams(); |
123 | 127 | foreach ( $params[$type][ApiBase::PARAM_TYPE] as $module ) { |
124 | | - $res[] = array( |
125 | | - 'value' => "$type=$module", |
126 | | - 'text' => /* x 3 */ "\xc2\xa0\xc2\xa0\xc2\xa0$type=$module", |
127 | | - ); |
| 128 | + $options["$type=$module"] = "$type=$module"; |
128 | 129 | } |
129 | | - sort( $res ); |
130 | | - array_unshift( $res, |
131 | | - array( |
132 | | - 'value' => "-$type-", |
133 | | - 'text' => wfMessage( "apisb-query-$type" )->parse(), |
134 | | - 'attributes' => array( 'disabled' => 'disabled' ) |
135 | | - ) |
136 | | - ); |
137 | | - |
138 | | - return $res; |
| 130 | + |
| 131 | + $optgroup = array(); |
| 132 | + $optgroup[wfMessage( "apisb-query-$type" )->parse()] = $options; |
| 133 | + |
| 134 | + return $optgroup; |
139 | 135 | } |
140 | 136 | |
141 | 137 | /** |
142 | 138 | * @param $name string |
143 | 139 | * @param $items array |
144 | | - * @param $default bool |
| 140 | + * @param $default mixed |
145 | 141 | * @return string |
146 | 142 | */ |
147 | 143 | private static function getSelect( $name, $items, $default = false ) { |
— | — | @@ -150,47 +146,21 @@ |
151 | 147 | 'id' => "api-sandbox-$name" ) |
152 | 148 | ); |
153 | 149 | if ( $default === false ) { |
154 | | - $s .= "\n\t" . self::option( '-', wfMessage( "apisb-select-$name" )->text(), |
155 | | - array( 'selected' => 'selected' ) |
156 | | - ); |
| 150 | + $s .= Xml::option( wfMessage( "apisb-select-$name" )->text(), '', true ); |
157 | 151 | } |
158 | | - foreach ( $items as $item ) { |
159 | | - $attributes = array(); |
160 | | - if ( is_array( $item ) ) { |
161 | | - $value = $item['value']; |
162 | | - $text = $item['text']; |
163 | | - $attributes = isset( $item['attributes'] ) ? $item['attributes'] : array(); |
164 | | - } else { |
165 | | - $value = $text = $item; |
166 | | - } |
167 | | - if ( $value === $default ) { |
168 | | - $attributes['selected'] = 'selected'; |
169 | | - } |
170 | | - $s .= "\n\t" . self::option( $value, $text, $attributes ); |
171 | | - } |
172 | | - $s .= "\n" . Html::closeElement( 'select' ) . "\n"; |
| 152 | + $s .= XmlSelect::formatOptions( $items, $default ); |
| 153 | + $s .= Html::closeElement( 'select' ); |
173 | 154 | return $s; |
174 | 155 | } |
175 | 156 | |
176 | 157 | /** |
177 | | - * @param $value string |
178 | | - * @param $text string |
179 | | - * @param $attributes array |
180 | | - * @return string |
181 | | - */ |
182 | | - private static function option( $value, $text, $attributes = array() ) { |
183 | | - $attributes['value'] = $value; |
184 | | - return Html::element( 'option', $attributes, $text ); |
185 | | - } |
186 | | - |
187 | | - /** |
188 | 158 | * @param $name string |
189 | 159 | * @param $attribs Array |
190 | 160 | * @return string |
191 | 161 | */ |
192 | 162 | private function openFieldset( $name, $attribs = array() ) { |
193 | 163 | return "\n" . Html::openElement( 'fieldset', array( 'id' => "api-sandbox-$name" ) + $attribs ) |
194 | | - . "\n\t" . Html::rawElement( 'legend', array(), wfMessage( "apisb-$name" )->parse() ) |
| 164 | + . "\n\t" . Html::rawElement( 'legend', array(), wfMessage( "apisb-legend-$name" )->parse() ) |
195 | 165 | . "\n"; |
196 | 166 | } |
197 | 167 | |
Index: trunk/extensions/ApiSandbox/ApiSandbox.i18n.php |
— | — | @@ -15,13 +15,15 @@ |
16 | 16 | 'apisb-intro' => "Use this page to experiment with the '''MediaWiki web service API'''. |
17 | 17 | Refer to [//www.mediawiki.org/wiki/API:Main_page the API documentation] for further details of API usage. Example: [//www.mediawiki.org/wiki/API#A_simple_example get the content of a Main Page]. Select an action to see more examples.", |
18 | 18 | 'apisb-api-disabled' => 'API is disabled on this site.', |
19 | | - 'apisb-parameters' => 'Parameters', |
20 | | - 'apisb-result' => 'Result', |
21 | | - 'apisb-request-url' => 'Request URL:', |
22 | | - 'apisb-request-post' => 'POST data:', |
23 | | - 'apisb-select-action' => 'Select action', |
24 | | - 'apisb-select-query' => 'What to query?', |
25 | | - 'apisb-select-value' => 'Select value', |
| 19 | + 'apisb-legend-parameters' => 'Parameters', |
| 20 | + 'apisb-legend-result' => 'Result', |
| 21 | + 'apisb-legend-generic-parameters'=> 'Generic parameters', |
| 22 | + 'apisb-legend-generator-parameters'=> 'Generator', |
| 23 | + 'apisb-result-request-url' => 'Request URL:', |
| 24 | + 'apisb-result-request-post' => 'POST data:', |
| 25 | + 'apisb-select-action' => '(select action)', |
| 26 | + 'apisb-select-query' => '(select query)', |
| 27 | + 'apisb-select-value' => '(select value)', |
26 | 28 | 'apisb-docs-more' => 'read more', |
27 | 29 | 'apisb-params-param' => 'Parameter', |
28 | 30 | 'apisb-params-input' => 'Input', |
— | — | @@ -35,8 +37,6 @@ |
36 | 38 | 'apisb-query-prop' => 'Properties', |
37 | 39 | 'apisb-query-list' => 'Lists', |
38 | 40 | 'apisb-query-meta' => 'Meta information', |
39 | | - 'apisb-generic-parameters'=> 'Generic parameters', |
40 | | - 'apisb-generator-parameters'=> 'Generator', |
41 | 41 | 'apisb-example' => 'Example', |
42 | 42 | 'apisb-examples' => 'Examples', |
43 | 43 | 'apisb-clear' => 'Clear', |
— | — | @@ -1721,7 +1721,7 @@ |
1722 | 1722 | 'apisb-query-list' => 'ליסטעס', |
1723 | 1723 | ); |
1724 | 1724 | |
1725 | | -/** Simplified Chinese (中文(简体)) |
| 1725 | +/** Simplified Chinese (中文(简体)) |
1726 | 1726 | * @author Anakmalaysia |
1727 | 1727 | * @author Hydra |
1728 | 1728 | * @author Hzy980512 |
— | — | @@ -1765,7 +1765,7 @@ |
1766 | 1766 | 'apisb-clear' => '清除', |
1767 | 1767 | ); |
1768 | 1768 | |
1769 | | -/** Traditional Chinese (中文(繁體)) |
| 1769 | +/** Traditional Chinese (中文(繁體)) |
1770 | 1770 | * @author Anakmalaysia |
1771 | 1771 | * @author Liangent |
1772 | 1772 | */ |