* @see https://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers
* @return array $attrs A modified attribute array
*/
- public static function buttonAttributes( $attrs, $modifiers = array() ) {
+ public static function buttonAttributes( array $attrs, array $modifiers = array() ) {
global $wgUseMediaWikiUIEverywhere;
if ( $wgUseMediaWikiUIEverywhere ) {
if ( isset( $attrs['class'] ) ) {
* @param array $attrs An attribute array.
* @return array $attrs A modified attribute array
*/
- public static function getTextInputAttributes( $attrs ) {
+ public static function getTextInputAttributes( array $attrs ) {
global $wgUseMediaWikiUIEverywhere;
- if ( !$attrs ) {
- $attrs = array();
- }
if ( $wgUseMediaWikiUIEverywhere ) {
if ( isset( $attrs['class'] ) ) {
if ( is_array( $attrs['class'] ) ) {
* @see http://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers
* @return string Raw HTML
*/
- public static function linkButton( $contents, $attrs, $modifiers = array() ) {
+ public static function linkButton( $contents, array $attrs, array $modifiers = array() ) {
return self::element( 'a',
self::buttonAttributes( $attrs, $modifiers ),
$contents
* @see http://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers
* @return string Raw HTML
*/
- public static function submitButton( $contents, $attrs, $modifiers = array() ) {
+ public static function submitButton( $contents, array $attrs, array $modifiers = array() ) {
$attrs['type'] = 'submit';
$attrs['value'] = $contents;
return self::element( 'input', self::buttonAttributes( $attrs, $modifiers ) );
* further documentation.
* @return array An array of attributes functionally identical to $attribs
*/
- private static function dropDefaults( $element, $attribs ) {
-
+ private static function dropDefaults( $element, array $attribs ) {
// Whenever altering this array, please provide a covering test case
// in HtmlTest::provideElementsWithAttributesHavingDefaultValues
static $attribDefaults = array(
* @return string HTML fragment that goes between element name and '>'
* (starting with a space if at least one attribute is output)
*/
- public static function expandAttributes( $attribs ) {
+ public static function expandAttributes( array $attribs ) {
global $wgWellFormedXml;
$ret = '';
- $attribs = (array)$attribs;
foreach ( $attribs as $key => $value ) {
// Support intuitive array( 'checked' => true/false ) form
if ( $value === false || is_null( $value ) ) {
* attributes, passed to Html::element()
* @return string Raw HTML
*/
- public static function input( $name, $value = '', $type = 'text', $attribs = array() ) {
+ public static function input( $name, $value = '', $type = 'text', array $attribs = array() ) {
$attribs['type'] = $type;
$attribs['value'] = $value;
$attribs['name'] = $name;
* attributes, passed to Html::element()
* @return string Raw HTML
*/
- public static function hidden( $name, $value, $attribs = array() ) {
+ public static function hidden( $name, $value, array $attribs = array() ) {
return self::input( $name, $value, 'hidden', $attribs );
}
* attributes, passed to Html::element()
* @return string Raw HTML
*/
- public static function textarea( $name, $value = '', $attribs = array() ) {
+ public static function textarea( $name, $value = '', array $attribs = array() ) {
$attribs['name'] = $name;
if ( substr( $value, 0, 1 ) == "\n" ) {
* attributes, passed to Html::element() of html tag.
* @return string Raw HTML
*/
- public static function htmlHeader( $attribs = array() ) {
+ public static function htmlHeader( array $attribs = array() ) {
$ret = '';
global $wgHtml5Version, $wgMimeType, $wgXhtmlNamespaces;
}
/**
- * Generate a srcset attribute value from an array mapping pixel densities
- * to URLs. Note that srcset supports width and height values as well, which
- * are not used here.
+ * Generate a srcset attribute value.
+ *
+ * Generates a srcset attribute value from an array mapping pixel densities
+ * to URLs. A trailing 'x' in pixel density values is optional.
+ *
+ * @note srcset width and height values are not supported.
+ *
+ * @see http://www.whatwg.org/html/embedded-content-1.html#attr-img-srcset
+ *
+ * @par Example:
+ * @code
+ * Html::srcSet( array(
+ * '1x' => 'standard.jpeg',
+ * '1.5x' => 'large.jpeg',
+ * '3x' => 'extra-large.jpeg',
+ * ) );
+ * // gives 'standard.jpeg 1x, large.jpeg 1.5x, extra-large.jpeg 2x'
+ * @endcode
*
* @param string[] $urls
* @return string
*/
- static function srcSet( $urls ) {
+ static function srcSet( array $urls ) {
$candidates = array();
foreach ( $urls as $density => $url ) {
- // Image candidate syntax per current whatwg live spec, 2012-09-23:
- // http://www.whatwg.org/html/embedded-content-1.html#attr-img-srcset
- $candidates[] = "{$url} {$density}x";
+ // Cast density to float to strip 'x'.
+ $candidates[] = $url . ' ' . (float)$density . 'x';
}
return implode( ", ", $candidates );
}