X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHtml.php;h=9e7f5c4db4a04be81435448c2fd60d35f8c48420;hb=308244ef44364f3eb49c420f48d030da85232924;hp=cb98009e8dcbfd609c766909effffaa192803d45;hpb=4c413f2ae7020a0a5a87aa0814b67c2c18d09f35;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Html.php b/includes/Html.php index cb98009e8d..9e7f5c4db4 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 @@ -225,12 +254,11 @@ class Html { } /** - * Returns "", except if $wgWellFormedXml is off, in which case - * it returns the empty string when that's guaranteed to be safe. + * Returns "" * * @since 1.17 * @param string $element Name of the element, e.g., 'a' - * @return string A closing tag, if required + * @return string A closing tag */ public static function closeElement( $element ) { $element = strtolower( $element ); @@ -633,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 ); } @@ -732,7 +762,7 @@ class Html { } else { $spacedValue = $value; } - return self::element( 'textarea', $attribs, $spacedValue ); + return self::element( 'textarea', Html::getTextInputAttributes( $attribs ), $spacedValue ); } /**