128 private const DEFAULT_PRIORITY = -100;
130 private const RESERVED_NAME_CHAR =
'_';
159 if ( strpos( $groupDefinition[
'name'], self::RESERVED_NAME_CHAR ) !==
false ) {
160 throw new InvalidArgumentException(
'Group names may not contain \'' .
161 self::RESERVED_NAME_CHAR .
162 '\'. Use the naming convention: \
'camelCase\''
166 $this->name = $groupDefinition[
'name'];
168 if ( isset( $groupDefinition[
'title'] ) ) {
169 $this->title = $groupDefinition[
'title'];
172 if ( isset( $groupDefinition[
'whatsThisHeader'] ) ) {
173 $this->whatsThisHeader = $groupDefinition[
'whatsThisHeader'];
174 $this->whatsThisBody = $groupDefinition[
'whatsThisBody'];
175 $this->whatsThisUrl = $groupDefinition[
'whatsThisUrl'];
176 $this->whatsThisLinkText = $groupDefinition[
'whatsThisLinkText'];
179 $this->type = $groupDefinition[
'type'];
180 $this->priority = $groupDefinition[
'priority'] ?? self::DEFAULT_PRIORITY;
182 $this->isFullCoverage = $groupDefinition[
'isFullCoverage'];
185 $lowestSpecifiedPriority = -1;
186 foreach ( $groupDefinition[
'filters'] as $filterDefinition ) {
187 if ( isset( $filterDefinition[
'priority'] ) ) {
188 $lowestSpecifiedPriority = min( $lowestSpecifiedPriority, $filterDefinition[
'priority'] );
196 $autoFillPriority = $lowestSpecifiedPriority - 1;
197 foreach ( $groupDefinition[
'filters'] as $filterDefinition ) {
198 if ( !isset( $filterDefinition[
'priority'] ) ) {
199 $filterDefinition[
'priority'] = $autoFillPriority;
202 $filterDefinition[
'group'] = $this;
205 $this->registerFilter( $filter );
231 public function conflictsWith( $other,
string $globalKey,
string $forwardKey,
string $backwardKey ) {
238 $other->setUnidirectionalConflict(
258 $this->conflictingGroups[] = [
259 'group' => $other->getName(),
260 'groupObject' => $other,
261 'globalDescription' => $globalDescription,
262 'contextDescription' => $contextDescription,
265 $this->conflictingFilters[] = [
266 'group' => $other->getGroup()->getName(),
267 'filter' => $other->getName(),
268 'filterObject' => $other,
269 'globalDescription' => $globalDescription,
270 'contextDescription' => $contextDescription,
273 throw new InvalidArgumentException(
274 'You can only pass in a ChangesListFilterGroup or a ChangesListFilter'
322 return $this->filters[
$name] ??
null;
343 if ( isset( $this->whatsThisHeader ) ) {
350 $output[
'messageKeys'],
351 $output[
'whatsThisHeader'],
352 $output[
'whatsThisBody'],
353 $output[
'whatsThisLinkText']
361 foreach ( $this->filters as $filter ) {
362 if ( $filter->displaysOnStructuredUi() ) {
363 $filterData = $filter->getJsData();
364 $output[
'messageKeys'] = array_merge(
365 $output[
'messageKeys'],
366 $filterData[
'messageKeys']
368 unset( $filterData[
'messageKeys'] );
369 $output[
'filters'][] = $filterData;
373 if ( count( $output[
'filters'] ) === 0 ) {
379 $conflicts = array_merge(
380 $this->conflictingGroups,
381 $this->conflictingFilters
384 foreach ( $conflicts as $conflictInfo ) {
385 unset( $conflictInfo[
'filterObject'] );
386 unset( $conflictInfo[
'groupObject'] );
387 $output[
'conflicts'][] = $conflictInfo;
389 $output[
'messageKeys'],
390 $conflictInfo[
'globalDescription'],
391 $conflictInfo[
'contextDescription']
404 return array_column( $this->conflictingGroups,
'groupObject' );
413 return array_column( $this->conflictingFilters,
'filterObject' );
423 return (
bool)count( array_filter(
448 &$tables, &$fields, &$conds, &$query_options, &$join_conds,
459 $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.
modifyQuery(IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, $isStructuredFiltersEnabled)
Modifies the query to include the filter group.
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.
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.