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 }
ChangesListBooleanFilter\$defaultValue
$defaultValue
Default.
Definition: ChangesListBooleanFilter.php:59
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
ChangesListBooleanFilter\getDefault
getDefault( $structuredUI=false)
Get the default value.
Definition: ChangesListBooleanFilter.php:151
ChangesListBooleanFilter\getShowHide
getShowHide()
Definition: ChangesListBooleanFilter.php:171
$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:2255
ChangesListBooleanFilter\isSelected
isSelected(FormOptions $opts)
@inheritDoc
Definition: ChangesListBooleanFilter.php:238
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:35
ChangesListBooleanFilter
Represents a hide-based boolean filter (used on ChangesListSpecialPage and descendants)
Definition: ChangesListBooleanFilter.php:31
ChangesListFilter\getName
getName()
Definition: ChangesListFilter.php:268
ChangesListBooleanFilter\isFeatureAvailableOnStructuredUi
isFeatureAvailableOnStructuredUi()
@inheritDoc
Definition: ChangesListBooleanFilter.php:185
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:37
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
ChangesListBooleanFilter\isActive
isActive(FormOptions $opts, $isStructuredUI)
Definition: ChangesListBooleanFilter.php:253
$dbr
$dbr
Definition: testCompression.php:50
MWException
MediaWiki exception.
Definition: MWException.php:26
ChangesListBooleanFilter\__construct
__construct( $filterDefinition)
Create a new filter with the specified configuration.
Definition: ChangesListBooleanFilter.php:115
ChangesListFilter\getSiblings
getSiblings()
Get filters in the same group.
Definition: ChangesListFilter.php:493
ChangesListBooleanFilter\$activeValue
$activeValue
Value that defined when this filter is considered active.
Definition: ChangesListBooleanFilter.php:73
ChangesListBooleanFilter\setDefault
setDefault( $defaultValue)
Sets default.
Definition: ChangesListBooleanFilter.php:164
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:695
ChangesListBooleanFilter\modifyQuery
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds)
Modifies the query to include the filter.
Definition: ChangesListBooleanFilter.php:202
ChangesListBooleanFilter\$queryCallable
$queryCallable
Callable used to do the actual query modification; see constructor.
Definition: ChangesListBooleanFilter.php:66
ChangesListBooleanFilter\displaysOnUnstructuredUi
displaysOnUnstructuredUi()
@inheritDoc
Definition: ChangesListBooleanFilter.php:178
$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:1015
ChangesListBooleanFilter\$isReplacedInStructuredUi
$isReplacedInStructuredUi
Whether there is a feature designed to replace this filter available on the structured UI.
Definition: ChangesListBooleanFilter.php:52
ChangesListFilter
Represents a filter (used on ChangesListSpecialPage and descendants)
Definition: ChangesListFilter.php:29
ChangesListBooleanFilter\$showHide
$showHide
Main unstructured UI i18n key.
Definition: ChangesListBooleanFilter.php:44
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:227