MediaWiki  REL1_31
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 
159  public function registerFilter( ChangesListStringOptionsFilter $filter ) {
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 
203  call_user_func_array(
204  $this->queryCallable,
205  [
206  get_class( $specialPage ),
207  $specialPage->getContext(),
208  $dbr,
209  &$tables,
210  &$fields,
211  &$conds,
212  &$query_options,
213  &$join_conds,
214  $selectedValues
215  ]
216  );
217  }
218 
222  public function getJsData() {
223  $output = parent::getJsData();
224 
225  $output['separator'] = self::SEPARATOR;
226  $output['default'] = $this->getDefault();
227 
228  return $output;
229  }
230 
234  public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) {
235  $opts->add( $this->getName(), $allowDefaults ? $this->getDefault() : '' );
236  }
237 
244  private function isActive( $isStructuredUI ) {
245  // STRING_OPTIONS filter groups are exclusively active on Structured UI
246  return $isStructuredUI;
247  }
248 }
ChangesListFilterGroup\getName
getName()
Definition: ChangesListFilterGroup.php:285
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
ChangesListStringOptionsFilter
An individual filter in a ChangesListStringOptionsFilterGroup.
Definition: ChangesListStringOptionsFilter.php:10
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$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:2255
ChangesListStringOptionsFilterGroup\createFilter
createFilter(array $filterDefinition)
@inheritDoc
Definition: ChangesListStringOptionsFilterGroup.php:150
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:35
ChangesListFilter\getName
getName()
Definition: ChangesListFilter.php:268
ChangesListStringOptionsFilterGroup\isActive
isActive( $isStructuredUI)
Check if this filter group is currently active.
Definition: ChangesListStringOptionsFilterGroup.php:244
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:37
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
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
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:695
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:45
ChangesListStringOptionsFilterGroup\$queryCallable
$queryCallable
Callable used to do the actual query modification; see constructor.
Definition: ChangesListStringOptionsFilterGroup.php:73
ChangesListStringOptionsFilterGroup\getJsData
getJsData()
@inheritDoc
Definition: ChangesListStringOptionsFilterGroup.php:222
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
$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:1015
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:22
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:234
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