MediaWiki REL1_39
ChangesListStringOptionsFilterGroup.php
Go to the documentation of this file.
1<?php
25
41 public const TYPE = 'string_options';
42
46 public const SEPARATOR = ';';
47
51 public const ALL = 'all';
52
59 public 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
161 $this->filters[$filter->getName()] = $filter;
162 }
163
167 public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage,
168 &$tables, &$fields, &$conds, &$query_options, &$join_conds,
169 FormOptions $opts, $isStructuredFiltersEnabled
170 ) {
171 if ( !$this->isActive( $isStructuredFiltersEnabled ) ) {
172 return;
173 }
174
175 $value = $opts[ $this->getName() ];
176 $allowedFilterNames = [];
177 foreach ( $this->filters as $filter ) {
178 $allowedFilterNames[] = $filter->getName();
179 }
180
181 if ( $value === self::ALL ) {
182 $selectedValues = $allowedFilterNames;
183 } else {
184 $selectedValues = explode( self::SEPARATOR, strtolower( $value ) );
185
186 // remove values that are not recognized or not currently allowed
187 $selectedValues = array_intersect(
188 $selectedValues,
189 $allowedFilterNames
190 );
191 }
192
193 // If there are now no values, because all are disallowed or invalid (also,
194 // the user may not have selected any), this is a no-op.
195
196 // If everything is unchecked, the group always has no effect, regardless
197 // of full-coverage.
198 if ( count( $selectedValues ) === 0 ) {
199 return;
200 }
201
202 sort( $selectedValues );
203
205 get_class( $specialPage ),
206 $specialPage->getContext(),
207 $dbr,
208 $tables,
209 $fields,
210 $conds,
211 $query_options,
212 $join_conds,
213 $selectedValues
214 );
215 }
216
220 public function getJsData() {
221 $output = parent::getJsData();
222
223 $output['separator'] = self::SEPARATOR;
224 $output['default'] = $this->getDefault();
225
226 return $output;
227 }
228
232 public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) {
233 $opts->add( $this->getName(), $allowDefaults ? $this->getDefault() : '' );
234 }
235
242 private function isActive( $isStructuredUI ) {
243 // STRING_OPTIONS filter groups are exclusively active on Structured UI
244 return $isStructuredUI;
245 }
246}
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.
addOptions(FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled)
All the options represented by this filter group to $opts.
__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.
callable $queryCallable
Callable used to do the actual query modification; see constructor.
createFilter(array $filterDefinition)
Creates a filter of the appropriate type for this group, from the definition.ChangesListFilter Filter
setDefault( $defaultValue)
Sets default of filter group.
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, $isStructuredFiltersEnabled)
Modifies the query to include the filter group.The modification is only done if the filter group is i...
getJsData()
Gets the JS data in the format required by the front-end of the structured UI.array|null Associative ...
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
An individual filter in a ChangesListStringOptionsFilterGroup.
Helper class to keep track of options when mixing links and form elements.
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
MediaWiki exception.
getContext()
Gets the context this SpecialPage is executed in.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39