MediaWiki  1.32.0
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  if ( isset( $filterDefinition['isReplacedInStructuredUi'] ) ) {
116  $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'];
117  } else {
118  $this->isReplacedInStructuredUi = false;
119  }
120 
121  if ( isset( $filterDefinition['default'] ) ) {
122  $this->setDefault( $filterDefinition['default'] );
123  } else {
124  throw new MWException( 'You must set a default' );
125  }
126 
127  if ( isset( $filterDefinition['queryCallable'] ) ) {
128  $this->queryCallable = $filterDefinition['queryCallable'];
129  }
130 
131  if ( isset( $filterDefinition['activeValue'] ) ) {
132  $this->activeValue = $filterDefinition['activeValue'];
133  } else {
134  $this->activeValue = true;
135  }
136  }
137 
144  public function getDefault( $structuredUI = false ) {
145  return $this->isReplacedInStructuredUi && $structuredUI ?
146  !$this->activeValue :
148  }
149 
157  public function setDefault( $defaultValue ) {
158  $this->defaultValue = (bool)$defaultValue;
159  }
160 
164  public function getShowHide() {
165  return $this->showHide;
166  }
167 
171  public function displaysOnUnstructuredUi() {
172  return !!$this->showHide;
173  }
174 
179  return $this->isReplacedInStructuredUi ||
180  parent::isFeatureAvailableOnStructuredUi();
181  }
182 
195  public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
196  &$tables, &$fields, &$conds, &$query_options, &$join_conds
197  ) {
198  if ( $this->queryCallable === null ) {
199  return;
200  }
201 
203  get_class( $specialPage ),
204  $specialPage->getContext(),
205  $dbr,
206  $tables,
207  $fields,
208  $conds,
209  $query_options,
210  $join_conds
211  );
212  }
213 
217  public function getJsData() {
218  $output = parent::getJsData();
219 
220  $output['default'] = $this->defaultValue;
221 
222  return $output;
223  }
224 
228  public function isSelected( FormOptions $opts ) {
229  return !$opts[ $this->getName() ] &&
230  array_filter(
231  $this->getSiblings(),
232  function ( ChangesListBooleanFilter $sibling ) use ( $opts ) {
233  return $opts[ $sibling->getName() ];
234  }
235  );
236  }
237 
243  public function isActive( FormOptions $opts, $isStructuredUI ) {
244  if ( $this->isReplacedInStructuredUi && $isStructuredUI ) {
245  return false;
246  }
247 
248  return $opts[ $this->getName() ] === $this->activeValue;
249  }
250 }
ChangesListBooleanFilter\$defaultValue
$defaultValue
Default.
Definition: ChangesListBooleanFilter.php:52
ChangesListBooleanFilter\getDefault
getDefault( $structuredUI=false)
Get the default value.
Definition: ChangesListBooleanFilter.php:144
ChangesListBooleanFilter\getShowHide
getShowHide()
Definition: ChangesListBooleanFilter.php:164
ChangesListBooleanFilter\isSelected
isSelected(FormOptions $opts)
@inheritDoc
Definition: ChangesListBooleanFilter.php:228
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:35
$tables
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:1018
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:178
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:38
ChangesListBooleanFilter\isActive
isActive(FormOptions $opts, $isStructuredUI)
Definition: ChangesListBooleanFilter.php:243
$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:108
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:66
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
ChangesListBooleanFilter\setDefault
setDefault( $defaultValue)
Sets default.
Definition: ChangesListBooleanFilter.php:157
$output
$output
Definition: SyntaxHighlight.php:334
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:698
ChangesListBooleanFilter\modifyQuery
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds)
Modifies the query to include the filter.
Definition: ChangesListBooleanFilter.php:195
ChangesListBooleanFilter\$queryCallable
$queryCallable
Callable used to do the actual query modification; see constructor.
Definition: ChangesListBooleanFilter.php:59
ChangesListBooleanFilter\displaysOnUnstructuredUi
displaysOnUnstructuredUi()
@inheritDoc
Definition: ChangesListBooleanFilter.php:171
ChangesListBooleanFilter\$isReplacedInStructuredUi
$isReplacedInStructuredUi
Whether there is a feature designed to replace this filter available on the structured UI.
Definition: ChangesListBooleanFilter.php:45
ChangesListFilter
Represents a filter (used on ChangesListSpecialPage and descendants)
Definition: ChangesListFilter.php:29
ChangesListBooleanFilter\$showHide
$showHide
Main unstructured UI i18n key.
Definition: ChangesListBooleanFilter.php:37
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:217