X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHtml.php;h=62ae0b85913b249da929d4957e4a1fd5fd33037e;hb=9c0a43600e9eff4a1a8e24ef0604ab6c0d69c0e8;hp=6907245bc35e2f962394e92fbdfb070fb2d21052;hpb=96366c1cf1966ca07e8f0b4361bbca28bfaf43a0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Html.php b/includes/Html.php index 6907245bc3..62ae0b8591 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -104,8 +104,8 @@ class Html { /** * Modifies a set of attributes meant for button elements * and apply a set of default attributes when $wgUseMediaWikiUIEverywhere enabled. - * @param array $attrs - * @param string[] $modifiers to add to the button + * @param array $attrs HTML attributes in an associative array + * @param string[] $modifiers classes to add to the button * @see https://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers * @return array $attrs A modified attribute array */ @@ -115,16 +115,15 @@ class Html { if ( isset( $attrs['class'] ) ) { if ( is_array( $attrs['class'] ) ) { $attrs['class'][] = 'mw-ui-button'; - $attrs = array_merge( $attrs, $modifiers ); + $attrs['class'] = array_merge( $attrs['class'], $modifiers ); // ensure compatibility with Xml $attrs['class'] = implode( ' ', $attrs['class'] ); } else { $attrs['class'] .= ' mw-ui-button ' . implode( ' ', $modifiers ); } } else { - $attrs['class'] = array( 'mw-ui-button' ); // ensure compatibility with Xml - $attrs['class'] = implode( ' ', array_merge( $attrs['class'], $modifiers ) ); + $attrs['class'] = 'mw-ui-button ' . implode( ' ', $modifiers ); } } return $attrs; @@ -162,7 +161,7 @@ class Html { * @param array $attrs Associative array of attributes, e.g., array( * 'href' => 'http://www.mediawiki.org/' ). See expandAttributes() for * further documentation. - * @param string[] $modifiers to add to the button + * @param string[] $modifiers classes to add to the button * @see http://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers * @return string Raw HTML */ @@ -182,7 +181,7 @@ class Html { * @param array $attrs Associative array of attributes, e.g., array( * 'href' => 'http://www.mediawiki.org/' ). See expandAttributes() for * further documentation. - * @param string[] $modifiers to add to the button + * @param string[] $modifiers classes to add to the button * @see http://tools.wmflabs.org/styleguide/desktop/index.html for guidance on available modifiers * @return string Raw HTML */ @@ -716,6 +715,9 @@ class Html { if ( in_array( $type, array( 'text', 'search', 'email', 'password', 'number' ) ) ) { $attribs = self::getTextInputAttributes( $attribs ); } + if ( in_array( $type, array( 'button', 'reset', 'submit' ) ) ) { + $attribs = self::buttonAttributes( $attribs ); + } return self::element( 'input', $attribs ); } @@ -820,6 +822,47 @@ class Html { return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue ); } + /** + * Helper for Html::namespaceSelector(). + * @param array $params See Html::namespaceSelector() + * @return array + */ + public static function namespaceSelectorOptions( array $params = array() ) { + global $wgContLang; + + $options = array(); + + if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) { + $params['exclude'] = array(); + } + + if ( isset( $params['all'] ) ) { + // add an option that would let the user select all namespaces. + // Value is provided by user, the name shown is localized for the user. + $options[$params['all']] = wfMessage( 'namespacesall' )->text(); + } + // Add all namespaces as options (in the content language) + $options += $wgContLang->getFormattedNamespaces(); + + $optionsOut = array(); + // Filter out namespaces below 0 and massage labels + foreach ( $options as $nsId => $nsName ) { + if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) { + continue; + } + if ( $nsId === NS_MAIN ) { + // For other namespaces use the namespace prefix as label, but for + // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)") + $nsName = wfMessage( 'blanknamespace' )->text(); + } elseif ( is_int( $nsId ) ) { + $nsName = $wgContLang->convertNamespace( $nsId ); + } + $optionsOut[ $nsId ] = $nsName; + } + + return $optionsOut; + } + /** * Build a drop-down box for selecting a namespace * @@ -839,8 +882,6 @@ class Html { public static function namespaceSelector( array $params = array(), array $selectAttribs = array() ) { - global $wgContLang; - ksort( $selectAttribs ); // Is a namespace selected? @@ -857,37 +898,16 @@ class Html { $params['selected'] = ''; } - if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) { - $params['exclude'] = array(); - } if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) { $params['disable'] = array(); } // Associative array between option-values and option-labels - $options = array(); + $options = self::namespaceSelectorOptions( $params ); - if ( isset( $params['all'] ) ) { - // add an option that would let the user select all namespaces. - // Value is provided by user, the name shown is localized for the user. - $options[$params['all']] = wfMessage( 'namespacesall' )->text(); - } - // Add all namespaces as options (in the content language) - $options += $wgContLang->getFormattedNamespaces(); - - // Convert $options to HTML and filter out namespaces below 0 + // Convert $options to HTML $optionsHtml = array(); foreach ( $options as $nsId => $nsName ) { - if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) { - continue; - } - if ( $nsId === NS_MAIN ) { - // For other namespaces use the namespace prefix as label, but for - // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)") - $nsName = wfMessage( 'blanknamespace' )->text(); - } elseif ( is_int( $nsId ) ) { - $nsName = $wgContLang->convertNamespace( $nsId ); - } $optionsHtml[] = self::element( 'option', array( 'disabled' => in_array( $nsId, $params['disable'] ),