X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FHtml.php;h=48dbdba6915ee2ec9d30b9fce697f16650be37c3;hb=d1b6cd35d4aa117c454994b4a7896fee8abf17d2;hp=419250795dad18e98489d0f72bdcc2e504320378;hpb=bc91ec321a0c57d39709f996fbf9d084c77b3f91;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Html.php b/includes/Html.php index 419250795d..48dbdba691 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -101,6 +101,35 @@ class Html { 'itemscope', ); + /** + * Modifies a set of attributes meant for text input elements + * and apply a set of default attributes. + * Removes size attribute when $wgUseMediaWikiUIEverywhere enabled. + * @param array $attrs An attribute array. + * @return array $attrs A modified attribute array + */ + public static function getTextInputAttributes( $attrs ) { + global $wgUseMediaWikiUIEverywhere; + if ( !$attrs ) { + $attrs = array(); + } + if ( isset( $attrs['class'] ) ) { + if ( is_array( $attrs['class'] ) ) { + $attrs['class'][] = 'mw-ui-input'; + } else { + $attrs['class'] .= ' mw-ui-input'; + } + } else { + $attrs['class'] = 'mw-ui-input'; + } + if ( $wgUseMediaWikiUIEverywhere ) { + // Note that size can effect the desired width rendering of mw-ui-input elements + // so it is removed. Left intact when mediawiki ui not enabled. + unset( $attrs['size'] ); + } + return $attrs; + } + /** * Returns an HTML element in a string. The major advantage here over * manually typing out the HTML is that it will escape all attribute @@ -632,7 +661,9 @@ class Html { $attribs['type'] = $type; $attribs['value'] = $value; $attribs['name'] = $name; - + if ( in_array( $type, array( 'text', 'search', 'email', 'password', 'number' ) ) ) { + $attribs = Html::getTextInputAttributes( $attribs ); + } return self::element( 'input', $attribs ); } @@ -642,6 +673,7 @@ class Html { * @param string $name Name attribute * @param bool $checked Whether the checkbox is checked or not * @param array $attribs Array of additional attributes + * @return string */ public static function check( $name, $checked = false, array $attribs = array() ) { if ( isset( $attribs['value'] ) ) { @@ -664,6 +696,7 @@ class Html { * @param string $name Name attribute * @param bool $checked Whether the checkbox is checked or not * @param array $attribs Array of additional attributes + * @return string */ public static function radio( $name, $checked = false, array $attribs = array() ) { if ( isset( $attribs['value'] ) ) { @@ -686,6 +719,7 @@ class Html { * @param string $label Contents of the label * @param string $id ID of the element being labeled * @param array $attribs Additional attributes + * @return string */ public static function label( $label, $id, array $attribs = array() ) { $attribs += array( @@ -731,7 +765,7 @@ class Html { } else { $spacedValue = $value; } - return self::element( 'textarea', $attribs, $spacedValue ); + return self::element( 'textarea', Html::getTextInputAttributes( $attribs ), $spacedValue ); } /**