Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/199849
Change subject: Add array type hints to minor methods in the Html class ...................................................................... Add array type hints to minor methods in the Html class I'm aware that adding these type hints does have the potential of beeing a breaking change if a caller misuses it. Note that it really is a misuse in this case because all these parameters are documented as "array" and nothing else. I double-checked the usages of all methods I touched and could not find any caller that does not fulfill the contract of these methods - in other words, all callers I can find in my local code base (which includes all major extensions like Echo, Flow, Parsoid, VisualEditor and so on) pass arrays to these parameters. I left the main methods openElement, rawElement and so on untouched because they are called way to often (500 times and more). Change-Id: I5ca13b26fb08d732ce4cadc4ee3d38314e606fd3 --- M includes/Html.php 1 file changed, 11 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/49/199849/1 diff --git a/includes/Html.php b/includes/Html.php index 6bd661f..606e0db 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -109,7 +109,7 @@ * @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'] ) ) { @@ -137,11 +137,8 @@ * @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'] ) ) { @@ -169,7 +166,7 @@ * @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 Html::element( 'a', self::buttonAttributes( $attrs, $modifiers ), $contents @@ -189,7 +186,7 @@ * @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 Html::element( 'input', self::buttonAttributes( $attrs, $modifiers ) ); @@ -337,8 +334,7 @@ * 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( @@ -485,11 +481,10 @@ * @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 ) ) { @@ -711,7 +706,7 @@ * 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; @@ -791,7 +786,7 @@ * 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 ); } @@ -807,7 +802,7 @@ * 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" ) { @@ -934,7 +929,7 @@ * 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; @@ -1029,7 +1024,7 @@ * @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: -- To view, visit https://gerrit.wikimedia.org/r/199849 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5ca13b26fb08d732ce4cadc4ee3d38314e606fd3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits