RCFilters: define consistent interface in ChangesListFilterGroup
[lhc/web/wiklou.git] / includes / changes / ChangesListBooleanFilterGroup.php
index 1fdcd00..7bab97b 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Wikimedia\Rdbms\IDatabase;
+
 /**
  * If the group is active, any unchecked filters will
  * translate to hide parameters in the URL.  E.g. if 'Human (not bot)' is checked,
@@ -19,13 +21,21 @@ class ChangesListBooleanFilterGroup extends ChangesListFilterGroup {
         * @param array $groupDefinition Configuration of group
         * * $groupDefinition['name'] string Group name
         * * $groupDefinition['title'] string i18n key for title (optional, can be omitted
-        * *  only if none of the filters in the group display in the structured UI)
+        *     only if none of the filters in the group display in the structured UI)
         * * $groupDefinition['priority'] int Priority integer.  Higher means higher in the
-        * *  group list.
+        *     group list.
         * * $groupDefinition['filters'] array Numeric array of filter definitions, each of which
-        * *  is an associative array to be passed to the filter constructor.  However,
-        * *  'priority' is optional for the filters.  Any filter that has priority unset
-        * *  will be put to the bottom, in the order given.
+        *     is an associative array to be passed to the filter constructor.  However,
+        *    'priority' is optional for the filters.  Any filter that has priority unset
+        *     will be put to the bottom, in the order given.
+        * * $groupDefinition['whatsThisHeader'] string i18n key for header of "What's
+        *     This" popup (optional).
+        * * $groupDefinition['whatsThisBody'] string i18n key for body of "What's This"
+        *     popup (optional).
+        * * $groupDefinition['whatsThisUrl'] string URL for main link of "What's This"
+        *     popup (optional).
+        * * $groupDefinition['whatsThisLinkText'] string i18n key of text for main link of
+        *     "What's This" popup (optional).
         */
        public function __construct( array $groupDefinition ) {
                $groupDefinition['isFullCoverage'] = true;
@@ -35,7 +45,7 @@ class ChangesListBooleanFilterGroup extends ChangesListFilterGroup {
        }
 
        /**
-        * @inheritdoc
+        * @inheritDoc
         */
        protected function createFilter( array $filterDefinition ) {
                return new ChangesListBooleanFilter( $filterDefinition );
@@ -51,9 +61,29 @@ class ChangesListBooleanFilterGroup extends ChangesListFilterGroup {
        }
 
        /**
-        * @inheritdoc
+        * @inheritDoc
+        */
+       public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
+               &$tables, &$fields, &$conds, &$query_options, &$join_conds,
+               FormOptions $opts, $isStructuredFiltersEnabled
+       ) {
+               /** @var ChangesListBooleanFilter $filter */
+               foreach ( $this->getFilters() as $filter ) {
+                       if ( $filter->isActive( $opts, $isStructuredFiltersEnabled ) ) {
+                               $filter->modifyQuery( $dbr, $specialPage, $tables, $fields, $conds,
+                                       $query_options, $join_conds );
+                       }
+               }
+       }
+
+       /**
+        * @inheritDoc
         */
-       public function isPerGroupRequestParameter() {
-               return false;
+       public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) {
+               /** @var ChangesListBooleanFilter $filter */
+               foreach ( $this->getFilters() as $filter ) {
+                       $defaultValue = $allowDefaults ? $filter->getDefault( $isStructuredFiltersEnabled ) : false;
+                       $opts->add( $filter->getName(), $defaultValue );
+               }
        }
 }