MediaWiki REL1_39
ChangesListBooleanFilter.php
Go to the documentation of this file.
1<?php
25
37 protected $showHide;
38
46
52 protected $defaultValue;
53
59 protected $queryCallable;
60
66 protected $activeValue;
67
108 public function __construct( $filterDefinition ) {
109 parent::__construct( $filterDefinition );
110
111 if ( isset( $filterDefinition['showHide'] ) ) {
112 $this->showHide = $filterDefinition['showHide'];
113 }
114
115 $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'] ?? false;
116
117 if ( isset( $filterDefinition['default'] ) ) {
118 $this->setDefault( $filterDefinition['default'] );
119 } else {
120 throw new MWException( 'You must set a default' );
121 }
122
123 if ( isset( $filterDefinition['queryCallable'] ) ) {
124 $this->queryCallable = $filterDefinition['queryCallable'];
125 }
126
127 $this->activeValue = $filterDefinition['activeValue'] ?? true;
128 }
129
136 public function getDefault( $structuredUI = false ) {
137 return $this->isReplacedInStructuredUi && $structuredUI ?
138 !$this->activeValue :
140 }
141
149 public function setDefault( $defaultValue ) {
150 $this->defaultValue = (bool)$defaultValue;
151 }
152
156 public function getShowHide() {
157 return $this->showHide;
158 }
159
163 public function displaysOnUnstructuredUi() {
164 return (bool)$this->showHide;
165 }
166
171 return $this->isReplacedInStructuredUi ||
172 parent::isFeatureAvailableOnStructuredUi();
173 }
174
187 public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
188 &$tables, &$fields, &$conds, &$query_options, &$join_conds
189 ) {
190 if ( $this->queryCallable === null ) {
191 return;
192 }
193
195 get_class( $specialPage ),
196 $specialPage->getContext(),
197 $dbr,
198 $tables,
199 $fields,
200 $conds,
201 $query_options,
202 $join_conds
203 );
204 }
205
209 public function getJsData() {
210 $output = parent::getJsData();
211
212 $output['default'] = $this->defaultValue;
213
214 return $output;
215 }
216
220 public function isSelected( FormOptions $opts ) {
221 return !$opts[ $this->getName() ] &&
222 array_filter(
223 $this->getSiblings(),
224 static function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
225 return $opts[ $sibling->getName() ];
226 }
227 );
228 }
229
235 public function isActive( FormOptions $opts, $isStructuredUI ) {
236 if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
237 return false;
238 }
239
240 return $opts[ $this->getName() ] === $this->activeValue;
241 }
242}
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)
__construct( $filterDefinition)
Create a new filter with the specified configuration.
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds)
Modifies the query to include the filter.
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.
Special page which uses a ChangesList to show query results.
Helper class to keep track of options when mixing links and form elements.
MediaWiki exception.
getContext()
Gets the context this SpecialPage is executed in.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39