MediaWiki REL1_30
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
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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Represents a filter group (used on ChangesListSpecialPage and descendants)
Special page which uses a ChangesList to show query results.
Represents a filter group with multiple string options.
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, $value)
Modifies the query to include the filter group.
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
registerFilter(ChangesListStringOptionsFilter $filter)
Registers a filter in this group.
const ALL
Signifies that all options in the group are selected.
$queryCallable
Callable used to do the actual query modification; see constructor.
setDefault( $defaultValue)
Sets default of filter group.
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
An individual filter in a ChangesListStringOptionsFilterGroup.
MediaWiki exception.
getContext()
Gets the context this SpecialPage is executed in.
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
the array() calling protocol came about after MediaWiki 1.4rc1.
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:2225
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:1013
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
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40