Merge "Add .pipeline/ with dev image variant"
[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 * @method ChangesListBooleanFilter[] getFilters()
12 */
13 class ChangesListBooleanFilterGroup extends ChangesListFilterGroup {
14 /**
15 * Type marker, used by JavaScript
16 */
17 const TYPE = 'send_unselected_if_any';
18
19 /**
20 * Create a new filter group with the specified configuration
21 *
22 * @param array $groupDefinition Configuration of group
23 * * $groupDefinition['name'] string Group name
24 * * $groupDefinition['title'] string i18n key for title (optional, can be omitted
25 * only if none of the filters in the group display in the structured UI)
26 * * $groupDefinition['priority'] int Priority integer. Higher means higher in the
27 * group list.
28 * * $groupDefinition['filters'] array Numeric array of filter definitions, each of which
29 * is an associative array to be passed to the filter constructor. However,
30 * 'priority' is optional for the filters. Any filter that has priority unset
31 * will be put to the bottom, in the order given.
32 * * $groupDefinition['whatsThisHeader'] string i18n key for header of "What's
33 * This" popup (optional).
34 * * $groupDefinition['whatsThisBody'] string i18n key for body of "What's This"
35 * popup (optional).
36 * * $groupDefinition['whatsThisUrl'] string URL for main link of "What's This"
37 * popup (optional).
38 * * $groupDefinition['whatsThisLinkText'] string i18n key of text for main link of
39 * "What's This" popup (optional).
40 */
41 public function __construct( array $groupDefinition ) {
42 $groupDefinition['isFullCoverage'] = true;
43 $groupDefinition['type'] = self::TYPE;
44
45 parent::__construct( $groupDefinition );
46 }
47
48 /**
49 * @inheritDoc
50 */
51 protected function createFilter( array $filterDefinition ) {
52 return new ChangesListBooleanFilter( $filterDefinition );
53 }
54
55 /**
56 * Registers a filter in this group
57 *
58 * @param ChangesListBooleanFilter $filter
59 * @suppress PhanParamSignaturePHPDocMismatchHasParamType,PhanParamSignatureMismatch
60 */
61 public function registerFilter( ChangesListBooleanFilter $filter ) {
62 $this->filters[$filter->getName()] = $filter;
63 }
64
65 /**
66 * @inheritDoc
67 */
68 public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
69 &$tables, &$fields, &$conds, &$query_options, &$join_conds,
70 FormOptions $opts, $isStructuredFiltersEnabled
71 ) {
72 /** @var ChangesListBooleanFilter $filter */
73 foreach ( $this->getFilters() as $filter ) {
74 if ( $filter->isActive( $opts, $isStructuredFiltersEnabled ) ) {
75 $filter->modifyQuery( $dbr, $specialPage, $tables, $fields, $conds,
76 $query_options, $join_conds );
77 }
78 }
79 }
80
81 /**
82 * @inheritDoc
83 */
84 public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) {
85 /** @var ChangesListBooleanFilter $filter */
86 foreach ( $this->getFilters() as $filter ) {
87 $defaultValue = $allowDefaults ? $filter->getDefault( $isStructuredFiltersEnabled ) : false;
88 $opts->add( $filter->getName(), $defaultValue );
89 }
90 }
91 }