127 private const DEFAULT_PRIORITY = -100;
129 private const RESERVED_NAME_CHAR =
'_';
158 if ( strpos( $groupDefinition[
'name'], self::RESERVED_NAME_CHAR ) !==
false ) {
159 throw new InvalidArgumentException(
'Group names may not contain \'' .
160 self::RESERVED_NAME_CHAR .
161 '\'. Use the naming convention: \
'camelCase\''
165 $this->name = $groupDefinition[
'name'];
167 if ( isset( $groupDefinition[
'title'] ) ) {
168 $this->title = $groupDefinition[
'title'];
171 if ( isset( $groupDefinition[
'whatsThisHeader'] ) ) {
172 $this->whatsThisHeader = $groupDefinition[
'whatsThisHeader'];
173 $this->whatsThisBody = $groupDefinition[
'whatsThisBody'];
174 $this->whatsThisUrl = $groupDefinition[
'whatsThisUrl'];
175 $this->whatsThisLinkText = $groupDefinition[
'whatsThisLinkText'];
178 $this->type = $groupDefinition[
'type'];
179 $this->priority = $groupDefinition[
'priority'] ?? self::DEFAULT_PRIORITY;
181 $this->isFullCoverage = $groupDefinition[
'isFullCoverage'];
184 $lowestSpecifiedPriority = -1;
185 foreach ( $groupDefinition[
'filters'] as $filterDefinition ) {
186 if ( isset( $filterDefinition[
'priority'] ) ) {
187 $lowestSpecifiedPriority = min( $lowestSpecifiedPriority, $filterDefinition[
'priority'] );
195 $autoFillPriority = $lowestSpecifiedPriority - 1;
196 foreach ( $groupDefinition[
'filters'] as $filterDefinition ) {
197 if ( !isset( $filterDefinition[
'priority'] ) ) {
198 $filterDefinition[
'priority'] = $autoFillPriority;
201 $filterDefinition[
'group'] = $this;
204 $this->registerFilter( $filter );
230 public function conflictsWith( $other,
string $globalKey,
string $forwardKey,
string $backwardKey ) {
237 $other->setUnidirectionalConflict(
257 $this->conflictingGroups[] = [
258 'group' => $other->getName(),
259 'groupObject' => $other,
260 'globalDescription' => $globalDescription,
261 'contextDescription' => $contextDescription,
264 $this->conflictingFilters[] = [
265 'group' => $other->getGroup()->getName(),
266 'filter' => $other->getName(),
267 'filterObject' => $other,
268 'globalDescription' => $globalDescription,
269 'contextDescription' => $contextDescription,
272 throw new InvalidArgumentException(
273 'You can only pass in a ChangesListFilterGroup or a ChangesListFilter'
303 return $this->priority;
311 return $this->filters;
321 return $this->filters[
$name] ??
null;
333 'name' => $this->name,
334 'type' => $this->type,
335 'fullCoverage' => $this->isFullCoverage,
337 'priority' => $this->priority,
339 'messageKeys' => [ $this->title ]
342 if ( isset( $this->whatsThisHeader ) ) {
343 $output[
'whatsThisHeader'] = $this->whatsThisHeader;
344 $output[
'whatsThisBody'] = $this->whatsThisBody;
345 $output[
'whatsThisUrl'] = $this->whatsThisUrl;
346 $output[
'whatsThisLinkText'] = $this->whatsThisLinkText;
349 $output[
'messageKeys'],
350 $output[
'whatsThisHeader'],
351 $output[
'whatsThisBody'],
352 $output[
'whatsThisLinkText']
360 foreach ( $this->filters as $filter ) {
361 if ( $filter->displaysOnStructuredUi() ) {
362 $filterData = $filter->getJsData();
363 $output[
'messageKeys'] = array_merge(
364 $output[
'messageKeys'],
365 $filterData[
'messageKeys']
367 unset( $filterData[
'messageKeys'] );
368 $output[
'filters'][] = $filterData;
372 if ( count( $output[
'filters'] ) === 0 ) {
376 $output[
'title'] = $this->title;
378 $conflicts = array_merge(
379 $this->conflictingGroups,
380 $this->conflictingFilters
383 foreach ( $conflicts as $conflictInfo ) {
384 unset( $conflictInfo[
'filterObject'] );
385 unset( $conflictInfo[
'groupObject'] );
386 $output[
'conflicts'][] = $conflictInfo;
388 $output[
'messageKeys'],
389 $conflictInfo[
'globalDescription'],
390 $conflictInfo[
'contextDescription']
403 return array_column( $this->conflictingGroups,
'groupObject' );
412 return array_column( $this->conflictingFilters,
'filterObject' );
422 return (
bool)count( array_filter(
447 &$tables, &$fields, &$conds, &$query_options, &$join_conds,
458 $isStructuredFiltersEnabled );
Represents a filter group (used on ChangesListSpecialPage and descendants)
int $priority
Priority integer.
string $name
Name (internal identifier)
string null $whatsThisBody
i18n key for body of What's This?
string $title
i18n key for title
anySelected(FormOptions $opts)
Check if any filter in this group is selected.
string null $whatsThisUrl
URL of What's This? link.
bool $isFullCoverage
Whether this group is full coverage.
getFilter( $name)
Get filter by name.
ChangesListFilter[] $filters
Associative array of filters, as ChangesListFilter objects, with filter name as key.
conflictsWith( $other, string $globalKey, string $forwardKey, string $backwardKey)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
getConflictingGroups()
Get groups conflicting with this filter group.
array $conflictingFilters
Array of associative arrays with conflict information.
modifyQuery(IReadableDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, $isStructuredFiltersEnabled)
Modifies the query to include the filter group.
getJsData()
Gets the JS data in the format required by the front-end of the structured UI.
__construct(array $groupDefinition)
Create a new filter group with the specified configuration.
string null $whatsThisHeader
i18n key for header of What's This?
addOptions(FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled)
All the options represented by this filter group to $opts.
getConflictingFilters()
Get filters conflicting with this filter group.
array $conflictingGroups
Array of associative arrays with conflict information.
setUnidirectionalConflict( $other, $globalDescription, $contextDescription)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
createFilter(array $filterDefinition)
Creates a filter of the appropriate type for this group, from the definition.
string $type
Type, from a TYPE constant of a subclass.
string null $whatsThisLinkText
i18n key for What's This? link
Represents a filter (used on ChangesListSpecialPage and descendants)
isSelected(FormOptions $opts)
Checks whether this filter is selected in the provided options.
Special page which uses a ChangesList to show query results.