r99260 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99259‎ | r99260 | r99261 >
Date:21:20, 7 October 2011
Author:nikerabbit
Status:deferred
Tags:
Comment:
Removed HTMLSelector in preference to XmlSelect class in core, which is better maintained
Modified paths:
  • /trunk/extensions/Translate/TranslateHooks.php (modified) (history)
  • /trunk/extensions/Translate/TranslateUtils.php (modified) (history)
  • /trunk/extensions/Translate/_autoload.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialMagic.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialMessageGroupStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/TranslateHooks.php
@@ -275,15 +275,16 @@
276276
277277 ksort( $languages );
278278
279 - $selector = new HTMLSelector( 'languagefilter', 'languagefilter', $selected );
280 - $selector->addOption( wfMessage( 'translate-search-nofilter' ), '-' );
 279+ $selector = new XmlSelect( 'languagefilter', 'languagefilter' );
 280+ $selector->setDefault( $selected );
 281+ $selector->addOption( wfMessage( 'translate-search-nofilter' )->text(), '-' );
281282 foreach ( $languages as $code => $name ) {
282283 $selector->addOption( "$code - $name", $code );
283284 }
284285
285286 $selector = $selector->getHTML();
286287
287 - $label = Xml::label( wfMessage( 'translate-search-languagefilter' ), 'languagefilter' ) . ' ';
 288+ $label = Xml::label( wfMessage( 'translate-search-languagefilter' )->text(), 'languagefilter' ) . ' ';
288289 $params = array( 'id' => 'mw-searchoptions' );
289290
290291 $form = Xml::fieldset( false, false, $params ) .
Index: trunk/extensions/Translate/_autoload.php
@@ -20,7 +20,6 @@
2121 $wgAutoloadClasses['TaskOptions'] = $dir . 'TranslateTasks.php';
2222
2323 $wgAutoloadClasses['TranslateUtils'] = $dir . 'TranslateUtils.php';
24 -$wgAutoloadClasses['HTMLSelector'] = $dir . 'TranslateUtils.php';
2524
2625 $wgAutoloadClasses['TranslateHooks'] = $dir . 'TranslateHooks.php';
2726
Index: trunk/extensions/Translate/specials/SpecialMagic.php
@@ -87,7 +87,7 @@
8888 * @return \string HTML5-compatible select-element.
8989 */
9090 protected function moduleSelector( $selectedId ) {
91 - $selector = new HTMLSelector( 'module', 'module', $selectedId );
 91+ $selector = new XmlSelect( 'module', 'module', $selectedId );
9292 foreach ( $this->aModules as $code ) {
9393 $selector->addOption( wfMsg( 'translate-magic-' . $code ), $code );
9494 }
Index: trunk/extensions/Translate/specials/SpecialMessageGroupStats.php
@@ -55,7 +55,7 @@
5656 /// @todo duplicated code
5757 protected function groupSelector( $default ) {
5858 $groups = MessageGroups::getAllGroups();
59 - $selector = new HTMLSelector( 'group', 'group', $default );
 59+ $selector = new XmlSelect( 'group', 'group', $default );
6060
6161 foreach ( $groups as $id => $class ) {
6262 if ( MessageGroups::getGroup( $id )->exists() ) {
Index: trunk/extensions/Translate/TranslateUtils.php
@@ -209,7 +209,8 @@
210210
211211 ksort( $languages );
212212
213 - $selector = new HTMLSelector( 'language', 'language', $selectedId );
 213+ $selector = new XmlSelect( 'language', 'language' );
 214+ $selector->setDefault( $selectedId );
214215 foreach ( $languages as $code => $name ) {
215216 $selector->addOption( "$code - $name", $code );
216217 }
@@ -321,70 +322,3 @@
322323 }
323324
324325 }
325 -
326 -/**
327 - * Yet another class for building html selectors.
328 - */
329 -class HTMLSelector {
330 - /// \list{String} \<option> elements.
331 - private $options = array();
332 - /// \string The selected value.
333 - private $selected = false;
334 - /// \array Extra html attributes.
335 - private $attributes = array();
336 -
337 - /**
338 - * @param $name \string
339 - * @param $id \string Default false.
340 - * @param $selected \string Default false.
341 - */
342 - public function __construct( $name = false, $id = false, $selected = false ) {
343 - if ( $name ) {
344 - $this->setAttribute( 'name', $name );
345 - }
346 -
347 - if ( $id ) {
348 - $this->setAttribute( 'id', $id );
349 - }
350 -
351 - if ( $selected ) {
352 - $this->selected = $selected;
353 - }
354 - }
355 -
356 - /**
357 - * Set selected value.
358 - * @param $selected \string Default false.
359 - */
360 - public function setSelected( $selected ) {
361 - $this->selected = $selected;
362 - }
363 -
364 - /**
365 - * Set html attribute.
366 - * @param $name \string Attribute name.
367 - * @param $value \string Attribute value.
368 - */
369 - public function setAttribute( $name, $value ) {
370 - $this->attributes[$name] = $value;
371 - }
372 -
373 - /**
374 - * Add an option.
375 - * @param $name \string Display name.
376 - * @param $value \string Option value. Uses $name if not given.
377 - * @param $selected \string Default selected value. Uses object value if not given.
378 - */
379 - public function addOption( $name, $value = false, $selected = false ) {
380 - $selected = $selected ? $selected : $this->selected;
381 - $value = $value ? $value : $name;
382 - $this->options[] = Xml::option( $name, $value, $value === $selected );
383 - }
384 -
385 - /**
386 - * @return \string Html for the selector.
387 - */
388 - public function getHTML() {
389 - return Xml::tags( 'select', $this->attributes, implode( "\n", $this->options ) );
390 - }
391 -}

Status & tagging log