From: Aryeh Gregor Date: Sun, 6 Sep 2009 15:07:52 +0000 (+0000) Subject: Move more logic from input() to element() X-Git-Tag: 1.31.0-rc.0~39895 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=e476e9731487905044a0aed74288aeeee64d6fe5;p=lhc%2Fweb%2Fwiklou.git Move more logic from input() to element() --- diff --git a/includes/Html.php b/includes/Html.php index 8d97bc4a66..a58459d04a 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -83,6 +83,17 @@ class Html { 'seamless', ); + # A nested associative array of element => content attribute => default + # value. Attributes that have the default value will be omitted, since + # they're pointless. Currently the list hasn't been systematically + # populated. + private static $attribDefaults = array( + 'input' => array( + 'value' => '', + 'type' => 'text', + ), + ); + /** * Returns an HTML element in a string. The major advantage here over * manually typing out the HTML is that it will escape all attribute @@ -153,6 +164,15 @@ class Html { } } + # Don't bother outputting the default values for attributes + foreach ( $attribs as $attrib => $value ) { + $lcattrib = strtolower( $attrib ); + if ( isset( self::$attribDefaults[$element][$lcattrib] ) && + self::$attribDefaults[$element][$lcattrib] === $value ) { + unset( $attribs[$attrib] ); + } + } + $start = "<$element" . self::expandAttributes( $attribs ); if ( in_array( $element, self::$voidElements ) ) { if ( $wgWellFormedXml ) { @@ -352,10 +372,8 @@ class Html { * @return string Raw HTML */ public static function input( $name, $value = null, $type = 'text', $attribs = array() ) { - if ( $type != 'text' ) { - $attribs['type'] = $type; - } - if ( $value !== null && $value !== '' ) { + $attribs['type'] = $type; + if ( $value !== null ) { $attribs['value'] = $value; } $attribs['name'] = $name;