Merge "registration: Only allow one extension to set a specific config setting"
[lhc/web/wiklou.git] / includes / changes / ChangesListBooleanFilterGroup.php
1 <?php
2
3 use Wikimedia\Rdbms\IDatabase;
4
5 /**
6 * If the group is active, any unchecked filters will
7 * translate to hide parameters in the URL. E.g. if 'Human (not bot)' is checked,
8 * but 'Bot' is unchecked, hidebots=1 will be sent.
9 *
10 * @since 1.29
11 */
12 class ChangesListBooleanFilterGroup extends ChangesListFilterGroup {
13 /**
14 * Type marker, used by JavaScript
15 */
16 const TYPE = 'send_unselected_if_any';
17
18 /**
19 * Create a new filter group with the specified configuration
20 *
21 * @param array $groupDefinition Configuration of group
22 * * $groupDefinition['name'] string Group name
23 * * $groupDefinition['title'] string i18n key for title (optional, can be omitted
24 * only if none of the filters in the group display in the structured UI)
25 * * $groupDefinition['priority'] int Priority integer. Higher means higher in the
26 * group list.
27 * * $groupDefinition['filters'] array Numeric array of filter definitions, each of which
28 * is an associative array to be passed to the filter constructor. However,
29 * 'priority' is optional for the filters. Any filter that has priority unset
30 * will be put to the bottom, in the order given.
31 * * $groupDefinition['whatsThisHeader'] string i18n key for header of "What's
32 * This" popup (optional).
33 * * $groupDefinition['whatsThisBody'] string i18n key for body of "What's This"
34 * popup (optional).
35 * * $groupDefinition['whatsThisUrl'] string URL for main link of "What's This"
36 * popup (optional).
37 * * $groupDefinition['whatsThisLinkText'] string i18n key of text for main link of
38 * "What's This" popup (optional).
39 */
40 public function __construct( array $groupDefinition ) {
41 $groupDefinition['isFullCoverage'] = true;
42 $groupDefinition['type'] = self::TYPE;
43
44 parent::__construct( $groupDefinition );
45 }
46
47 /**
48 * @inheritDoc
49 */
50 protected function createFilter( array $filterDefinition ) {
51 return new ChangesListBooleanFilter( $filterDefinition );
52 }
53
54 /**
55 * Registers a filter in this group
56 *
57 * @param ChangesListBooleanFilter $filter ChangesListBooleanFilter
58 */
59 public function registerFilter( ChangesListBooleanFilter $filter ) {
60 $this->filters[$filter->getName()] = $filter;
61 }
62
63 /**
64 * @inheritDoc
65 */
66 public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
67 &$tables, &$fields, &$conds, &$query_options, &$join_conds,
68 FormOptions $opts, $isStructuredFiltersEnabled
69 ) {
70 /** @var ChangesListBooleanFilter $filter */
71 foreach ( $this->getFilters() as $filter ) {
72 if ( $filter->isActive( $opts, $isStructuredFiltersEnabled ) ) {
73 $filter->modifyQuery( $dbr, $specialPage, $tables, $fields, $conds,
74 $query_options, $join_conds );
75 }
76 }
77 }
78
79 /**
80 * @inheritDoc
81 */
82 public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) {
83 /** @var ChangesListBooleanFilter $filter */
84 foreach ( $this->getFilters() as $filter ) {
85 $defaultValue = $allowDefaults ? $filter->getDefault( $isStructuredFiltersEnabled ) : false;
86 $opts->add( $filter->getName(), $defaultValue );
87 }
88 }
89 }