MediaWiki master
ChangesListBooleanFilter.php
Go to the documentation of this file.
1<?php
8
9use InvalidArgumentException;
13
27 protected $showHide;
28
36
42 protected $defaultValue;
43
49 protected $queryCallable;
50
56 protected $activeValue;
57
98 public function __construct( $filterDefinition ) {
99 parent::__construct( $filterDefinition );
100
101 if ( isset( $filterDefinition['showHide'] ) ) {
102 $this->showHide = $filterDefinition['showHide'];
103 }
104
105 $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'] ?? false;
106
107 if ( isset( $filterDefinition['default'] ) ) {
108 $this->setDefault( $filterDefinition['default'] );
109 } else {
110 throw new InvalidArgumentException( 'You must set a default' );
111 }
112
113 if ( isset( $filterDefinition['queryCallable'] ) ) {
114 $this->queryCallable = $filterDefinition['queryCallable'];
115 }
116
117 $this->activeValue = $filterDefinition['activeValue'] ?? true;
118 }
119
126 public function getDefault( $structuredUI = false ) {
127 return $this->isReplacedInStructuredUi && $structuredUI ?
128 !$this->activeValue :
130 }
131
139 public function setDefault( $defaultValue ) {
140 $this->defaultValue = (bool)$defaultValue;
141 }
142
146 public function getShowHide() {
147 return $this->showHide;
148 }
149
153 public function displaysOnUnstructuredUi() {
154 return (bool)$this->showHide;
155 }
156
161 return $this->isReplacedInStructuredUi ||
162 parent::isFeatureAvailableOnStructuredUi();
163 }
164
177 public function modifyQuery( IReadableDatabase $dbr, ChangesListSpecialPage $specialPage,
178 &$tables, &$fields, &$conds, &$query_options, &$join_conds
179 ) {
180 if ( $this->queryCallable === null ) {
181 return;
182 }
183
185 get_class( $specialPage ),
186 $specialPage->getContext(),
187 $dbr,
188 $tables,
189 $fields,
190 $conds,
191 $query_options,
192 $join_conds
193 );
194 }
195
199 public function getJsData() {
200 $output = parent::getJsData();
201
202 $output['default'] = $this->defaultValue;
203
204 return $output;
205 }
206
210 public function isSelected( FormOptions $opts ) {
211 return !$opts[ $this->getName() ] &&
212 array_filter(
213 $this->getSiblings(),
214 static function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
215 return $opts[ $sibling->getName() ];
216 }
217 );
218 }
219
223 public function isActive( FormOptions $opts, $isStructuredUI ) {
224 if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
225 return false;
226 }
227
228 return $opts[ $this->getName() ] === $this->activeValue;
229 }
230}
231
233class_alias( ChangesListBooleanFilter::class, 'ChangesListBooleanFilter' );
Helper class to keep track of options when mixing links and form elements.
Represents a hide-based boolean filter (used on ChangesListSpecialPage and descendants)
isActive(FormOptions $opts, $isStructuredUI)
bool Whether this filter should be considered active
bool $isReplacedInStructuredUi
Whether there is a feature designed to replace this filter available on the structured UI.
modifyQuery(IReadableDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds)
Modifies the query to include the filter.
callable $queryCallable
Callable used to do the actual query modification; see constructor.
getDefault( $structuredUI=false)
Get the default value.
getJsData()
Gets the JS data required by the front-end of the structured UI.array Associative array Data required...
isFeatureAvailableOnStructuredUi()
Checks whether an equivalent feature for this filter is available on the structured UI....
isSelected(FormOptions $opts)
Checks whether this filter is selected in the provided options.bool
bool $activeValue
Value that defined when this filter is considered active.
__construct( $filterDefinition)
Create a new filter with the specified configuration.
displaysOnUnstructuredUi()
Checks whether the filter should display on the unstructured UI.bool Whether to display
Represents a filter (used on ChangesListSpecialPage and descendants)
getSiblings()
Get filters in the same group.
Special page which uses a ChangesList to show query results.
getContext()
Gets the context this SpecialPage is executed in.
A database connection without write operations.