MediaWiki  1.33.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  $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 (bool)$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 }
ChangesListBooleanFilter\$defaultValue
$defaultValue
Default.
Definition: ChangesListBooleanFilter.php:52
ChangesListBooleanFilter\getDefault
getDefault( $structuredUI=false)
Get the default value.
Definition: ChangesListBooleanFilter.php:136
ChangesListBooleanFilter\getShowHide
getShowHide()
Definition: ChangesListBooleanFilter.php:156
ChangesListBooleanFilter\isSelected
isSelected(FormOptions $opts)
@inheritDoc
Definition: ChangesListBooleanFilter.php:220
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:36
$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:979
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:170
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:235
$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:149
$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:187
ChangesListBooleanFilter\$queryCallable
$queryCallable
Callable used to do the actual query modification; see constructor.
Definition: ChangesListBooleanFilter.php:59
ChangesListBooleanFilter\displaysOnUnstructuredUi
displaysOnUnstructuredUi()
@inheritDoc
Definition: ChangesListBooleanFilter.php:163
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:209