r109777 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109776‎ | r109777 | r109778 >
Date:23:04, 22 January 2012
Author:krinkle
Status:ok
Tags:api 
Comment:
[ApiSandbox] clean up msgs and selects

* Renamed messages:
apisb-parameters > apisb-legend-parameters
apisb-result > apisb-legend-result
apisb-generic-parameters > apisb-legend-generic-parameters
apisb-generator-parameters > apisb-legend-generator-parameters
apisb-request-url > apisb-result-request-url
apisb-request-post > apisb-result-request-post

* Removed weird character hack in getSelect with special characters, indention and disabled options. Using <optgroup> instead
Modified paths:
  • /trunk/extensions/ApiSandbox/ApiSandbox.i18n.php (modified) (history)
  • /trunk/extensions/ApiSandbox/SpecialApiSandbox.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ApiSandbox/SpecialApiSandbox.php
@@ -40,11 +40,11 @@
4141 . '<table class="api-sandbox-result-container"><tbody>
4242 '
4343 . '<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>'
4545 . '<td><input id="api-sandbox-url" readonly="readonly" /></td></tr>
4646 '
4747 . '<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>'
4949 . '<td><input id="api-sandbox-post" readonly="readonly" /></td></tr>
5050 '
5151 . '<tr><td colspan="2"><div id="api-sandbox-output"></div></td></tr>'
@@ -62,9 +62,11 @@
6363
6464 $apiMain = new ApiMain( new FauxRequest( array() ), $wgEnableWriteAPI );
6565 $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' );
6868 sort( $formats );
 69+ $formatOptions = array_combine( $formats, $formats );
 70+
6971 $modules = array_keys( $apiMain->getModules() );
7072 sort( $modules );
7173 $key = array_search( 'query', $modules );
@@ -72,6 +74,8 @@
7375 array_splice( $modules, $key, 1 );
7476 array_unshift( $modules, 'query' );
7577 }
 78+ $moduleOptions = array_combine( $modules, $modules );
 79+
7680 $queryModules = array_merge(
7781 $this->getQueryModules( 'list' ),
7882 $this->getQueryModules( 'prop' ),
@@ -89,9 +93,9 @@
9094 <th class="api-sandbox-docs-col">Documentation</th>
9195 </tr>
9296 <tr>
93 - <td>' . self::getSelect( 'format', $formats, 'json' ) . '</td>
 97+ <td>' . self::getSelect( 'format', $formatOptions, 'json' ) . '</td>
9498 <td>
95 - ' . self::getSelect( 'action', $modules ) . '
 99+ ' . self::getSelect( 'action', $moduleOptions ) . '
96100 <div id="api-sandbox-query-row" style="display: none;">
97101 ' . self::getSelect( 'query', $queryModules ) . '
98102 </div>
@@ -117,30 +121,22 @@
118122 * @return array
119123 */
120124 private function getQueryModules( $type ) {
121 - $res = array();
 125+ $options = array();
122126 $params = $this->apiQuery->getAllowedParams();
123127 foreach ( $params[$type][ApiBase::PARAM_TYPE] as $module ) {
124 - $res[] = array(
125 - 'value' => "$type=$module",
126 - 'text' => /* &nbsp; x 3 */ "\xc2\xa0\xc2\xa0\xc2\xa0$type=$module",
127 - );
 128+ $options["$type=$module"] = "$type=$module";
128129 }
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;
139135 }
140136
141137 /**
142138 * @param $name string
143139 * @param $items array
144 - * @param $default bool
 140+ * @param $default mixed
145141 * @return string
146142 */
147143 private static function getSelect( $name, $items, $default = false ) {
@@ -150,47 +146,21 @@
151147 'id' => "api-sandbox-$name" )
152148 );
153149 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 );
157151 }
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' );
173154 return $s;
174155 }
175156
176157 /**
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 - /**
188158 * @param $name string
189159 * @param $attribs Array
190160 * @return string
191161 */
192162 private function openFieldset( $name, $attribs = array() ) {
193163 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() )
195165 . "\n";
196166 }
197167
Index: trunk/extensions/ApiSandbox/ApiSandbox.i18n.php
@@ -15,13 +15,15 @@
1616 'apisb-intro' => "Use this page to experiment with the '''MediaWiki web service API'''.
1717 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.",
1818 '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)',
2628 'apisb-docs-more' => 'read more',
2729 'apisb-params-param' => 'Parameter',
2830 'apisb-params-input' => 'Input',
@@ -35,8 +37,6 @@
3638 'apisb-query-prop' => 'Properties',
3739 'apisb-query-list' => 'Lists',
3840 'apisb-query-meta' => 'Meta information',
39 - 'apisb-generic-parameters'=> 'Generic parameters',
40 - 'apisb-generator-parameters'=> 'Generator',
4141 'apisb-example' => 'Example',
4242 'apisb-examples' => 'Examples',
4343 'apisb-clear' => 'Clear',
@@ -1721,7 +1721,7 @@
17221722 'apisb-query-list' => 'ליסטעס',
17231723 );
17241724
1725 -/** Simplified Chinese (‪中文(简体)‬)
 1725+/** Simplified Chinese (中文(简体))
17261726 * @author Anakmalaysia
17271727 * @author Hydra
17281728 * @author Hzy980512
@@ -1765,7 +1765,7 @@
17661766 'apisb-clear' => '清除',
17671767 );
17681768
1769 -/** Traditional Chinese (‪中文(繁體)‬)
 1769+/** Traditional Chinese (中文(繁體))
17701770 * @author Anakmalaysia
17711771 * @author Liangent
17721772 */

Status & tagging log