MediaWiki REL1_30
ChangesListBooleanFilter.php
Go to the documentation of this file.
1<?php
26
33 // This can sometimes be different on Special:RecentChanges
34 // and Special:Watchlist, due to the double-legacy hooks
35 // (SpecialRecentChangesFilters and SpecialWatchlistFilters)
36
37 // but there will be separate sets of ChangesListFilterGroup and ChangesListFilter instances
38 // for those pages (it should work even if they're both loaded
39 // at once, but that can't happen).
45 protected $showHide;
46
54
60 protected $defaultValue;
61
67 protected $queryCallable;
68
74 protected $activeValue;
75
116 public function __construct( $filterDefinition ) {
117 parent::__construct( $filterDefinition );
118
119 if ( isset( $filterDefinition['showHide'] ) ) {
120 $this->showHide = $filterDefinition['showHide'];
121 }
122
123 if ( isset( $filterDefinition['isReplacedInStructuredUi'] ) ) {
124 $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'];
125 } else {
126 $this->isReplacedInStructuredUi = false;
127 }
128
129 if ( isset( $filterDefinition['default'] ) ) {
130 $this->setDefault( $filterDefinition['default'] );
131 } else {
132 throw new MWException( 'You must set a default' );
133 }
134
135 if ( isset( $filterDefinition['queryCallable'] ) ) {
136 $this->queryCallable = $filterDefinition['queryCallable'];
137 }
138
139 if ( isset( $filterDefinition['activeValue'] ) ) {
140 $this->activeValue = $filterDefinition['activeValue'];
141 } else {
142 $this->activeValue = true;
143 }
144 }
145
152 public function getDefault( $structuredUI = false ) {
153 return $this->isReplacedInStructuredUi && $structuredUI ?
154 !$this->activeValue :
156 }
157
165 public function setDefault( $defaultValue ) {
166 $this->defaultValue = (bool)$defaultValue;
167 }
168
172 public function getShowHide() {
173 return $this->showHide;
174 }
175
179 public function displaysOnUnstructuredUi() {
180 return !!$this->showHide;
181 }
182
187 return $this->isReplacedInStructuredUi ||
188 parent::isFeatureAvailableOnStructuredUi();
189 }
190
203 public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
204 &$tables, &$fields, &$conds, &$query_options, &$join_conds
205 ) {
206 if ( $this->queryCallable === null ) {
207 return;
208 }
209
210 call_user_func_array(
211 $this->queryCallable,
212 [
213 get_class( $specialPage ),
214 $specialPage->getContext(),
215 $dbr,
216 &$tables,
217 &$fields,
218 &$conds,
219 &$query_options,
220 &$join_conds
221 ]
222 );
223 }
224
228 public function getJsData() {
229 $output = parent::getJsData();
230
231 $output['default'] = $this->defaultValue;
232
233 return $output;
234 }
235
239 public function isSelected( FormOptions $opts ) {
240 return !$opts[ $this->getName() ] &&
241 array_filter(
242 $this->getSiblings(),
243 function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
244 return $opts[ $sibling->getName() ];
245 }
246 );
247 }
248
254 public function isActive( FormOptions $opts, $isStructuredUI ) {
255 if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
256 return false;
257 }
258
259 return $opts[ $this->getName() ] === $this->activeValue;
260 }
261}
An individual filter in a boolean group.
isSelected(FormOptions $opts)
@inheritDoc
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.
setDefault( $defaultValue)
Sets default.
$isReplacedInStructuredUi
Whether there is a feature designed to replace this filter available on the structured UI.
$showHide
Main unstructured UI i18n key.
$activeValue
Value that defined when this filter is considered active.
getDefault( $structuredUI=false)
Get the default value.
$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.
if(! $regexes) $dbr
Definition cleanup.php:94
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2225
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1013
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40