MediaWiki  1.29.2
ChangesListBooleanFilter.php
Go to the documentation of this file.
1 <?php
26 
39  // This can sometimes be different on Special:RecentChanges
40  // and Special:Watchlist, due to the double-legacy hooks
41  // (SpecialRecentChangesFilters and SpecialWatchlistFilters)
42 
43  // but there will be separate sets of ChangesListFilterGroup and ChangesListFilter instances
44  // for those pages (it should work even if they're both loaded
45  // at once, but that can't happen).
51  protected $showHide;
52 
60 
66  protected $defaultValue;
67 
73  protected $queryCallable;
74 
114  public function __construct( $filterDefinition ) {
115  parent::__construct( $filterDefinition );
116 
117  if ( isset( $filterDefinition['showHide'] ) ) {
118  $this->showHide = $filterDefinition['showHide'];
119  }
120 
121  if ( isset( $filterDefinition['isReplacedInStructuredUi'] ) ) {
122  $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'];
123  } else {
124  $this->isReplacedInStructuredUi = false;
125  }
126 
127  if ( isset( $filterDefinition['default'] ) ) {
128  $this->defaultValue = $filterDefinition['default'];
129  } else {
130  throw new MWException( 'You must set a default' );
131  }
132 
133  if ( isset( $filterDefinition['queryCallable'] ) ) {
134  $this->queryCallable = $filterDefinition['queryCallable'];
135  }
136  }
137 
144  public function getDefault( $structuredUI = false ) {
145  return $this->isReplacedInStructuredUi && $structuredUI ?
146  false :
148  }
149 
155  public function setDefault( $defaultValue ) {
156  $this->defaultValue = $defaultValue;
157  }
158 
162  public function getShowHide() {
163  return $this->showHide;
164  }
165 
169  public function displaysOnUnstructuredUi() {
170  return !!$this->showHide;
171  }
172 
177  return $this->isReplacedInStructuredUi ||
178  parent::isFeatureAvailableOnStructuredUi();
179  }
180 
193  public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
194  &$tables, &$fields, &$conds, &$query_options, &$join_conds ) {
195 
196  if ( $this->queryCallable === null ) {
197  return;
198  }
199 
200  call_user_func_array(
201  $this->queryCallable,
202  [
203  get_class( $specialPage ),
204  $specialPage->getContext(),
205  $dbr,
206  &$tables,
207  &$fields,
208  &$conds,
209  &$query_options,
210  &$join_conds
211  ]
212  );
213  }
214 
218  public function getJsData() {
219  $output = parent::getJsData();
220 
221  $output['default'] = $this->defaultValue;
222 
223  return $output;
224  }
225 
229  public function isSelected( FormOptions $opts ) {
230  return !$opts[ $this->getName() ] &&
231  array_filter( $this->getSiblings(), function ( $sibling ) use ( $opts ) {
232  return $opts[ $sibling->getName() ];
233  } );
234  }
235 }
ChangesListBooleanFilter\$defaultValue
$defaultValue
Default.
Definition: ChangesListBooleanFilter.php:66
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
$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:990
ChangesListBooleanFilter\getDefault
getDefault( $structuredUI=false)
Get the default value.
Definition: ChangesListBooleanFilter.php:144
ChangesListBooleanFilter\getShowHide
getShowHide()
Definition: ChangesListBooleanFilter.php:162
ChangesListBooleanFilter\isSelected
isSelected(FormOptions $opts)
Checks whether this filter is selected in the provided options.bool
Definition: ChangesListBooleanFilter.php:229
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:33
ChangesListBooleanFilter
An individual filter in a boolean group.
Definition: ChangesListBooleanFilter.php:32
ChangesListFilter\getName
getName()
Definition: ChangesListFilter.php:272
ChangesListBooleanFilter\isFeatureAvailableOnStructuredUi
isFeatureAvailableOnStructuredUi()
Checks whether an equivalent feature for this filter is available on the structured UI....
Definition: ChangesListBooleanFilter.php:176
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
MWException
MediaWiki exception.
Definition: MWException.php:26
ChangesListBooleanFilter\__construct
__construct( $filterDefinition)
Create a new filter with the specified configuration.
Definition: ChangesListBooleanFilter.php:114
ChangesListFilter\getSiblings
getSiblings()
Get filters in the same group.
Definition: ChangesListFilter.php:495
ChangesListBooleanFilter\setDefault
setDefault( $defaultValue)
Sets default.
Definition: ChangesListBooleanFilter.php:155
$output
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 and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
Definition: hooks.txt:1049
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:193
ChangesListBooleanFilter\$queryCallable
$queryCallable
Callable used to do the actual query modification; see constructor.
Definition: ChangesListBooleanFilter.php:73
ChangesListBooleanFilter\displaysOnUnstructuredUi
displaysOnUnstructuredUi()
Checks whether the filter should display on the unstructured UI.bool Whether to display
Definition: ChangesListBooleanFilter.php:169
$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:59
ChangesListFilter
Represents a filter (used on ChangesListSpecialPage and descendants)
Definition: ChangesListFilter.php:30
ChangesListBooleanFilter\$showHide
$showHide
Main unstructured UI i18n key.
Definition: ChangesListBooleanFilter.php:51
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
ChangesListBooleanFilter\getJsData
getJsData()
Gets the JS data required by the front-end of the structured UI.array Associative array Data required...
Definition: ChangesListBooleanFilter.php:218