MediaWiki  1.30.0
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 }
ChangesListBooleanFilter\$defaultValue
$defaultValue
Default.
Definition: ChangesListBooleanFilter.php:60
$tables
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:988
ChangesListBooleanFilter\getDefault
getDefault( $structuredUI=false)
Get the default value.
Definition: ChangesListBooleanFilter.php:152
ChangesListBooleanFilter\getShowHide
getShowHide()
Definition: ChangesListBooleanFilter.php:172
ChangesListBooleanFilter\isSelected
isSelected(FormOptions $opts)
@inheritDoc
Definition: ChangesListBooleanFilter.php:239
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:34
ChangesListBooleanFilter
An individual filter in a boolean group.
Definition: ChangesListBooleanFilter.php:32
ChangesListFilter\getName
getName()
Definition: ChangesListFilter.php:265
ChangesListBooleanFilter\isFeatureAvailableOnStructuredUi
isFeatureAvailableOnStructuredUi()
@inheritDoc
Definition: ChangesListBooleanFilter.php:186
$output
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:2198
php
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
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
ChangesListBooleanFilter\isActive
isActive(FormOptions $opts, $isStructuredUI)
Definition: ChangesListBooleanFilter.php:254
MWException
MediaWiki exception.
Definition: MWException.php:26
ChangesListBooleanFilter\__construct
__construct( $filterDefinition)
Create a new filter with the specified configuration.
Definition: ChangesListBooleanFilter.php:116
ChangesListFilter\getSiblings
getSiblings()
Get filters in the same group.
Definition: ChangesListFilter.php:489
ChangesListBooleanFilter\$activeValue
$activeValue
Value that defined when this filter is considered active.
Definition: ChangesListBooleanFilter.php:74
ChangesListBooleanFilter\setDefault
setDefault( $defaultValue)
Sets default.
Definition: ChangesListBooleanFilter.php:165
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:648
ChangesListBooleanFilter\modifyQuery
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds)
Modifies the query to include the filter.
Definition: ChangesListBooleanFilter.php:203
ChangesListBooleanFilter\$queryCallable
$queryCallable
Callable used to do the actual query modification; see constructor.
Definition: ChangesListBooleanFilter.php:67
ChangesListBooleanFilter\displaysOnUnstructuredUi
displaysOnUnstructuredUi()
@inheritDoc
Definition: ChangesListBooleanFilter.php:179
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
ChangesListBooleanFilter\$isReplacedInStructuredUi
$isReplacedInStructuredUi
Whether there is a feature designed to replace this filter available on the structured UI.
Definition: ChangesListBooleanFilter.php:53
ChangesListFilter
Represents a filter (used on ChangesListSpecialPage and descendants)
Definition: ChangesListFilter.php:30
ChangesListBooleanFilter\$showHide
$showHide
Main unstructured UI i18n key.
Definition: ChangesListBooleanFilter.php:45
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
ChangesListBooleanFilter\getJsData
getJsData()
@inheritDoc
Definition: ChangesListBooleanFilter.php:228