MediaWiki master
ChangesListBooleanFilter.php
Go to the documentation of this file.
1<?php
24
38 protected $showHide;
39
47
53 protected $defaultValue;
54
60 protected $queryCallable;
61
67 protected $activeValue;
68
109 public function __construct( $filterDefinition ) {
110 parent::__construct( $filterDefinition );
111
112 if ( isset( $filterDefinition['showHide'] ) ) {
113 $this->showHide = $filterDefinition['showHide'];
114 }
115
116 $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'] ?? false;
117
118 if ( isset( $filterDefinition['default'] ) ) {
119 $this->setDefault( $filterDefinition['default'] );
120 } else {
121 throw new InvalidArgumentException( 'You must set a default' );
122 }
123
124 if ( isset( $filterDefinition['queryCallable'] ) ) {
125 $this->queryCallable = $filterDefinition['queryCallable'];
126 }
127
128 $this->activeValue = $filterDefinition['activeValue'] ?? true;
129 }
130
137 public function getDefault( $structuredUI = false ) {
138 return $this->isReplacedInStructuredUi && $structuredUI ?
139 !$this->activeValue :
140 $this->defaultValue;
141 }
142
150 public function setDefault( $defaultValue ) {
151 $this->defaultValue = (bool)$defaultValue;
152 }
153
157 public function getShowHide() {
158 return $this->showHide;
159 }
160
164 public function displaysOnUnstructuredUi() {
165 return (bool)$this->showHide;
166 }
167
172 return $this->isReplacedInStructuredUi ||
173 parent::isFeatureAvailableOnStructuredUi();
174 }
175
188 public function modifyQuery( IReadableDatabase $dbr, ChangesListSpecialPage $specialPage,
189 &$tables, &$fields, &$conds, &$query_options, &$join_conds
190 ) {
191 if ( $this->queryCallable === null ) {
192 return;
193 }
194
195 ( $this->queryCallable )(
196 get_class( $specialPage ),
197 $specialPage->getContext(),
198 $dbr,
199 $tables,
200 $fields,
201 $conds,
202 $query_options,
203 $join_conds
204 );
205 }
206
210 public function getJsData() {
211 $output = parent::getJsData();
212
213 $output['default'] = $this->defaultValue;
214
215 return $output;
216 }
217
221 public function isSelected( FormOptions $opts ) {
222 return !$opts[ $this->getName() ] &&
223 array_filter(
224 $this->getSiblings(),
225 static function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
226 return $opts[ $sibling->getName() ];
227 }
228 );
229 }
230
236 public function isActive( FormOptions $opts, $isStructuredUI ) {
237 if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
238 return false;
239 }
240
241 return $opts[ $this->getName() ] === $this->activeValue;
242 }
243}
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.