MediaWiki master
ChangesListBooleanFilter.php
Go to the documentation of this file.
1<?php
27
39 protected $showHide;
40
48
54 protected $defaultValue;
55
61 protected $queryCallable;
62
68 protected $activeValue;
69
110 public function __construct( $filterDefinition ) {
111 parent::__construct( $filterDefinition );
112
113 if ( isset( $filterDefinition['showHide'] ) ) {
114 $this->showHide = $filterDefinition['showHide'];
115 }
116
117 $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'] ?? false;
118
119 if ( isset( $filterDefinition['default'] ) ) {
120 $this->setDefault( $filterDefinition['default'] );
121 } else {
122 throw new InvalidArgumentException( 'You must set a default' );
123 }
124
125 if ( isset( $filterDefinition['queryCallable'] ) ) {
126 $this->queryCallable = $filterDefinition['queryCallable'];
127 }
128
129 $this->activeValue = $filterDefinition['activeValue'] ?? true;
130 }
131
138 public function getDefault( $structuredUI = false ) {
139 return $this->isReplacedInStructuredUi && $structuredUI ?
140 !$this->activeValue :
141 $this->defaultValue;
142 }
143
151 public function setDefault( $defaultValue ) {
152 $this->defaultValue = (bool)$defaultValue;
153 }
154
158 public function getShowHide() {
159 return $this->showHide;
160 }
161
165 public function displaysOnUnstructuredUi() {
166 return (bool)$this->showHide;
167 }
168
173 return $this->isReplacedInStructuredUi ||
174 parent::isFeatureAvailableOnStructuredUi();
175 }
176
189 public function modifyQuery( IReadableDatabase $dbr, ChangesListSpecialPage $specialPage,
190 &$tables, &$fields, &$conds, &$query_options, &$join_conds
191 ) {
192 if ( $this->queryCallable === null ) {
193 return;
194 }
195
196 ( $this->queryCallable )(
197 get_class( $specialPage ),
198 $specialPage->getContext(),
199 $dbr,
200 $tables,
201 $fields,
202 $conds,
203 $query_options,
204 $join_conds
205 );
206 }
207
211 public function getJsData() {
212 $output = parent::getJsData();
213
214 $output['default'] = $this->defaultValue;
215
216 return $output;
217 }
218
222 public function isSelected( FormOptions $opts ) {
223 return !$opts[ $this->getName() ] &&
224 array_filter(
225 $this->getSiblings(),
226 static function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
227 return $opts[ $sibling->getName() ];
228 }
229 );
230 }
231
237 public function isActive( FormOptions $opts, $isStructuredUI ) {
238 if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
239 return false;
240 }
241
242 return $opts[ $this->getName() ] === $this->activeValue;
243 }
244}
Represents a hide-based boolean filter (used on ChangesListSpecialPage and descendants)
displaysOnUnstructuredUi()
Checks whether the filter should display on the unstructured UI.bool Whether to display
isSelected(FormOptions $opts)
Checks whether this filter is selected in the provided options.bool
isActive(FormOptions $opts, $isStructuredUI)
modifyQuery(IReadableDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds)
Modifies the query to include the filter.
__construct( $filterDefinition)
Create a new filter with the specified configuration.
getJsData()
Gets the JS data required by the front-end of the structured UI.array Associative array Data required...
setDefault( $defaultValue)
Sets default.
bool $isReplacedInStructuredUi
Whether there is a feature designed to replace this filter available on the structured UI.
string $showHide
Main unstructured UI i18n key.
isFeatureAvailableOnStructuredUi()
Checks whether an equivalent feature for this filter is available on the structured UI....
bool $activeValue
Value that defined when this filter is considered active.
getDefault( $structuredUI=false)
Get the default value.
callable $queryCallable
Callable used to do the actual query modification; see constructor.
Represents a filter (used on ChangesListSpecialPage and descendants)
getSiblings()
Get filters in the same group.
Helper class to keep track of options when mixing links and form elements.
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.