MediaWiki  1.30.1
ChangesListFilterGroup.php
Go to the documentation of this file.
1 <?php
25 // TODO: Might want to make a super-class or trait to share behavior (especially re
26 // conflicts) between ChangesListFilter and ChangesListFilterGroup.
27 // What to call it. FilterStructure? That would also let me make
28 // setUnidirectionalConflict protected.
29 
35 abstract class ChangesListFilterGroup {
41  protected $name;
42 
48  protected $title;
49 
55  protected $whatsThisHeader;
56 
62  protected $whatsThisBody;
63 
69  protected $whatsThisUrl;
70 
76  protected $whatsThisLinkText;
77 
83  protected $type;
84 
91  protected $priority;
92 
98  protected $filters;
99 
106  protected $isFullCoverage;
107 
114  protected $conflictingGroups = [];
115 
122  protected $conflictingFilters = [];
123 
124  const DEFAULT_PRIORITY = -100;
125 
126  const RESERVED_NAME_CHAR = '_';
127 
154  public function __construct( array $groupDefinition ) {
155  if ( strpos( $groupDefinition['name'], self::RESERVED_NAME_CHAR ) !== false ) {
156  throw new MWException( 'Group names may not contain \'' .
157  self::RESERVED_NAME_CHAR .
158  '\'. Use the naming convention: \'camelCase\''
159  );
160  }
161 
162  $this->name = $groupDefinition['name'];
163 
164  if ( isset( $groupDefinition['title'] ) ) {
165  $this->title = $groupDefinition['title'];
166  }
167 
168  if ( isset( $groupDefinition['whatsThisHeader'] ) ) {
169  $this->whatsThisHeader = $groupDefinition['whatsThisHeader'];
170  $this->whatsThisBody = $groupDefinition['whatsThisBody'];
171  $this->whatsThisUrl = $groupDefinition['whatsThisUrl'];
172  $this->whatsThisLinkText = $groupDefinition['whatsThisLinkText'];
173  }
174 
175  $this->type = $groupDefinition['type'];
176  if ( isset( $groupDefinition['priority'] ) ) {
177  $this->priority = $groupDefinition['priority'];
178  } else {
179  $this->priority = self::DEFAULT_PRIORITY;
180  }
181 
182  $this->isFullCoverage = $groupDefinition['isFullCoverage'];
183 
184  $this->filters = [];
185  $lowestSpecifiedPriority = -1;
186  foreach ( $groupDefinition['filters'] as $filterDefinition ) {
187  if ( isset( $filterDefinition['priority'] ) ) {
188  $lowestSpecifiedPriority = min( $lowestSpecifiedPriority, $filterDefinition['priority'] );
189  }
190  }
191 
192  // Convenience feature: If you specify a group (and its filters) all in
193  // one place, you don't have to specify priority. You can just put them
194  // in order. However, if you later add one (e.g. an extension adds a filter
195  // to a core-defined group), you need to specify it.
196  $autoFillPriority = $lowestSpecifiedPriority - 1;
197  foreach ( $groupDefinition['filters'] as $filterDefinition ) {
198  if ( !isset( $filterDefinition['priority'] ) ) {
199  $filterDefinition['priority'] = $autoFillPriority;
200  $autoFillPriority--;
201  }
202  $filterDefinition['group'] = $this;
203 
204  $filter = $this->createFilter( $filterDefinition );
205  $this->registerFilter( $filter );
206  }
207  }
208 
215  abstract protected function createFilter( array $filterDefinition );
216 
232  public function conflictsWith( $other, $globalKey, $forwardKey, $backwardKey ) {
233  if ( $globalKey === null || $forwardKey === null || $backwardKey === null ) {
234  throw new MWException( 'All messages must be specified' );
235  }
236 
238  $other,
239  $globalKey,
240  $forwardKey
241  );
242 
243  $other->setUnidirectionalConflict(
244  $this,
245  $globalKey,
246  $backwardKey
247  );
248  }
249 
262  public function setUnidirectionalConflict( $other, $globalDescription, $contextDescription ) {
263  if ( $other instanceof ChangesListFilterGroup ) {
264  $this->conflictingGroups[] = [
265  'group' => $other->getName(),
266  'groupObject' => $other,
267  'globalDescription' => $globalDescription,
268  'contextDescription' => $contextDescription,
269  ];
270  } elseif ( $other instanceof ChangesListFilter ) {
271  $this->conflictingFilters[] = [
272  'group' => $other->getGroup()->getName(),
273  'filter' => $other->getName(),
274  'filterObject' => $other,
275  'globalDescription' => $globalDescription,
276  'contextDescription' => $contextDescription,
277  ];
278  } else {
279  throw new MWException( 'You can only pass in a ChangesListFilterGroup or a ChangesListFilter' );
280  }
281  }
282 
286  public function getName() {
287  return $this->name;
288  }
289 
293  public function getTitle() {
294  return $this->title;
295  }
296 
300  public function getType() {
301  return $this->type;
302  }
303 
307  public function getPriority() {
308  return $this->priority;
309  }
310 
315  public function getFilters() {
316  return $this->filters;
317  }
318 
325  public function getFilter( $name ) {
326  return isset( $this->filters[$name] ) ? $this->filters[$name] : null;
327  }
328 
335  abstract public function isPerGroupRequestParameter();
336 
344  public function getJsData() {
345  $output = [
346  'name' => $this->name,
347  'type' => $this->type,
348  'fullCoverage' => $this->isFullCoverage,
349  'filters' => [],
350  'priority' => $this->priority,
351  'conflicts' => [],
352  'messageKeys' => [ $this->title ]
353  ];
354 
355  if ( isset( $this->whatsThisHeader ) ) {
356  $output['whatsThisHeader'] = $this->whatsThisHeader;
357  $output['whatsThisBody'] = $this->whatsThisBody;
358  $output['whatsThisUrl'] = $this->whatsThisUrl;
359  $output['whatsThisLinkText'] = $this->whatsThisLinkText;
360 
361  array_push(
362  $output['messageKeys'],
363  $output['whatsThisHeader'],
364  $output['whatsThisBody'],
365  $output['whatsThisLinkText']
366  );
367  }
368 
369  usort( $this->filters, function ( $a, $b ) {
370  return $b->getPriority() - $a->getPriority();
371  } );
372 
373  foreach ( $this->filters as $filterName => $filter ) {
374  if ( $filter->displaysOnStructuredUi() ) {
375  $filterData = $filter->getJsData();
376  $output['messageKeys'] = array_merge(
377  $output['messageKeys'],
378  $filterData['messageKeys']
379  );
380  unset( $filterData['messageKeys'] );
381  $output['filters'][] = $filterData;
382  }
383  }
384 
385  if ( count( $output['filters'] ) === 0 ) {
386  return null;
387  }
388 
389  $output['title'] = $this->title;
390 
391  $conflicts = array_merge(
392  $this->conflictingGroups,
393  $this->conflictingFilters
394  );
395 
396  foreach ( $conflicts as $conflictInfo ) {
397  unset( $conflictInfo['filterObject'] );
398  unset( $conflictInfo['groupObject'] );
399  $output['conflicts'][] = $conflictInfo;
400  array_push(
401  $output['messageKeys'],
402  $conflictInfo['globalDescription'],
403  $conflictInfo['contextDescription']
404  );
405  }
406 
407  return $output;
408  }
409 
415  public function getConflictingGroups() {
416  return array_map(
417  function ( $conflictDesc ) {
418  return $conflictDesc[ 'groupObject' ];
419  },
421  );
422  }
423 
429  public function getConflictingFilters() {
430  return array_map(
431  function ( $conflictDesc ) {
432  return $conflictDesc[ 'filterObject' ];
433  },
435  );
436  }
437 
444  public function anySelected( FormOptions $opts ) {
445  return !!count( array_filter(
446  $this->getFilters(),
447  function ( ChangesListFilter $filter ) use ( $opts ) {
448  return $filter->isSelected( $opts );
449  }
450  ) );
451  }
452 }
ChangesListFilterGroup\getType
getType()
Definition: ChangesListFilterGroup.php:300
ChangesListFilter\isSelected
isSelected(FormOptions $opts)
Checks whether this filter is selected in the provided options.
ChangesListFilterGroup\getName
getName()
Definition: ChangesListFilterGroup.php:286
type
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 as and are nearing end of 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:22
ChangesListFilterGroup\$type
$type
Type, from a TYPE constant of a subclass.
Definition: ChangesListFilterGroup.php:83
ChangesListFilterGroup\$name
$name
Name (internal identifier)
Definition: ChangesListFilterGroup.php:41
captcha-old.count
count
Definition: captcha-old.py:249
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
ChangesListFilterGroup\createFilter
createFilter(array $filterDefinition)
Creates a filter of the appropriate type for this group, from the definition.
ChangesListFilterGroup\getFilter
getFilter( $name)
Get filter by name.
Definition: ChangesListFilterGroup.php:325
ChangesListFilterGroup\getTitle
getTitle()
Definition: ChangesListFilterGroup.php:293
ChangesListFilterGroup
Represents a filter group (used on ChangesListSpecialPage and descendants)
Definition: ChangesListFilterGroup.php:35
ChangesListFilterGroup\conflictsWith
conflictsWith( $other, $globalKey, $forwardKey, $backwardKey)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
Definition: ChangesListFilterGroup.php:232
$output
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:2198
ChangesListFilterGroup\$whatsThisUrl
$whatsThisUrl
URL of What's This? link.
Definition: ChangesListFilterGroup.php:69
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
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2696
MWException
MediaWiki exception.
Definition: MWException.php:26
ChangesListFilterGroup\__construct
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
Definition: ChangesListFilterGroup.php:154
ChangesListFilterGroup\$priority
$priority
Priority integer.
Definition: ChangesListFilterGroup.php:91
ChangesListFilterGroup\getConflictingFilters
getConflictingFilters()
Get filters conflicting with this filter group.
Definition: ChangesListFilterGroup.php:429
ChangesListFilterGroup\DEFAULT_PRIORITY
const DEFAULT_PRIORITY
Definition: ChangesListFilterGroup.php:124
ChangesListFilterGroup\setUnidirectionalConflict
setUnidirectionalConflict( $other, $globalDescription, $contextDescription)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
Definition: ChangesListFilterGroup.php:262
ChangesListFilterGroup\$isFullCoverage
$isFullCoverage
Whether this group is full coverage.
Definition: ChangesListFilterGroup.php:106
ChangesListFilterGroup\getFilters
getFilters()
Definition: ChangesListFilterGroup.php:315
ChangesListFilterGroup\$whatsThisHeader
$whatsThisHeader
i18n key for header of What's This?
Definition: ChangesListFilterGroup.php:55
ChangesListFilterGroup\getJsData
getJsData()
Gets the JS data in the format required by the front-end of the structured UI.
Definition: ChangesListFilterGroup.php:344
ChangesListFilterGroup\getPriority
getPriority()
Definition: ChangesListFilterGroup.php:307
ChangesListFilterGroup\anySelected
anySelected(FormOptions $opts)
Check if any filter in this group is selected.
Definition: ChangesListFilterGroup.php:444
ChangesListFilterGroup\$whatsThisLinkText
$whatsThisLinkText
i18n key for What's This? link
Definition: ChangesListFilterGroup.php:76
ChangesListFilterGroup\$conflictingFilters
$conflictingFilters
Array of associative arrays with conflict information.
Definition: ChangesListFilterGroup.php:122
ChangesListFilterGroup\$filters
$filters
Associative array of filters, as ChangesListFilter objects, with filter name as key.
Definition: ChangesListFilterGroup.php:98
as
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
Definition: distributors.txt:9
ChangesListFilter
Represents a filter (used on ChangesListSpecialPage and descendants)
Definition: ChangesListFilter.php:30
ChangesListFilterGroup\$whatsThisBody
$whatsThisBody
i18n key for body of What's This?
Definition: ChangesListFilterGroup.php:62
ChangesListFilterGroup\RESERVED_NAME_CHAR
const RESERVED_NAME_CHAR
Definition: ChangesListFilterGroup.php:126
name
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
Definition: design.txt:12
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
ChangesListFilterGroup\$conflictingGroups
$conflictingGroups
Array of associative arrays with conflict information.
Definition: ChangesListFilterGroup.php:114
ChangesListFilterGroup\$title
$title
i18n key for title
Definition: ChangesListFilterGroup.php:48
ChangesListFilterGroup\getConflictingGroups
getConflictingGroups()
Get groups conflicting with this filter group.
Definition: ChangesListFilterGroup.php:415
ChangesListFilterGroup\isPerGroupRequestParameter
isPerGroupRequestParameter()
Check whether the URL parameter is for the group, or for individual filters.
array
the array() calling protocol came about after MediaWiki 1.4rc1.