MediaWiki  master
ChangesListBooleanFilter.php
Go to the documentation of this file.
1 <?php
26 
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 :
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( IDatabase $dbr, ChangesListSpecialPage $specialPage,
189  &$tables, &$fields, &$conds, &$query_options, &$join_conds
190  ) {
191  if ( $this->queryCallable === null ) {
192  return;
193  }
194 
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)
__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.
Definition: FormOptions.php:41
getContext()
Gets the context this SpecialPage is executed in.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:36