SpecialActiveUsers: Change checkboxes to dropdown
[lhc/web/wiklou.git] / includes / FormOptions.php
index 079267a..826f3bb 100644 (file)
@@ -52,6 +52,9 @@ class FormOptions implements ArrayAccess {
         * This is useful for the namespace selector.
         */
        const INTNULL = 3;
+       /** Array type, maps guessType() to WebRequest::getArray()
+        * @since 1.28 */
+       const ARR = 5;
        /* @} */
 
        /**
@@ -64,7 +67,7 @@ class FormOptions implements ArrayAccess {
         *   consumeValue() or consumeValues()
         * - 'type' - one of the type constants (but never AUTO)
         */
-       protected $options = array();
+       protected $options = [];
 
        # Setting up
 
@@ -76,7 +79,7 @@ class FormOptions implements ArrayAccess {
         * @param int $type One of the type constants (optional, defaults to AUTO)
         */
        public function add( $name, $default, $type = self::AUTO ) {
-               $option = array();
+               $option = [];
                $option['default'] = $default;
                $option['value'] = null;
                $option['consumed'] = false;
@@ -120,6 +123,8 @@ class FormOptions implements ArrayAccess {
                        return self::FLOAT;
                } elseif ( is_string( $data ) ) {
                        return self::STRING;
+               } elseif ( is_array( $data ) ) {
+                       return self::ARR;
                } else {
                        throw new MWException( 'Unsupported datatype' );
                }
@@ -228,7 +233,7 @@ class FormOptions implements ArrayAccess {
         * @return array Array of option values, or the default values if they are null
         */
        public function consumeValues( $names ) {
-               $out = array();
+               $out = [];
 
                foreach ( $names as $name ) {
                        $this->validateName( $name, true );
@@ -278,7 +283,7 @@ class FormOptions implements ArrayAccess {
         * @return array
         */
        public function getUnconsumedValues( $all = false ) {
-               $values = array();
+               $values = [];
 
                foreach ( $this->options as $name => $data ) {
                        if ( !$data['consumed'] ) {
@@ -296,7 +301,7 @@ class FormOptions implements ArrayAccess {
         * @return array
         */
        public function getChangedValues() {
-               $values = array();
+               $values = [];
 
                foreach ( $this->options as $name => $data ) {
                        if ( $data['value'] !== null ) {
@@ -312,7 +317,7 @@ class FormOptions implements ArrayAccess {
         * @return array
         */
        public function getAllValues() {
-               $values = array();
+               $values = [];
 
                foreach ( $this->options as $name => $data ) {
                        $values[$name] = $this->getValueReal( $data );
@@ -358,6 +363,9 @@ class FormOptions implements ArrayAccess {
                                case self::INTNULL:
                                        $value = $r->getIntOrNull( $name );
                                        break;
+                               case self::ARR:
+                                       $value = $r->getArray( $name );
+                                       break;
                                default:
                                        throw new MWException( 'Unsupported datatype' );
                        }
@@ -375,6 +383,7 @@ class FormOptions implements ArrayAccess {
        /* @{ */
        /**
         * Whether the option exists.
+        * @param string $name
         * @return bool
         */
        public function offsetExists( $name ) {
@@ -383,6 +392,7 @@ class FormOptions implements ArrayAccess {
 
        /**
         * Retrieve an option value.
+        * @param string $name
         * @return mixed
         */
        public function offsetGet( $name ) {
@@ -391,6 +401,8 @@ class FormOptions implements ArrayAccess {
 
        /**
         * Set an option to given value.
+        * @param string $name
+        * @param mixed $value
         */
        public function offsetSet( $name, $value ) {
                $this->setValue( $name, $value );
@@ -398,6 +410,7 @@ class FormOptions implements ArrayAccess {
 
        /**
         * Delete the option.
+        * @param string $name
         */
        public function offsetUnset( $name ) {
                $this->delete( $name );