MediaWiki REL1_31
ChangesListStringOptionsFilterGroup.php
Go to the documentation of this file.
1<?php
25
41 const TYPE = 'string_options';
42
46 const SEPARATOR = ';';
47
51 const ALL = 'all';
52
59 const NONE = '';
60
66 protected $defaultValue;
67
73 protected $queryCallable;
74
111 public function __construct( array $groupDefinition ) {
112 if ( !isset( $groupDefinition['isFullCoverage'] ) ) {
113 throw new MWException( 'You must specify isFullCoverage' );
114 }
115
116 $groupDefinition['type'] = self::TYPE;
117
118 parent::__construct( $groupDefinition );
119
120 $this->queryCallable = $groupDefinition['queryCallable'];
121
122 if ( isset( $groupDefinition['default'] ) ) {
123 $this->setDefault( $groupDefinition['default'] );
124 } else {
125 throw new MWException( 'You must specify a default' );
126 }
127 }
128
134 public function setDefault( $defaultValue ) {
135 $this->defaultValue = $defaultValue;
136 }
137
143 public function getDefault() {
144 return $this->defaultValue;
145 }
146
150 protected function createFilter( array $filterDefinition ) {
151 return new ChangesListStringOptionsFilter( $filterDefinition );
152 }
153
160 $this->filters[$filter->getName()] = $filter;
161 }
162
166 public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
167 &$tables, &$fields, &$conds, &$query_options, &$join_conds,
168 FormOptions $opts, $isStructuredFiltersEnabled
169 ) {
170 if ( !$this->isActive( $isStructuredFiltersEnabled ) ) {
171 return;
172 }
173
174 $value = $opts[ $this->getName() ];
175 $allowedFilterNames = [];
176 foreach ( $this->filters as $filter ) {
177 $allowedFilterNames[] = $filter->getName();
178 }
179
180 if ( $value === self::ALL ) {
181 $selectedValues = $allowedFilterNames;
182 } else {
183 $selectedValues = explode( self::SEPARATOR, strtolower( $value ) );
184
185 // remove values that are not recognized or not currently allowed
186 $selectedValues = array_intersect(
187 $selectedValues,
188 $allowedFilterNames
189 );
190 }
191
192 // If there are now no values, because all are disallowed or invalid (also,
193 // the user may not have selected any), this is a no-op.
194
195 // If everything is unchecked, the group always has no effect, regardless
196 // of full-coverage.
197 if ( count( $selectedValues ) === 0 ) {
198 return;
199 }
200
201 sort( $selectedValues );
202
203 call_user_func_array(
204 $this->queryCallable,
205 [
206 get_class( $specialPage ),
207 $specialPage->getContext(),
208 $dbr,
209 &$tables,
210 &$fields,
211 &$conds,
212 &$query_options,
213 &$join_conds,
214 $selectedValues
215 ]
216 );
217 }
218
222 public function getJsData() {
223 $output = parent::getJsData();
224
225 $output['separator'] = self::SEPARATOR;
226 $output['default'] = $this->getDefault();
227
228 return $output;
229 }
230
234 public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) {
235 $opts->add( $this->getName(), $allowDefaults ? $this->getDefault() : '' );
236 }
237
244 private function isActive( $isStructuredUI ) {
245 // STRING_OPTIONS filter groups are exclusively active on Structured UI
246 return $isStructuredUI;
247 }
248}
Represents a filter group (used on ChangesListSpecialPage and descendants)
Special page which uses a ChangesList to show query results.
Represents a filter group with multiple string options.
addOptions(FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled)
@inheritDoc
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
registerFilter(ChangesListStringOptionsFilter $filter)
Registers a filter in this group.
const ALL
Signifies that all options in the group are selected.
$queryCallable
Callable used to do the actual query modification; see constructor.
setDefault( $defaultValue)
Sets default of filter group.
isActive( $isStructuredUI)
Check if this filter group is currently active.
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, $isStructuredFiltersEnabled)
@inheritDoc
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
An individual filter in a ChangesListStringOptionsFilterGroup.
Helper class to keep track of options when mixing links and form elements.
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
MediaWiki exception.
getContext()
Gets the context this SpecialPage is executed in.
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
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
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38