X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fhtmlform%2FHTMLMultiSelectField.php;h=23125bd4652a9e114bc452af1b22c507ee0078e9;hb=5f0cc1436acfbe92775c035121b9c61db9d6092d;hp=523f04550c99909a7fdebc7a2fd094dcb764a96e;hpb=5de749d207b9ca7f15cd7ecb40f4c3a05f07f764;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/HTMLMultiSelectField.php b/includes/htmlform/HTMLMultiSelectField.php index 523f04550c..23125bd465 100644 --- a/includes/htmlform/HTMLMultiSelectField.php +++ b/includes/htmlform/HTMLMultiSelectField.php @@ -37,24 +37,24 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable function formatOptions( $options, $value ) { $html = ''; - $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) ); + $attribs = $this->getAttributes( [ 'disabled', 'tabindex' ] ); foreach ( $options as $label => $info ) { if ( is_array( $info ) ) { - $html .= Html::rawElement( 'h1', array(), $label ) . "\n"; + $html .= Html::rawElement( 'h1', [], $label ) . "\n"; $html .= $this->formatOptions( $info, $value ); } else { - $thisAttribs = array( + $thisAttribs = [ 'id' => "{$this->mID}-$info", 'value' => $info, - ); + ]; $checked = in_array( $info, $value, true ); $checkbox = $this->getOneCheckbox( $checked, $attribs + $thisAttribs, $label ); $html .= ' ' . Html::rawElement( 'div', - array( 'class' => 'mw-htmlform-flatlist-item' ), + [ 'class' => 'mw-htmlform-flatlist-item' ], $checkbox ); } @@ -65,32 +65,19 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable protected function getOneCheckbox( $checked, $attribs, $label ) { if ( $this->mParent instanceof OOUIHTMLForm ) { - if ( $this->mOptionsLabelsNotFromMessage ) { - $label = new OOUI\HtmlSnippet( $label ); - } - return new OOUI\FieldLayout( - new OOUI\CheckboxInputWidget( array( - 'name' => "{$this->mName}[]", - 'selected' => $checked, - 'value' => $attribs['value'], - ) + $attribs ), - array( - 'label' => $label, - 'align' => 'inline', - ) - ); + throw new MWException( 'HTMLMultiSelectField#getOneCheckbox() is not supported' ); } else { - $elementFunc = array( 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' ); + $elementFunc = [ 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' ]; $checkbox = Xml::check( "{$this->mName}[]", $checked, $attribs ) . ' ' . call_user_func( $elementFunc, 'label', - array( 'for' => $attribs['id'] ), + [ 'for' => $attribs['id'] ], $label ); if ( $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' ) ) { - $checkbox = Html::openElement( 'div', array( 'class' => 'mw-ui-checkbox' ) ) . + $checkbox = Html::openElement( 'div', [ 'class' => 'mw-ui-checkbox' ] ) . $checkbox . Html::closeElement( 'div' ); } @@ -98,6 +85,38 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable } } + /** + * Get the OOUI version of this field. + * + * @since 1.28 + * @param string[] $value + * @return OOUI\CheckboxMultiselectInputWidget + */ + public function getInputOOUI( $value ) { + $attr = $this->getTooltipAndAccessKey(); + $attr['id'] = $this->mID; + $attr['name'] = "{$this->mName}[]"; + + $attr['value'] = $value; + $attr['options'] = $this->getOptionsOOUI(); + + if ( $this->mOptionsLabelsNotFromMessage ) { + foreach ( $attr['options'] as &$option ) { + $option['label'] = new OOUI\HtmlSnippet( $option['label'] ); + } + } + + $attr += OOUI\Element::configFromHtmlAttributes( + $this->getAttributes( [ 'disabled', 'tabindex' ] ) + ); + + if ( $this->mClass !== '' ) { + $attr['classes'] = [ $this->mClass ]; + } + + return new OOUI\CheckboxMultiselectInputWidget( $attr ); + } + /** * @param WebRequest $request * @@ -108,7 +127,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable if ( $request->wasPosted() ) { # Checkboxes are just not added to the request arrays if they're not checked, # so it's perfectly possible for there not to be an entry at all - return $request->getArray( $this->mName, array() ); + return $request->getArray( $this->mName, [] ); } else { # That's ok, the user has not yet submitted the form, so show the defaults return $this->getDefault(); @@ -120,7 +139,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable # latter, which basically means that you can't specify 'positive' defaults # for GET forms. # @todo FIXME... - return $request->getArray( $this->mName, array() ); + return $request->getArray( $this->mName, [] ); } } @@ -128,7 +147,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable if ( isset( $this->mDefault ) ) { return $this->mDefault; } else { - return array(); + return []; } } @@ -136,7 +155,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable $data = HTMLFormField::forceToStringRecursive( $data ); $options = HTMLFormField::flattenOptions( $this->getOptions() ); - $res = array(); + $res = []; foreach ( $options as $opt ) { $res["$opt"] = in_array( $opt, $data, true ); }