MediaWiki  1.33.0
ChangesListStringOptionsFilterGroup.php
Go to the documentation of this file.
1 <?php
25 
41  const TYPE = 'string_options';
42 
46  const SEPARATOR = ';';
47 
51  const ALL = 'all';
52 
59  const NONE = '';
60 
66  protected $defaultValue;
67 
73  protected $queryCallable;
74 
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 
134  public function setDefault( $defaultValue ) {
135  $this->defaultValue = $defaultValue;
136  }
137 
143  public function getDefault() {
144  return $this->defaultValue;
145  }
146 
150  protected function createFilter( array $filterDefinition ) {
151  return new ChangesListStringOptionsFilter( $filterDefinition );
152  }
153 
160  $this->filters[$filter->getName()] = $filter;
161  }
162 
166  public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
167  &$tables, &$fields, &$conds, &$query_options, &$join_conds,
168  FormOptions $opts, $isStructuredFiltersEnabled
169  ) {
170  if ( !$this->isActive( $isStructuredFiltersEnabled ) ) {
171  return;
172  }
173 
174  $value = $opts[ $this->getName() ];
175  $allowedFilterNames = [];
176  foreach ( $this->filters as $filter ) {
177  $allowedFilterNames[] = $filter->getName();
178  }
179 
180  if ( $value === self::ALL ) {
181  $selectedValues = $allowedFilterNames;
182  } else {
183  $selectedValues = explode( self::SEPARATOR, strtolower( $value ) );
184 
185  // remove values that are not recognized or not currently allowed
186  $selectedValues = array_intersect(
187  $selectedValues,
188  $allowedFilterNames
189  );
190  }
191 
192  // If there are now no values, because all are disallowed or invalid (also,
193  // the user may not have selected any), this is a no-op.
194 
195  // If everything is unchecked, the group always has no effect, regardless
196  // of full-coverage.
197  if ( count( $selectedValues ) === 0 ) {
198  return;
199  }
200 
201  sort( $selectedValues );
202 
204  get_class( $specialPage ),
205  $specialPage->getContext(),
206  $dbr,
207  $tables,
208  $fields,
209  $conds,
210  $query_options,
211  $join_conds,
212  $selectedValues
213  );
214  }
215 
219  public function getJsData() {
220  $output = parent::getJsData();
221 
222  $output['separator'] = self::SEPARATOR;
223  $output['default'] = $this->getDefault();
224 
225  return $output;
226  }
227 
231  public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) {
232  $opts->add( $this->getName(), $allowDefaults ? $this->getDefault() : '' );
233  }
234 
241  private function isActive( $isStructuredUI ) {
242  // STRING_OPTIONS filter groups are exclusively active on Structured UI
243  return $isStructuredUI;
244  }
245 }
$filter
$filter
Definition: profileinfo.php:341
ChangesListFilterGroup\getName
getName()
Definition: ChangesListFilterGroup.php:281
ChangesListStringOptionsFilter
An individual filter in a ChangesListStringOptionsFilterGroup.
Definition: ChangesListStringOptionsFilter.php:10
captcha-old.count
count
Definition: captcha-old.py:249
ChangesListStringOptionsFilterGroup\createFilter
createFilter(array $filterDefinition)
@inheritDoc
Definition: ChangesListStringOptionsFilterGroup.php:150
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:36
$tables
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:979
ChangesListStringOptionsFilterGroup\isActive
isActive( $isStructuredUI)
Check if this filter group is currently active.
Definition: ChangesListStringOptionsFilterGroup.php:241
ChangesListFilterGroup
Represents a filter group (used on ChangesListSpecialPage and descendants)
Definition: ChangesListFilterGroup.php:36
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:38
$dbr
$dbr
Definition: testCompression.php:50
FormOptions\add
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:81
MWException
MediaWiki exception.
Definition: MWException.php:26
ChangesListStringOptionsFilterGroup\SEPARATOR
const SEPARATOR
Delimiter.
Definition: ChangesListStringOptionsFilterGroup.php:46
ChangesListStringOptionsFilterGroup\__construct
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
Definition: ChangesListStringOptionsFilterGroup.php:111
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
$output
$output
Definition: SyntaxHighlight.php:334
ChangesListStringOptionsFilterGroup\ALL
const ALL
Signifies that all options in the group are selected.
Definition: ChangesListStringOptionsFilterGroup.php:51
ChangesListStringOptionsFilterGroup\modifyQuery
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, $isStructuredFiltersEnabled)
@inheritDoc
Definition: ChangesListStringOptionsFilterGroup.php:166
array
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))
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:698
ChangesListStringOptionsFilterGroup\$defaultValue
$defaultValue
Defaul parameter value.
Definition: ChangesListStringOptionsFilterGroup.php:66
ChangesListStringOptionsFilterGroup\setDefault
setDefault( $defaultValue)
Sets default of filter group.
Definition: ChangesListStringOptionsFilterGroup.php:134
$value
$value
Definition: styleTest.css.php:49
ChangesListStringOptionsFilterGroup\$queryCallable
$queryCallable
Callable used to do the actual query modification; see constructor.
Definition: ChangesListStringOptionsFilterGroup.php:73
ChangesListStringOptionsFilterGroup\getJsData
getJsData()
@inheritDoc
Definition: ChangesListStringOptionsFilterGroup.php:219
ChangesListStringOptionsFilterGroup\NONE
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
Definition: ChangesListStringOptionsFilterGroup.php:59
ChangesListStringOptionsFilterGroup\getDefault
getDefault()
Gets default of filter group.
Definition: ChangesListStringOptionsFilterGroup.php:143
ChangesListStringOptionsFilterGroup\registerFilter
registerFilter(ChangesListStringOptionsFilter $filter)
Registers a filter in this group.
Definition: ChangesListStringOptionsFilterGroup.php:159
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
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
ChangesListStringOptionsFilterGroup\addOptions
addOptions(FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled)
@inheritDoc
Definition: ChangesListStringOptionsFilterGroup.php:231
ChangesListStringOptionsFilterGroup
Represents a filter group with multiple string options.
Definition: ChangesListStringOptionsFilterGroup.php:37
ChangesListStringOptionsFilterGroup\TYPE
const TYPE
Type marker, used by JavaScript.
Definition: ChangesListStringOptionsFilterGroup.php:41