MediaWiki REL1_31
ChangesListBooleanFilter.php
Go to the documentation of this file.
1<?php
25
32 // This can sometimes be different on Special:RecentChanges
33 // and Special:Watchlist, due to the double-legacy hooks
34 // (SpecialRecentChangesFilters and SpecialWatchlistFilters)
35
36 // but there will be separate sets of ChangesListFilterGroup and ChangesListFilter instances
37 // for those pages (it should work even if they're both loaded
38 // at once, but that can't happen).
44 protected $showHide;
45
53
59 protected $defaultValue;
60
66 protected $queryCallable;
67
73 protected $activeValue;
74
115 public function __construct( $filterDefinition ) {
116 parent::__construct( $filterDefinition );
117
118 if ( isset( $filterDefinition['showHide'] ) ) {
119 $this->showHide = $filterDefinition['showHide'];
120 }
121
122 if ( isset( $filterDefinition['isReplacedInStructuredUi'] ) ) {
123 $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'];
124 } else {
125 $this->isReplacedInStructuredUi = false;
126 }
127
128 if ( isset( $filterDefinition['default'] ) ) {
129 $this->setDefault( $filterDefinition['default'] );
130 } else {
131 throw new MWException( 'You must set a default' );
132 }
133
134 if ( isset( $filterDefinition['queryCallable'] ) ) {
135 $this->queryCallable = $filterDefinition['queryCallable'];
136 }
137
138 if ( isset( $filterDefinition['activeValue'] ) ) {
139 $this->activeValue = $filterDefinition['activeValue'];
140 } else {
141 $this->activeValue = true;
142 }
143 }
144
151 public function getDefault( $structuredUI = false ) {
152 return $this->isReplacedInStructuredUi && $structuredUI ?
153 !$this->activeValue :
155 }
156
164 public function setDefault( $defaultValue ) {
165 $this->defaultValue = (bool)$defaultValue;
166 }
167
171 public function getShowHide() {
172 return $this->showHide;
173 }
174
178 public function displaysOnUnstructuredUi() {
179 return !!$this->showHide;
180 }
181
186 return $this->isReplacedInStructuredUi ||
187 parent::isFeatureAvailableOnStructuredUi();
188 }
189
202 public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
203 &$tables, &$fields, &$conds, &$query_options, &$join_conds
204 ) {
205 if ( $this->queryCallable === null ) {
206 return;
207 }
208
209 call_user_func_array(
210 $this->queryCallable,
211 [
212 get_class( $specialPage ),
213 $specialPage->getContext(),
214 $dbr,
215 &$tables,
216 &$fields,
217 &$conds,
218 &$query_options,
219 &$join_conds
220 ]
221 );
222 }
223
227 public function getJsData() {
228 $output = parent::getJsData();
229
230 $output['default'] = $this->defaultValue;
231
232 return $output;
233 }
234
238 public function isSelected( FormOptions $opts ) {
239 return !$opts[ $this->getName() ] &&
240 array_filter(
241 $this->getSiblings(),
242 function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
243 return $opts[ $sibling->getName() ];
244 }
245 );
246 }
247
253 public function isActive( FormOptions $opts, $isStructuredUI ) {
254 if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
255 return false;
256 }
257
258 return $opts[ $this->getName() ] === $this->activeValue;
259 }
260}
Represents a hide-based boolean filter (used on ChangesListSpecialPage and descendants)
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.
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:2255
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:1015
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38