MediaWiki  1.30.0
ChangesListStringOptionsFilterGroup.php
Go to the documentation of this file.
1 <?php
26 
43  const TYPE = 'string_options';
44 
48  const SEPARATOR = ';';
49 
53  const ALL = 'all';
54 
61  const NONE = '';
62 
68  protected $defaultValue;
69 
75  protected $queryCallable;
76 
113  public function __construct( array $groupDefinition ) {
114  if ( !isset( $groupDefinition['isFullCoverage'] ) ) {
115  throw new MWException( 'You must specify isFullCoverage' );
116  }
117 
118  $groupDefinition['type'] = self::TYPE;
119 
120  parent::__construct( $groupDefinition );
121 
122  $this->queryCallable = $groupDefinition['queryCallable'];
123 
124  if ( isset( $groupDefinition['default'] ) ) {
125  $this->setDefault( $groupDefinition['default'] );
126  } else {
127  throw new MWException( 'You must specify a default' );
128  }
129  }
130 
134  public function isPerGroupRequestParameter() {
135  return true;
136  }
137 
143  public function setDefault( $defaultValue ) {
144  $this->defaultValue = $defaultValue;
145  }
146 
152  public function getDefault() {
153  return $this->defaultValue;
154  }
155 
159  protected function createFilter( array $filterDefinition ) {
160  return new ChangesListStringOptionsFilter( $filterDefinition );
161  }
162 
168  public function registerFilter( ChangesListStringOptionsFilter $filter ) {
169  $this->filters[$filter->getName()] = $filter;
170  }
171 
187  public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
188  &$tables, &$fields, &$conds, &$query_options, &$join_conds, $value
189  ) {
190  $allowedFilterNames = [];
191  foreach ( $this->filters as $filter ) {
192  $allowedFilterNames[] = $filter->getName();
193  }
194 
195  if ( $value === self::ALL ) {
196  $selectedValues = $allowedFilterNames;
197  } else {
198  $selectedValues = explode( self::SEPARATOR, strtolower( $value ) );
199 
200  // remove values that are not recognized or not currently allowed
201  $selectedValues = array_intersect(
202  $selectedValues,
203  $allowedFilterNames
204  );
205  }
206 
207  // If there are now no values, because all are disallowed or invalid (also,
208  // the user may not have selected any), this is a no-op.
209 
210  // If everything is unchecked, the group always has no effect, regardless
211  // of full-coverage.
212  if ( count( $selectedValues ) === 0 ) {
213  return;
214  }
215 
216  sort( $selectedValues );
217 
218  call_user_func_array(
219  $this->queryCallable,
220  [
221  get_class( $specialPage ),
222  $specialPage->getContext(),
223  $dbr,
224  &$tables,
225  &$fields,
226  &$conds,
227  &$query_options,
228  &$join_conds,
229  $selectedValues
230  ]
231  );
232  }
233 
237  public function getJsData() {
238  $output = parent::getJsData();
239 
240  $output['separator'] = self::SEPARATOR;
241  $output['default'] = $this->getDefault();
242 
243  return $output;
244  }
245 }
$tables
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:988
ChangesListStringOptionsFilter
An individual filter in a ChangesListStringOptionsFilterGroup.
Definition: ChangesListStringOptionsFilter.php:10
ChangesListStringOptionsFilterGroup\modifyQuery
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, $value)
Modifies the query to include the filter group.
Definition: ChangesListStringOptionsFilterGroup.php:187
captcha-old.count
count
Definition: captcha-old.py:249
ChangesListStringOptionsFilterGroup\createFilter
createFilter(array $filterDefinition)
@inheritDoc
Definition: ChangesListStringOptionsFilterGroup.php:159
ChangesListStringOptionsFilterGroup\isPerGroupRequestParameter
isPerGroupRequestParameter()
@inheritDoc
Definition: ChangesListStringOptionsFilterGroup.php:134
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
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:34
ChangesListFilter\getName
getName()
Definition: ChangesListFilter.php:265
ChangesListFilterGroup
Represents a filter group (used on ChangesListSpecialPage and descendants)
Definition: ChangesListFilterGroup.php:35
$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
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
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
MWException
MediaWiki exception.
Definition: MWException.php:26
ChangesListStringOptionsFilterGroup\SEPARATOR
const SEPARATOR
Delimiter.
Definition: ChangesListStringOptionsFilterGroup.php:48
ChangesListStringOptionsFilterGroup\__construct
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
Definition: ChangesListStringOptionsFilterGroup.php:113
ChangesListStringOptionsFilterGroup\ALL
const ALL
Signifies that all options in the group are selected.
Definition: ChangesListStringOptionsFilterGroup.php:53
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:648
ChangesListStringOptionsFilterGroup\$defaultValue
$defaultValue
Defaul parameter value.
Definition: ChangesListStringOptionsFilterGroup.php:68
ChangesListStringOptionsFilterGroup\setDefault
setDefault( $defaultValue)
Sets default of filter group.
Definition: ChangesListStringOptionsFilterGroup.php:143
$value
$value
Definition: styleTest.css.php:45
ChangesListStringOptionsFilterGroup\$queryCallable
$queryCallable
Callable used to do the actual query modification; see constructor.
Definition: ChangesListStringOptionsFilterGroup.php:75
ChangesListStringOptionsFilterGroup\getJsData
getJsData()
@inheritDoc
Definition: ChangesListStringOptionsFilterGroup.php:237
ChangesListStringOptionsFilterGroup\NONE
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
Definition: ChangesListStringOptionsFilterGroup.php:61
ChangesListStringOptionsFilterGroup\getDefault
getDefault()
Gets default of filter group.
Definition: ChangesListStringOptionsFilterGroup.php:152
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
ChangesListStringOptionsFilterGroup\registerFilter
registerFilter(ChangesListStringOptionsFilter $filter)
Registers a filter in this group.
Definition: ChangesListStringOptionsFilterGroup.php:168
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
ChangesListStringOptionsFilterGroup
Represents a filter group with multiple string options.
Definition: ChangesListStringOptionsFilterGroup.php:39
ChangesListStringOptionsFilterGroup\TYPE
const TYPE
Type marker, used by JavaScript.
Definition: ChangesListStringOptionsFilterGroup.php:43
array
the array() calling protocol came about after MediaWiki 1.4rc1.