MediaWiki  master
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 
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 }
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))
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
addOptions(FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled)
getContext()
Gets the context this SpecialPage is executed in.
const TYPE
Type marker, used by JavaScript.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
An individual filter in a ChangesListStringOptionsFilterGroup.
$value
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:81
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:1027
isActive( $isStructuredUI)
Check if this filter group is currently active.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2280
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
setDefault( $defaultValue)
Sets default of filter group.
Represents a filter group (used on ChangesListSpecialPage and descendants)
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, $isStructuredFiltersEnabled)
Represents a filter group with multiple string options.
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
const ALL
Signifies that all options in the group are selected.
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
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
Special page which uses a ChangesList to show query results.
$queryCallable
Callable used to do the actual query modification; see constructor.
registerFilter(ChangesListStringOptionsFilter $filter)
Registers a filter in this group.