Make autopatrol third option in rc_patrolled and use it in API
[lhc/web/wiklou.git] / includes / changes / ChangesListBooleanFilter.php
index dd62d7f..f37ed2d 100644 (file)
  * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
- * @license GPL 2+
  * @author Matthew Flaschen
  */
 
 use Wikimedia\Rdbms\IDatabase;
 
 /**
- * An individual filter in a boolean group
+ * Represents a hide-based boolean filter (used on ChangesListSpecialPage and descendants)
  *
  * @since 1.29
  */
@@ -127,7 +126,7 @@ class ChangesListBooleanFilter extends ChangesListFilter {
                }
 
                if ( isset( $filterDefinition['default'] ) ) {
-                       $this->defaultValue = $filterDefinition['default'];
+                       $this->setDefault( $filterDefinition['default'] );
                } else {
                        throw new MWException( 'You must set a default' );
                }
@@ -156,12 +155,14 @@ class ChangesListBooleanFilter extends ChangesListFilter {
        }
 
        /**
-        * Sets default
+        * Sets default.  It must be a boolean.
+        *
+        * It will be coerced to boolean.
         *
         * @param bool $defaultValue
         */
        public function setDefault( $defaultValue ) {
-               $this->defaultValue = $defaultValue;
+               $this->defaultValue = (bool)$defaultValue;
        }
 
        /**
@@ -235,11 +236,11 @@ class ChangesListBooleanFilter extends ChangesListFilter {
         * @inheritDoc
         */
        public function isSelected( FormOptions $opts ) {
-               return !$this->getValue( $opts ) &&
+               return !$opts[ $this->getName() ] &&
                        array_filter(
                                $this->getSiblings(),
                                function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
-                                       return $sibling->getValue( $opts );
+                                       return $opts[ $sibling->getName() ];
                                }
                        );
        }
@@ -254,14 +255,6 @@ class ChangesListBooleanFilter extends ChangesListFilter {
                        return false;
                }
 
-               return $this->getValue( $opts ) === $this->activeValue;
-       }
-
-       /**
-        * @param FormOptions $opts
-        * @return bool The current value of this filter according to $opts but coerced to boolean
-        */
-       public function getValue( FormOptions $opts ) {
-               return (bool)$opts[ $this->getName() ];
+               return $opts[ $this->getName() ] === $this->activeValue;
        }
 }