r23382 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23381‎ | r23382 | r23383 >
Date:11:09, 25 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Clean up the mess that is Xml::monthSelector()...
* Use accessors instead of direct access to static members
* Use existing XML functions to make life easier and guarantee clean XHTML
* Drop the useless class (use the ID in CSS)
Modified paths:
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -131,28 +131,18 @@
132132 * @param $allmonths String: value of a special item denoting all month. Null to not include (default)
133133 * @return String: Html string containing the month selector
134134 */
135 - public static function monthSelector($selected = '', $allmonths = null) {
 135+ public static function monthSelector( $selected = '', $allmonths = null ) {
 136+ global $wgLang;
 137+ $options = array();
136138 if( is_null( $selected ) )
137139 $selected = '';
138 - $s = "\n<select id='month' name='month' class='monthselector'>\n";
139 - $arr = Language::$mMonthMsgs;
140 -
141 - if( !is_null($allmonths) ) {
142 - $arr = array($allmonths => 'monthsall') + $arr;
143 - }
144 - foreach ($arr as $index => $name) {
145 - $message = wfMsgHtml($name);
146 - $index++; // Let January be 1
147 -
148 - if ($index === $selected) {
149 - $s .= "\t" . self::element("option",
150 - array("value" => $index, "selected" => "selected"), $message) . "\n";
151 - } else {
152 - $s .= "\t" . self::element("option", array("value" => $index), $message) . "\n";
153 - }
154 - }
155 - $s .= "</select>\n";
156 - return $s;
 140+ if( !is_null( $allmonths ) )
 141+ $options[] = self::option( wfMsg( 'monthsall' ), $allmonths, $selected === $allmonths );
 142+ for( $i = 1; $i < 13; $i++ )
 143+ $options[] = self::option( $wgLang->getMonthName( $i ), $i, $selected === $i );
 144+ return self::openElement( 'select', array( 'id' => 'month', 'name' => 'month' ) )
 145+ . implode( "\n", $options )
 146+ . self::closeElement( 'select' );
157147 }
158148
159149 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r23407Merged revisions 23203-23405 via svnmerge from...david23:00, 25 June 2007

Status & tagging log