Move MediaHandler defaults out of global scope
[lhc/web/wiklou.git] / includes / htmlform / HTMLMultiSelectField.php
index 1aaa3e8..a231b2f 100644 (file)
@@ -65,21 +65,7 @@ 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( [
-                                       'name' => "{$this->mName}[]",
-                                       'selected' => $checked,
-                               ] + OOUI\Element::configFromHtmlAttributes(
-                                       $attribs
-                               ) ),
-                               [
-                                       'label' => $label,
-                                       'align' => 'inline',
-                               ]
-                       );
+                       throw new MWException( 'HTMLMultiSelectField#getOneCheckbox() is not supported' );
                } else {
                        $elementFunc = [ 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' ];
                        $checkbox =
@@ -99,29 +85,51 @@ 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
         *
         * @return string
         */
        function loadDataFromRequest( $request ) {
-               if ( $this->mParent->getMethod() == 'post' ) {
-                       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, [] );
-                       } else {
-                               # That's ok, the user has not yet submitted the form, so show the defaults
-                               return $this->getDefault();
-                       }
-               } else {
-                       # This is the impossible case: if we look at $_GET and see no data for our
-                       # field, is it because the user has not yet submitted the form, or that they
-                       # have submitted it with all the options unchecked? We will have to assume the
-                       # latter, which basically means that you can't specify 'positive' defaults
-                       # for GET forms.
-                       # @todo FIXME...
+               if ( $this->isSubmitAttempt( $request ) ) {
+                       // 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, [] );
+               } else {
+                       // That's ok, the user has not yet submitted the form, so show the defaults
+                       return $this->getDefault();
                }
        }