Merge "Batch request titles for cdn purge from db"
[lhc/web/wiklou.git] / includes / changes / ChangesListBooleanFilter.php
index 01e67f5..913bd38 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
@@ -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,7 +151,7 @@ class ChangesListBooleanFilter extends ChangesListFilter {
         */
        public function getDefault( $structuredUI = false ) {
                return $this->isReplacedInStructuredUi && $structuredUI ?
-                       false :
+                       !$this->activeValue :
                        $this->defaultValue;
        }
 
@@ -225,4 +240,17 @@ class ChangesListBooleanFilter extends ChangesListFilter {
                                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;
+       }
 }