MediaWiki REL1_33
ChangesListFilterGroup.php
Go to the documentation of this file.
1<?php
24// TODO: Might want to make a super-class or trait to share behavior (especially re
25// conflicts) between ChangesListFilter and ChangesListFilterGroup.
26// What to call it. FilterStructure? That would also let me make
27// setUnidirectionalConflict protected.
28
30
36abstract class ChangesListFilterGroup {
42 protected $name;
43
49 protected $title;
50
57
63 protected $whatsThisBody;
64
70 protected $whatsThisUrl;
71
78
84 protected $type;
85
92 protected $priority;
93
99 protected $filters;
100
108
115 protected $conflictingGroups = [];
116
123 protected $conflictingFilters = [];
124
125 const DEFAULT_PRIORITY = -100;
126
128
155 public function __construct( array $groupDefinition ) {
156 if ( strpos( $groupDefinition['name'], self::RESERVED_NAME_CHAR ) !== false ) {
157 throw new MWException( 'Group names may not contain \'' .
158 self::RESERVED_NAME_CHAR .
159 '\'. Use the naming convention: \'camelCase\''
160 );
161 }
162
163 $this->name = $groupDefinition['name'];
164
165 if ( isset( $groupDefinition['title'] ) ) {
166 $this->title = $groupDefinition['title'];
167 }
168
169 if ( isset( $groupDefinition['whatsThisHeader'] ) ) {
170 $this->whatsThisHeader = $groupDefinition['whatsThisHeader'];
171 $this->whatsThisBody = $groupDefinition['whatsThisBody'];
172 $this->whatsThisUrl = $groupDefinition['whatsThisUrl'];
173 $this->whatsThisLinkText = $groupDefinition['whatsThisLinkText'];
174 }
175
176 $this->type = $groupDefinition['type'];
177 $this->priority = $groupDefinition['priority'] ?? self::DEFAULT_PRIORITY;
178
179 $this->isFullCoverage = $groupDefinition['isFullCoverage'];
180
181 $this->filters = [];
182 $lowestSpecifiedPriority = -1;
183 foreach ( $groupDefinition['filters'] as $filterDefinition ) {
184 if ( isset( $filterDefinition['priority'] ) ) {
185 $lowestSpecifiedPriority = min( $lowestSpecifiedPriority, $filterDefinition['priority'] );
186 }
187 }
188
189 // Convenience feature: If you specify a group (and its filters) all in
190 // one place, you don't have to specify priority. You can just put them
191 // in order. However, if you later add one (e.g. an extension adds a filter
192 // to a core-defined group), you need to specify it.
193 $autoFillPriority = $lowestSpecifiedPriority - 1;
194 foreach ( $groupDefinition['filters'] as $filterDefinition ) {
195 if ( !isset( $filterDefinition['priority'] ) ) {
196 $filterDefinition['priority'] = $autoFillPriority;
197 $autoFillPriority--;
198 }
199 $filterDefinition['group'] = $this;
200
201 $filter = $this->createFilter( $filterDefinition );
202 $this->registerFilter( $filter );
203 }
204 }
205
212 abstract protected function createFilter( array $filterDefinition );
213
228 public function conflictsWith( $other, $globalKey, $forwardKey, $backwardKey ) {
229 if ( $globalKey === null || $forwardKey === null || $backwardKey === null ) {
230 throw new MWException( 'All messages must be specified' );
231 }
232
234 $other,
235 $globalKey,
236 $forwardKey
237 );
238
239 $other->setUnidirectionalConflict(
240 $this,
241 $globalKey,
242 $backwardKey
243 );
244 }
245
257 public function setUnidirectionalConflict( $other, $globalDescription, $contextDescription ) {
258 if ( $other instanceof ChangesListFilterGroup ) {
259 $this->conflictingGroups[] = [
260 'group' => $other->getName(),
261 'groupObject' => $other,
262 'globalDescription' => $globalDescription,
263 'contextDescription' => $contextDescription,
264 ];
265 } elseif ( $other instanceof ChangesListFilter ) {
266 $this->conflictingFilters[] = [
267 'group' => $other->getGroup()->getName(),
268 'filter' => $other->getName(),
269 'filterObject' => $other,
270 'globalDescription' => $globalDescription,
271 'contextDescription' => $contextDescription,
272 ];
273 } else {
274 throw new MWException( 'You can only pass in a ChangesListFilterGroup or a ChangesListFilter' );
275 }
276 }
277
281 public function getName() {
282 return $this->name;
283 }
284
288 public function getTitle() {
289 return $this->title;
290 }
291
295 public function getType() {
296 return $this->type;
297 }
298
302 public function getPriority() {
303 return $this->priority;
304 }
305
310 public function getFilters() {
311 return $this->filters;
312 }
313
320 public function getFilter( $name ) {
321 return $this->filters[$name] ?? null;
322 }
323
331 public function getJsData() {
332 $output = [
333 'name' => $this->name,
334 'type' => $this->type,
335 'fullCoverage' => $this->isFullCoverage,
336 'filters' => [],
337 'priority' => $this->priority,
338 'conflicts' => [],
339 'messageKeys' => [ $this->title ]
340 ];
341
342 if ( isset( $this->whatsThisHeader ) ) {
343 $output['whatsThisHeader'] = $this->whatsThisHeader;
344 $output['whatsThisBody'] = $this->whatsThisBody;
345 $output['whatsThisUrl'] = $this->whatsThisUrl;
346 $output['whatsThisLinkText'] = $this->whatsThisLinkText;
347
348 array_push(
349 $output['messageKeys'],
350 $output['whatsThisHeader'],
351 $output['whatsThisBody'],
352 $output['whatsThisLinkText']
353 );
354 }
355
356 usort( $this->filters, function ( $a, $b ) {
357 return $b->getPriority() <=> $a->getPriority();
358 } );
359
360 foreach ( $this->filters as $filterName => $filter ) {
361 if ( $filter->displaysOnStructuredUi() ) {
362 $filterData = $filter->getJsData();
363 $output['messageKeys'] = array_merge(
364 $output['messageKeys'],
365 $filterData['messageKeys']
366 );
367 unset( $filterData['messageKeys'] );
368 $output['filters'][] = $filterData;
369 }
370 }
371
372 if ( count( $output['filters'] ) === 0 ) {
373 return null;
374 }
375
376 $output['title'] = $this->title;
377
378 $conflicts = array_merge(
379 $this->conflictingGroups,
380 $this->conflictingFilters
381 );
382
383 foreach ( $conflicts as $conflictInfo ) {
384 unset( $conflictInfo['filterObject'] );
385 unset( $conflictInfo['groupObject'] );
386 $output['conflicts'][] = $conflictInfo;
387 array_push(
388 $output['messageKeys'],
389 $conflictInfo['globalDescription'],
390 $conflictInfo['contextDescription']
391 );
392 }
393
394 return $output;
395 }
396
402 public function getConflictingGroups() {
403 return array_map(
404 function ( $conflictDesc ) {
405 return $conflictDesc[ 'groupObject' ];
406 },
408 );
409 }
410
416 public function getConflictingFilters() {
417 return array_map(
418 function ( $conflictDesc ) {
419 return $conflictDesc[ 'filterObject' ];
420 },
422 );
423 }
424
431 public function anySelected( FormOptions $opts ) {
432 return (bool)count( array_filter(
433 $this->getFilters(),
434 function ( ChangesListFilter $filter ) use ( $opts ) {
435 return $filter->isSelected( $opts );
436 }
437 ) );
438 }
439
456 abstract public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
457 &$tables, &$fields, &$conds, &$query_options, &$join_conds,
458 FormOptions $opts, $isStructuredFiltersEnabled );
459
467 abstract public function addOptions( FormOptions $opts, $allowDefaults,
468 $isStructuredFiltersEnabled );
469}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Represents a filter group (used on ChangesListSpecialPage and descendants)
$filters
Associative array of filters, as ChangesListFilter objects, with filter name as key.
$name
Name (internal identifier)
$whatsThisBody
i18n key for body of What's This?
anySelected(FormOptions $opts)
Check if any filter in this group is selected.
$whatsThisUrl
URL of What's This? link.
$isFullCoverage
Whether this group is full coverage.
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, $isStructuredFiltersEnabled)
Modifies the query to include the filter group.
getFilter( $name)
Get filter by name.
getConflictingGroups()
Get groups conflicting with this filter group.
$conflictingFilters
Array of associative arrays with conflict information.
getJsData()
Gets the JS data in the format required by the front-end of the structured UI.
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
$whatsThisHeader
i18n key for header of What's This?
addOptions(FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled)
All the options represented by this filter group to $opts.
getConflictingFilters()
Get filters conflicting with this filter group.
$conflictingGroups
Array of associative arrays with conflict information.
setUnidirectionalConflict( $other, $globalDescription, $contextDescription)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
createFilter(array $filterDefinition)
Creates a filter of the appropriate type for this group, from the definition.
$type
Type, from a TYPE constant of a subclass.
conflictsWith( $other, $globalKey, $forwardKey, $backwardKey)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
$whatsThisLinkText
i18n key for What's This? link
Represents a filter (used on ChangesListSpecialPage and descendants)
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.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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:996
and how to run hooks for an and one after Each event has a name
Definition hooks.txt:12
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:2272
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
title
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:30
$filter