Sn1per has uploaded a new change for review. https://gerrit.wikimedia.org/r/216511
Change subject: Use XmlSelect to "simplify" stuff in class Xml ...................................................................... Use XmlSelect to "simplify" stuff in class Xml * Not all of it is "simplifying," for example, the listDropDown is kinda messy, so I understand if you don't want it. * Modify Xml::monthSelector and Xml::listDropDown * Tweak XmlTest.php to swap the order of some props (XmlSelect output swaps the position of id and name props of <select>s) Change-Id: If7e41251a6b2314e36dac8b7522c8e7b765f1814 --- M includes/Xml.php M tests/phpunit/includes/XmlTest.php 2 files changed, 24 insertions(+), 37 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/11/216511/1 diff --git a/includes/Xml.php b/includes/Xml.php index c356c6d..9ac8316 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -144,26 +144,19 @@ 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 ); + $options[$wgLang->getMonthName( $i )] = $i; } - return self::openElement( 'select', array( - 'id' => $id, - 'name' => 'month', - 'class' => 'mw-month-selector' - ) ) - . implode( "\n", $options ) - . self::closeElement( 'select' ); + $data->addOptions( $options ); + $data->setAttribute( 'class', 'mw-month-selector' ); + return $data->getHTML(); } /** @@ -516,8 +509,12 @@ $selected = '', $class = '', $tabindex = null ) { $optgroup = false; + $optgroupdata = array(); + $optgroupvalue = ''; + $value = ''; - $options = self::option( $other, 'other', $selected === 'other' ); + $options = new XmlSelect( $name ? $name : false, $name ? $name : false, $selected ); + $options->addOption( $other, 'other' ); foreach ( explode( "\n", $list ) as $option ) { $value = trim( $option ); @@ -527,48 +524,38 @@ // A new group is starting ... $value = trim( substr( $value, 1 ) ); if ( $optgroup ) { - $options .= self::closeElement( 'optgroup' ); + $options->addOption( $optgroupvalue, $optgroupdata ); } - $options .= self::openElement( 'optgroup', array( 'label' => $value ) ); + $optgroupdata = array(); $optgroup = true; + $optgroupvalue = $value; } elseif ( substr( $value, 0, 2 ) == '**' ) { // groupmember $value = trim( substr( $value, 2 ) ); - $options .= self::option( $value, $value, $selected === $value ); + $optgroupdata[$value] = $value; } else { // groupless reason list if ( $optgroup ) { - $options .= self::closeElement( 'optgroup' ); + $options->addOption( $optgroupvalue, $optgroupdata ); } - $options .= self::option( $value, $value, $selected === $value ); + $options->addOption( $value, $value ); $optgroup = false; } } if ( $optgroup ) { - $options .= self::closeElement( 'optgroup' ); - } - - $attribs = array(); - - if ( $name ) { - $attribs['id'] = $name; - $attribs['name'] = $name; + $options->addOption( $optgroupvalue, $optgroupdata ); } if ( $class ) { - $attribs['class'] = $class; + $options->setAttribute( 'class', $class ); } if ( $tabindex ) { - $attribs['tabindex'] = $tabindex; + $options->setAttribute( 'tabindex', $tabindex ); } - return Xml::openElement( 'select', $attribs ) - . "\n" - . $options - . "\n" - . Xml::closeElement( 'select' ); + return $options->getHTML(); } /** diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index 382e3d8..bea338d 100644 --- a/tests/phpunit/includes/XmlTest.php +++ b/tests/phpunit/includes/XmlTest.php @@ -154,7 +154,7 @@ '<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 @@ '<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 @@ '<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" . -- To view, visit https://gerrit.wikimedia.org/r/216511 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If7e41251a6b2314e36dac8b7522c8e7b765f1814 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Sn1per <geof...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits