MediaWiki  master
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 !!$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  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 }
$activeValue
Value that defined when this filter is considered active.
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
getContext()
Gets the context this SpecialPage is executed in.
$queryCallable
Callable used to do the actual query modification; see constructor.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$showHide
Main unstructured UI i18n key.
isActive(FormOptions $opts, $isStructuredUI)
this hook is for auditing only 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:990
Represents a filter (used on ChangesListSpecialPage and descendants)
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2221
$isReplacedInStructuredUi
Whether there is a feature designed to replace this filter available on the structured UI...
getSiblings()
Get filters in the same group.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Represents a hide-based boolean filter (used on ChangesListSpecialPage and descendants) ...
__construct( $filterDefinition)
Create a new filter with the specified configuration.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Special page which uses a ChangesList to show query results.
getDefault( $structuredUI=false)
Get the default value.
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds)
Modifies the query to include the filter.
setDefault( $defaultValue)
Sets default.