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