MediaWiki  1.29.1
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 
74  protected $defaultValue;
75 
81  protected $queryCallable;
82 
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 
132  public function isPerGroupRequestParameter() {
133  return true;
134  }
135 
141  public function setDefault( $defaultValue ) {
142  $this->defaultValue = $defaultValue;
143  }
144 
150  public function getDefault() {
151  return $this->defaultValue;
152  }
153 
157  protected function createFilter( array $filterDefinition ) {
158  return new ChangesListStringOptionsFilter( $filterDefinition );
159  }
160 
166  public function registerFilter( ChangesListStringOptionsFilter $filter ) {
167  $this->filters[$filter->getName()] = $filter;
168  }
169 
185  public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
186  &$tables, &$fields, &$conds, &$query_options, &$join_conds, $value ) {
187 
188  $allowedFilterNames = [];
189  foreach ( $this->filters as $filter ) {
190  $allowedFilterNames[] = $filter->getName();
191  }
192 
193  if ( $value === self::ALL ) {
194  $selectedValues = $allowedFilterNames;
195  } else {
196  $selectedValues = explode( self::SEPARATOR, strtolower( $value ) );
197 
198  // remove values that are not recognized or not currently allowed
199  $selectedValues = array_intersect(
200  $selectedValues,
201  $allowedFilterNames
202  );
203  }
204 
205  // If there are now no values, because all are disallowed or invalid (also,
206  // the user may not have selected any), this is a no-op.
207 
208  // If everything is unchecked, the group always has no effect, regardless
209  // of full-coverage.
210  if ( count( $selectedValues ) === 0 ) {
211  return;
212  }
213 
214  sort( $selectedValues );
215 
216  call_user_func_array(
217  $this->queryCallable,
218  [
219  get_class( $specialPage ),
220  $specialPage->getContext(),
221  $dbr,
222  &$tables,
223  &$fields,
224  &$conds,
225  &$query_options,
226  &$join_conds,
227  $selectedValues
228  ]
229  );
230  }
231 
235  public function getJsData() {
236  $output = parent::getJsData();
237 
238  $output['separator'] = self::SEPARATOR;
239  $output['default'] = $this->getDefault();
240 
241  return $output;
242  }
243 }
$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:990
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:185
captcha-old.count
count
Definition: captcha-old.py:225
ChangesListStringOptionsFilterGroup\createFilter
createFilter(array $filterDefinition)
Creates a filter of the appropriate type for this group, from the definition.Filter definition Change...
Definition: ChangesListStringOptionsFilterGroup.php:157
ChangesListStringOptionsFilterGroup\isPerGroupRequestParameter
isPerGroupRequestParameter()
Check whether the URL parameter is for the group, or for individual filters.Defaults can also be defi...
Definition: ChangesListStringOptionsFilterGroup.php:132
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:33
ChangesListFilter\getName
getName()
Definition: ChangesListFilter.php:272
ChangesListFilterGroup
Represents a filter group (used on ChangesListSpecialPage and descendants)
Definition: ChangesListFilterGroup.php:35
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:111
$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
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:74
ChangesListStringOptionsFilterGroup\setDefault
setDefault( $defaultValue)
Sets default of filter group.
Definition: ChangesListStringOptionsFilterGroup.php:141
$value
$value
Definition: styleTest.css.php:45
ChangesListStringOptionsFilterGroup\$queryCallable
$queryCallable
Callable used to do the actual query modification; see constructor.
Definition: ChangesListStringOptionsFilterGroup.php:81
ChangesListStringOptionsFilterGroup\getJsData
getJsData()
Gets the JS data in the format required by the front-end of the structured UI.array|null Associative ...
Definition: ChangesListStringOptionsFilterGroup.php:235
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:150
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
ChangesListStringOptionsFilterGroup\registerFilter
registerFilter(ChangesListStringOptionsFilter $filter)
Registers a filter in this group.
Definition: ChangesListStringOptionsFilterGroup.php:166
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.