From e476e9731487905044a0aed74288aeeee64d6fe5 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 6 Sep 2009 15:07:52 +0000 Subject: [PATCH] Move more logic from input() to element() --- includes/Html.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) 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; -- 2.20.1