MediaWiki  1.29.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 
146  public function __construct( array $groupDefinition ) {
147  if ( strpos( $groupDefinition['name'], self::RESERVED_NAME_CHAR ) !== false ) {
148  throw new MWException( 'Group names may not contain \'' .
149  self::RESERVED_NAME_CHAR .
150  '\'. Use the naming convention: \'camelCase\''
151  );
152  }
153 
154  $this->name = $groupDefinition['name'];
155 
156  if ( isset( $groupDefinition['title'] ) ) {
157  $this->title = $groupDefinition['title'];
158  }
159 
160  if ( isset ( $groupDefinition['whatsThisHeader'] ) ) {
161  $this->whatsThisHeader = $groupDefinition['whatsThisHeader'];
162  $this->whatsThisBody = $groupDefinition['whatsThisBody'];
163  $this->whatsThisUrl = $groupDefinition['whatsThisUrl'];
164  $this->whatsThisLinkText = $groupDefinition['whatsThisLinkText'];
165  }
166 
167  $this->type = $groupDefinition['type'];
168  if ( isset( $groupDefinition['priority'] ) ) {
169  $this->priority = $groupDefinition['priority'];
170  } else {
171  $this->priority = self::DEFAULT_PRIORITY;
172  }
173 
174  $this->isFullCoverage = $groupDefinition['isFullCoverage'];
175 
176  $this->filters = [];
177  $lowestSpecifiedPriority = -1;
178  foreach ( $groupDefinition['filters'] as $filterDefinition ) {
179  if ( isset( $filterDefinition['priority'] ) ) {
180  $lowestSpecifiedPriority = min( $lowestSpecifiedPriority, $filterDefinition['priority'] );
181  }
182  }
183 
184  // Convenience feature: If you specify a group (and its filters) all in
185  // one place, you don't have to specify priority. You can just put them
186  // in order. However, if you later add one (e.g. an extension adds a filter
187  // to a core-defined group), you need to specify it.
188  $autoFillPriority = $lowestSpecifiedPriority - 1;
189  foreach ( $groupDefinition['filters'] as $filterDefinition ) {
190  if ( !isset( $filterDefinition['priority'] ) ) {
191  $filterDefinition['priority'] = $autoFillPriority;
192  $autoFillPriority--;
193  }
194  $filterDefinition['group'] = $this;
195 
196  $filter = $this->createFilter( $filterDefinition );
197  $this->registerFilter( $filter );
198  }
199  }
200 
207  abstract protected function createFilter( array $filterDefinition );
208 
224  public function conflictsWith( $other, $globalKey, $forwardKey,
225  $backwardKey ) {
226 
227  if ( $globalKey === null || $forwardKey === null ||
228  $backwardKey === null ) {
229 
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 
258  public function setUnidirectionalConflict( $other, $globalDescription,
259  $contextDescription ) {
260 
261  if ( $other instanceof ChangesListFilterGroup ) {
262  $this->conflictingGroups[] = [
263  'group' => $other->getName(),
264  'groupObject' => $other,
265  'globalDescription' => $globalDescription,
266  'contextDescription' => $contextDescription,
267  ];
268  } elseif ( $other instanceof ChangesListFilter ) {
269  $this->conflictingFilters[] = [
270  'group' => $other->getGroup()->getName(),
271  'filter' => $other->getName(),
272  'filterObject' => $other,
273  'globalDescription' => $globalDescription,
274  'contextDescription' => $contextDescription,
275  ];
276  } else {
277  throw new MWException( 'You can only pass in a ChangesListFilterGroup or a ChangesListFilter' );
278  }
279  }
280 
284  public function getName() {
285  return $this->name;
286  }
287 
291  public function getTitle() {
292  return $this->title;
293  }
294 
298  public function getType() {
299  return $this->type;
300  }
301 
305  public function getPriority() {
306  return $this->priority;
307  }
308 
312  public function getFilters() {
313  return $this->filters;
314  }
315 
322  public function getFilter( $name ) {
323  return isset( $this->filters[$name] ) ? $this->filters[$name] : null;
324  }
325 
332  abstract public function isPerGroupRequestParameter();
333 
341  public function getJsData() {
342  $output = [
343  'name' => $this->name,
344  'type' => $this->type,
345  'fullCoverage' => $this->isFullCoverage,
346  'filters' => [],
347  'priority' => $this->priority,
348  'conflicts' => [],
349  'messageKeys' => [ $this->title ]
350  ];
351 
352  if ( isset ( $this->whatsThisHeader ) ) {
353  $output['whatsThisHeader'] = $this->whatsThisHeader;
354  $output['whatsThisBody'] = $this->whatsThisBody;
355  $output['whatsThisUrl'] = $this->whatsThisUrl;
356  $output['whatsThisLinkText'] = $this->whatsThisLinkText;
357 
358  array_push(
359  $output['messageKeys'],
360  $output['whatsThisHeader'],
361  $output['whatsThisBody'],
362  $output['whatsThisLinkText']
363  );
364  }
365 
366  usort( $this->filters, function ( $a, $b ) {
367  return $b->getPriority() - $a->getPriority();
368  } );
369 
370  foreach ( $this->filters as $filterName => $filter ) {
371  if ( $filter->displaysOnStructuredUi() ) {
372  $filterData = $filter->getJsData();
373  $output['messageKeys'] = array_merge(
374  $output['messageKeys'],
375  $filterData['messageKeys']
376  );
377  unset( $filterData['messageKeys'] );
378  $output['filters'][] = $filterData;
379  }
380  }
381 
382  if ( count( $output['filters'] ) === 0 ) {
383  return null;
384  }
385 
386  $output['title'] = $this->title;
387 
388  $conflicts = array_merge(
389  $this->conflictingGroups,
390  $this->conflictingFilters
391  );
392 
393  foreach ( $conflicts as $conflictInfo ) {
394  $output['conflicts'][] = $conflictInfo;
395  unset( $conflictInfo['filterObject'] );
396  unset( $conflictInfo['groupObject'] );
397  array_push(
398  $output['messageKeys'],
399  $conflictInfo['globalDescription'],
400  $conflictInfo['contextDescription']
401  );
402  }
403 
404  return $output;
405  }
406 
412  public function getConflictingGroups() {
413  return array_map(
414  function ( $conflictDesc ) {
415  return $conflictDesc[ 'groupObject' ];
416  },
418  );
419  }
420 
426  public function getConflictingFilters() {
427  return array_map(
428  function ( $conflictDesc ) {
429  return $conflictDesc[ 'filterObject' ];
430  },
432  );
433  }
434 
441  public function anySelected( FormOptions $opts ) {
442  return !!count( array_filter(
443  $this->getFilters(),
444  function ( ChangesListFilter $filter ) use ( $opts ) {
445  return $filter->isSelected( $opts );
446  }
447  ) );
448  }
449 }
ChangesListFilterGroup\getType
getType()
Definition: ChangesListFilterGroup.php:298
ChangesListFilter\isSelected
isSelected(FormOptions $opts)
Checks whether this filter is selected in the provided options.
ChangesListFilterGroup\getName
getName()
Definition: ChangesListFilterGroup.php:284
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:225
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:322
ChangesListFilterGroup\getTitle
getTitle()
Definition: ChangesListFilterGroup.php:291
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:224
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
ChangesListFilterGroup\$conflictingFilters
$conflictingFilters
Definition: ChangesListFilterGroup.php:122
MWException
MediaWiki exception.
Definition: MWException.php:26
ChangesListFilterGroup\__construct
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
Definition: ChangesListFilterGroup.php:146
ChangesListFilterGroup\$priority
$priority
Priority integer.
Definition: ChangesListFilterGroup.php:91
ChangesListFilterGroup\getConflictingFilters
getConflictingFilters()
Get filters conflicting with this filter group.
Definition: ChangesListFilterGroup.php:426
$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
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:258
ChangesListFilterGroup\$isFullCoverage
$isFullCoverage
Whether this group is full coverage.
Definition: ChangesListFilterGroup.php:106
ChangesListFilterGroup\getFilters
getFilters()
Definition: ChangesListFilterGroup.php:312
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:341
ChangesListFilterGroup\$conflictingGroups
$conflictingGroups
Definition: ChangesListFilterGroup.php:114
title
title
Definition: parserTests.txt:211
ChangesListFilterGroup\getPriority
getPriority()
Definition: ChangesListFilterGroup.php:305
ChangesListFilterGroup\anySelected
anySelected(FormOptions $opts)
Check if any filter in this group is selected.
Definition: ChangesListFilterGroup.php:441
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\$whatsThisLinkText
$whatsThisLinkText
i18n key for What's This? link
Definition: ChangesListFilterGroup.php:76
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\$title
$title
i18n key for title
Definition: ChangesListFilterGroup.php:48
ChangesListFilterGroup\getConflictingGroups
getConflictingGroups()
Get groups conflicting with this filter group.
Definition: ChangesListFilterGroup.php:412
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.