Clean up the mess that is Xml::monthSelector()...
authorRob Church <robchurch@users.mediawiki.org>
Mon, 25 Jun 2007 11:09:51 +0000 (11:09 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Mon, 25 Jun 2007 11:09:51 +0000 (11:09 +0000)
* 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)

includes/Xml.php

index c31a077..c5c60cb 100644 (file)
@@ -131,28 +131,18 @@ class Xml {
         * @param $allmonths String: value of a special item denoting all month. Null to not include (default)
         * @return String: Html string containing the month selector
         */
-       public static function monthSelector($selected = '', $allmonths = null) {
+       public static function monthSelector( $selected = '', $allmonths = null ) {
+               global $wgLang;
+               $options = array();
                if( is_null( $selected ) )
                        $selected = '';
-               $s = "\n<select id='month' name='month' class='monthselector'>\n";
-               $arr = Language::$mMonthMsgs;
-               
-               if( !is_null($allmonths) ) {
-                       $arr = array($allmonths => 'monthsall') + $arr;
-               }
-               foreach ($arr as $index => $name) {
-                       $message = wfMsgHtml($name);
-                       $index++; // Let January be 1
-
-                       if ($index === $selected) {
-                               $s .= "\t" . self::element("option",
-                                               array("value" => $index, "selected" => "selected"), $message) . "\n";
-                       } else {
-                               $s .= "\t" . self::element("option", array("value" => $index), $message) . "\n";
-                       }
-               }
-               $s .= "</select>\n";
-               return $s;
+               if( !is_null( $allmonths ) )
+                       $options[] = self::option( wfMsg( 'monthsall' ), $allmonths, $selected === $allmonths );
+               for( $i = 1; $i < 13; $i++ )
+                       $options[] = self::option( $wgLang->getMonthName( $i ), $i, $selected === $i );
+               return self::openElement( 'select', array( 'id' => 'month', 'name' => 'month' ) )
+                       . implode( "\n", $options )
+                       . self::closeElement( 'select' );
        }
 
        /**