MediaWiki master
ChangesListBooleanFilter.php
Go to the documentation of this file.
1<?php
22
23use InvalidArgumentException;
27
41 protected $showHide;
42
50
56 protected $defaultValue;
57
63 protected $queryCallable;
64
70 protected $activeValue;
71
112 public function __construct( $filterDefinition ) {
113 parent::__construct( $filterDefinition );
114
115 if ( isset( $filterDefinition['showHide'] ) ) {
116 $this->showHide = $filterDefinition['showHide'];
117 }
118
119 $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'] ?? false;
120
121 if ( isset( $filterDefinition['default'] ) ) {
122 $this->setDefault( $filterDefinition['default'] );
123 } else {
124 throw new InvalidArgumentException( 'You must set a default' );
125 }
126
127 if ( isset( $filterDefinition['queryCallable'] ) ) {
128 $this->queryCallable = $filterDefinition['queryCallable'];
129 }
130
131 $this->activeValue = $filterDefinition['activeValue'] ?? true;
132 }
133
140 public function getDefault( $structuredUI = false ) {
141 return $this->isReplacedInStructuredUi && $structuredUI ?
142 !$this->activeValue :
144 }
145
153 public function setDefault( $defaultValue ) {
154 $this->defaultValue = (bool)$defaultValue;
155 }
156
160 public function getShowHide() {
161 return $this->showHide;
162 }
163
167 public function displaysOnUnstructuredUi() {
168 return (bool)$this->showHide;
169 }
170
175 return $this->isReplacedInStructuredUi ||
176 parent::isFeatureAvailableOnStructuredUi();
177 }
178
191 public function modifyQuery( IReadableDatabase $dbr, ChangesListSpecialPage $specialPage,
192 &$tables, &$fields, &$conds, &$query_options, &$join_conds
193 ) {
194 if ( $this->queryCallable === null ) {
195 return;
196 }
197
199 get_class( $specialPage ),
200 $specialPage->getContext(),
201 $dbr,
202 $tables,
203 $fields,
204 $conds,
205 $query_options,
206 $join_conds
207 );
208 }
209
213 public function getJsData() {
214 $output = parent::getJsData();
215
216 $output['default'] = $this->defaultValue;
217
218 return $output;
219 }
220
224 public function isSelected( FormOptions $opts ) {
225 return !$opts[ $this->getName() ] &&
226 array_filter(
227 $this->getSiblings(),
228 static function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
229 return $opts[ $sibling->getName() ];
230 }
231 );
232 }
233
239 public function isActive( FormOptions $opts, $isStructuredUI ) {
240 if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
241 return false;
242 }
243
244 return $opts[ $this->getName() ] === $this->activeValue;
245 }
246}
247
249class_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)
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.