MediaWiki REL1_32
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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Represents a hide-based boolean filter (used on ChangesListSpecialPage and descendants)
isSelected(FormOptions $opts)
@inheritDoc
isActive(FormOptions $opts, $isStructuredUI)
__construct( $filterDefinition)
Create a new filter with the specified configuration.
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds)
Modifies the query to include the filter.
setDefault( $defaultValue)
Sets default.
$isReplacedInStructuredUi
Whether there is a feature designed to replace this filter available on the structured UI.
$showHide
Main unstructured UI i18n key.
$activeValue
Value that defined when this filter is considered active.
getDefault( $structuredUI=false)
Get the default value.
$queryCallable
Callable used to do the actual query modification; see constructor.
Represents a filter (used on ChangesListSpecialPage and descendants)
getSiblings()
Get filters in the same group.
Special page which uses a ChangesList to show query results.
Helper class to keep track of options when mixing links and form elements.
MediaWiki exception.
getContext()
Gets the context this SpecialPage is executed in.
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:1035
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2317
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
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38