MediaWiki master
ChangesListBooleanFilterGroup.php
Go to the documentation of this file.
1<?php
2
4
5use InvalidArgumentException;
9
24 public const TYPE = 'send_unselected_if_any';
25
48 public function __construct( array $groupDefinition ) {
49 $groupDefinition['isFullCoverage'] = true;
50 $groupDefinition['type'] = self::TYPE;
51
52 parent::__construct( $groupDefinition );
53 }
54
58 protected function createFilter( array $filterDefinition ) {
59 return new ChangesListBooleanFilter( $filterDefinition );
60 }
61
66 public function setDefault( $defaultValue ) {
67 if ( !is_array( $defaultValue ) ) {
68 throw new InvalidArgumentException(
69 "Can't set the default of filter options group \"{$this->getName()}\"" .
70 ' to a value of type "' . gettype( $defaultValue ) . ': expected bool[]' );
71 }
72 foreach ( $defaultValue as $name => $value ) {
73 if ( !is_bool( $value ) ) {
74 throw new InvalidArgumentException(
75 "Can't set the default of filter option \"{$this->getName()}/$name\"" .
76 ' to a value of type "' . gettype( $value ) . ': expected bool' );
77 }
78 $this->getFilter( $name )?->setDefault( $value );
79 }
80 }
81
88 public function registerFilter( ChangesListBooleanFilter $filter ) {
89 $this->filters[$filter->getName()] = $filter;
90 }
91
95 public function modifyQuery( IReadableDatabase $dbr, ChangesListSpecialPage $specialPage,
96 &$tables, &$fields, &$conds, &$query_options, &$join_conds,
97 FormOptions $opts, $isStructuredFiltersEnabled
98 ) {
99 foreach ( $this->getFilters() as $filter ) {
100 if ( $filter->isActive( $opts, $isStructuredFiltersEnabled ) ) {
101 $filter->modifyQuery( $dbr, $specialPage, $tables, $fields, $conds,
102 $query_options, $join_conds );
103 }
104 }
105 }
106
110 public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) {
111 foreach ( $this->getFilters() as $filter ) {
112 $defaultValue = $allowDefaults ? $filter->getDefault( $isStructuredFiltersEnabled ) : false;
113 $opts->add( $filter->getName(), $defaultValue );
114 }
115 }
116}
117
119class_alias( ChangesListBooleanFilterGroup::class, 'ChangesListBooleanFilterGroup' );
Helper class to keep track of options when mixing links and form elements.
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
If the group is active, any unchecked filters will translate to hide parameters in the URL.
addOptions(FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled)
Add all the options represented by this filter group to $opts.
registerFilter(ChangesListBooleanFilter $filter)
Registers a filter in this group.
modifyQuery(IReadableDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, $isStructuredFiltersEnabled)
Modifies the query to include the filter group (legacy interface).The modification is only done if th...
createFilter(array $filterDefinition)
Creates a filter of the appropriate type for this group, from the definition.ChangesListFilter Filter
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
Represents a hide-based boolean filter (used on ChangesListSpecialPage and descendants)
Represents a filter group (used on ChangesListSpecialPage and descendants)
Special page which uses a ChangesList to show query results.
A database connection without write operations.