Use XmlSelect to simplify Xml::monthSelector
authorGeoffrey Mon <geofbot@gmail.com>
Sun, 7 Jun 2015 00:26:57 +0000 (20:26 -0400)
committerGeoffrey Mon <geofbot@gmail.com>
Sun, 7 Jun 2015 00:26:57 +0000 (20:26 -0400)
 * Modify Xml::monthSelector
 * Tweak XmlTest.php to swap the order of some props (XmlSelect
    output swaps the position of id and name props of <select>s)

Bug: T93234
Change-Id: If7e41251a6b2314e36dac8b7522c8e7b765f1814

includes/Xml.php
tests/phpunit/includes/XmlTest.php

index c356c6d..37cffde 100644 (file)
@@ -144,26 +144,19 @@ class Xml {
        public static function monthSelector( $selected = '', $allmonths = null, $id = 'month' ) {
                global $wgLang;
                $options = array();
+               $data = new XmlSelect( 'month', $id, $selected );
                if ( is_null( $selected ) ) {
                        $selected = '';
                }
                if ( !is_null( $allmonths ) ) {
-                       $options[] = self::option(
-                               wfMessage( 'monthsall' )->text(),
-                               $allmonths,
-                               $selected === $allmonths
-                       );
+                       $options[wfMessage( 'monthsall' )->text()] = $allmonths;
                }
                for ( $i = 1; $i < 13; $i++ ) {
-                       $options[] = self::option( $wgLang->getMonthName( $i ), $i, $selected === $i );
-               }
-               return self::openElement( 'select', array(
-                       'id' => $id,
-                       'name' => 'month',
-                       'class' => 'mw-month-selector'
-               ) )
-                       . implode( "\n", $options )
-                       . self::closeElement( 'select' );
+                       $options[$wgLang->getMonthName( $i )] = $i;
+               }
+               $data->addOptions( $options );
+               $data->setAttribute( 'class', 'mw-month-selector' );
+               return $data->getHTML();
        }
 
        /**
index 382e3d8..bea338d 100644 (file)
@@ -154,7 +154,7 @@ class XmlTest extends MediaWikiTestCase {
                        '<label for="year">From year (and earlier):</label> ' .
                                '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> ' .
                                '<label for="month">From month (and earlier):</label> ' .
-                               '<select id="month" name="month" class="mw-month-selector">' .
+                               '<select name="month" id="month" class="mw-month-selector">' .
                                '<option value="-1">all</option>' . "\n" .
                                '<option value="1">January</option>' . "\n" .
                                '<option value="2" selected="">February</option>' . "\n" .
@@ -175,7 +175,7 @@ class XmlTest extends MediaWikiTestCase {
                        '<label for="year">From year (and earlier):</label> ' .
                                '<input id="year" maxlength="4" size="7" type="number" value="2011" name="year" /> ' .
                                '<label for="month">From month (and earlier):</label> ' .
-                               '<select id="month" name="month" class="mw-month-selector">' .
+                               '<select name="month" id="month" class="mw-month-selector">' .
                                '<option value="-1">all</option>' . "\n" .
                                '<option value="1">January</option>' . "\n" .
                                '<option value="2">February</option>' . "\n" .
@@ -209,7 +209,7 @@ class XmlTest extends MediaWikiTestCase {
                        '<label for="year">From year (and earlier):</label> ' .
                                '<input id="year" maxlength="4" size="7" type="number" name="year" /> ' .
                                '<label for="month">From month (and earlier):</label> ' .
-                               '<select id="month" name="month" class="mw-month-selector">' .
+                               '<select name="month" id="month" class="mw-month-selector">' .
                                '<option value="-1">all</option>' . "\n" .
                                '<option value="1">January</option>' . "\n" .
                                '<option value="2">February</option>' . "\n" .