Merge "Improve "selfmove" message's wording"
[lhc/web/wiklou.git] / includes / changes / ChangesListBooleanFilter.php
index 930269c..2a7ba88 100644 (file)
@@ -66,6 +66,13 @@ class ChangesListBooleanFilter extends ChangesListFilter {
         */
        protected $queryCallable;
 
+       /**
+        * Value that defined when this filter is considered active
+        *
+        * @var bool $activeValue
+        */
+       protected $activeValue;
+
        /**
         * Create a new filter with the specified configuration.
         *
@@ -90,6 +97,8 @@ class ChangesListBooleanFilter extends ChangesListFilter {
         *     to true.  It does not need to be set if the exact same filter is simply visible
         *     on both.
         * * $filterDefinition['default'] bool Default
+        * * $filterDefinition['activeValue'] bool This filter is considered active when
+        *     its value is equal to its activeValue. Default is true.
         * * $filterDefinition['priority'] int Priority integer.  Higher value means higher
         *     up in the group's filter list.
         * * $filterDefinition['queryCallable'] callable Callable accepting parameters, used
@@ -118,7 +127,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' );
                }
@@ -126,6 +135,12 @@ class ChangesListBooleanFilter extends ChangesListFilter {
                if ( isset( $filterDefinition['queryCallable'] ) ) {
                        $this->queryCallable = $filterDefinition['queryCallable'];
                }
+
+               if ( isset( $filterDefinition['activeValue'] ) ) {
+                       $this->activeValue = $filterDefinition['activeValue'];
+               } else {
+                       $this->activeValue = true;
+               }
        }
 
        /**
@@ -136,17 +151,19 @@ class ChangesListBooleanFilter extends ChangesListFilter {
         */
        public function getDefault( $structuredUI = false ) {
                return $this->isReplacedInStructuredUi && $structuredUI ?
-                       false :
+                       !$this->activeValue :
                        $this->defaultValue;
        }
 
        /**
-        * 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;
        }
 
        /**
@@ -157,14 +174,14 @@ class ChangesListBooleanFilter extends ChangesListFilter {
        }
 
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        public function displaysOnUnstructuredUi() {
                return !!$this->showHide;
        }
 
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        public function isFeatureAvailableOnStructuredUi() {
                return $this->isReplacedInStructuredUi ||
@@ -206,7 +223,7 @@ class ChangesListBooleanFilter extends ChangesListFilter {
        }
 
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        public function getJsData() {
                $output = parent::getJsData();
@@ -217,12 +234,28 @@ class ChangesListBooleanFilter extends ChangesListFilter {
        }
 
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        public function isSelected( FormOptions $opts ) {
                return !$opts[ $this->getName() ] &&
-                       array_filter( $this->getSiblings(), function ( $sibling ) use ( $opts ) {
-                               return $opts[ $sibling->getName() ];
-                       } );
+                       array_filter(
+                               $this->getSiblings(),
+                               function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
+                                       return $opts[ $sibling->getName() ];
+                               }
+                       );
+       }
+
+       /**
+        * @param FormOptions $opts Query parameters merged with defaults
+        * @param bool $isStructuredUI Whether the structured UI is currently enabled
+        * @return bool Whether this filter should be considered active
+        */
+       public function isActive( FormOptions $opts, $isStructuredUI ) {
+               if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
+                       return false;
+               }
+
+               return $opts[ $this->getName() ] === $this->activeValue;
        }
 }