113 private const RESERVED_NAME_CHAR =
'_';
147 if ( isset( $filterDefinition[
'group'] ) ) {
148 $this->group = $filterDefinition[
'group'];
150 throw new InvalidArgumentException(
'You must use \'group\' to specify the ' .
151 'ChangesListFilterGroup this filter belongs to' );
154 if ( strpos( $filterDefinition[
'name'], self::RESERVED_NAME_CHAR ) !==
false ) {
155 throw new InvalidArgumentException(
'Filter names may not contain \'' .
156 self::RESERVED_NAME_CHAR .
157 '\'. Use the naming convention: \
'lowercase\''
161 if ( $this->group->getFilter( $filterDefinition[
'name'] ) ) {
162 throw new InvalidArgumentException(
'Two filters in a group cannot have the ' .
163 "same name: '{$filterDefinition['name']}'" );
166 $this->name = $filterDefinition[
'name'];
168 if ( isset( $filterDefinition[
'cssClassSuffix'] ) ) {
169 $this->cssClassSuffix = $filterDefinition[
'cssClassSuffix'];
171 $this->isRowApplicableCallable = $filterDefinition[
'isRowApplicableCallable'];
174 if ( isset( $filterDefinition[
'label'] ) ) {
175 $this->label = $filterDefinition[
'label'];
176 $this->description = $filterDefinition[
'description'];
179 $this->priority = $filterDefinition[
'priority'];
181 $this->group->registerFilter( $this );
198 public function conflictsWith( $other,
string $globalKey,
string $forwardKey,
string $backwardKey ) {
205 $other->setUnidirectionalConflict(
225 $this->conflictingGroups[] = [
226 'group' => $other->getName(),
227 'groupObject' => $other,
228 'globalDescription' => $globalDescription,
229 'contextDescription' => $contextDescription,
232 $this->conflictingFilters[] = [
233 'group' => $other->getGroup()->getName(),
234 'filter' => $other->getName(),
235 'filterObject' => $other,
236 'globalDescription' => $globalDescription,
237 'contextDescription' => $contextDescription,
240 throw new InvalidArgumentException(
241 'You can only pass in a ChangesListFilterGroup or a ChangesListFilter'
256 if ( $other->
getGroup() !== $this->getGroup() ) {
257 throw new InvalidArgumentException(
'Supersets can only be defined for filters in the same group' );
260 $this->subsetFilters[] = [
263 'group' => $other->
getGroup()->getName(),
310 return $this->label !==
null;
337 if ( $this->cssClassSuffix !==
null ) {
352 if ( $this->isRowApplicableCallable ===
null ) {
356 if ( call_user_func( $this->isRowApplicableCallable, $ctx, $rc ) ) {
380 $output[
'messageKeys'] = [
385 $conflicts = array_merge(
386 $this->conflictingGroups,
387 $this->conflictingFilters
390 foreach ( $conflicts as $conflictInfo ) {
391 unset( $conflictInfo[
'filterObject'] );
392 unset( $conflictInfo[
'groupObject'] );
393 $output[
'conflicts'][] = $conflictInfo;
395 $output[
'messageKeys'],
396 $conflictInfo[
'globalDescription'],
397 $conflictInfo[
'contextDescription']
418 return array_column( $this->conflictingGroups,
'groupObject' );
427 return array_column( $this->conflictingFilters,
'filterObject' );
440 foreach ( $this->
getSiblings() as $siblingFilter ) {
441 if ( $siblingFilter->isSelected( $opts ) && !$siblingFilter->hasConflictWithGroup(
$group ) ) {
464 foreach ( $this->
getSiblings() as $siblingFilter ) {
466 $siblingFilter->isSelected( $opts ) &&
467 !$siblingFilter->hasConflictWithFilter( $filter )
489 function ( $filter ) {
490 return $filter !== $this;
Represents a filter group (used on ChangesListSpecialPage and descendants)
anySelected(FormOptions $opts)
Check if any filter in this group is selected.
Represents a filter (used on ChangesListSpecialPage and descendants)
displaysOnUnstructuredUi()
Checks whether the filter should display on the unstructured UI.
string null $cssClassSuffix
CSS class suffix used for attribution, e.g.
getConflictingFilters()
Get filters conflicting with this filter.
ChangesListFilterGroup $group
Group.
getJsData()
Gets the JS data required by the front-end of the structured UI.
activelyInConflictWithGroup(ChangesListFilterGroup $group, FormOptions $opts)
Check if the conflict with a group is currently "active".
array $conflictingGroups
Array of associative arrays with conflict information.
conflictsWith( $other, string $globalKey, string $forwardKey, string $backwardKey)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
int $priority
Priority integer.
array $conflictingFilters
Array of associative arrays with conflict information.
displaysOnStructuredUi()
Checks whether the filter should display on the structured UI This refers to the exact filter.
string $label
i18n key of label for structured UI
setUnidirectionalConflict( $other, $globalDescription, $contextDescription)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
isFeatureAvailableOnStructuredUi()
Checks whether an equivalent feature for this filter is available on the structured UI.
applyCssClassIfNeeded(IContextSource $ctx, RecentChange $rc, array &$classes)
Add CSS class if needed.
setAsSupersetOf(ChangesListFilter $other)
Marks that the current instance is (also) a superset of the filter passed in.
__construct(array $filterDefinition)
Creates a new filter with the specified configuration, and registers it to the specified group.
array $subsetFilters
Array of associative arrays with subset information.
isSelected(FormOptions $opts)
Checks whether this filter is selected in the provided options.
setDefaultHighlightColor( $defaultHighlightColor)
string $description
i18n key of description for structured UI
getConflictingGroups()
Get groups conflicting with this filter.
getCssClass()
Gets the CSS class.
string $defaultHighlightColor
getSiblings()
Get filters in the same group.
activelyInConflictWithFilter(ChangesListFilter $filter, FormOptions $opts)
Check if the conflict with a filter is currently "active".
callable $isRowApplicableCallable
Callable that returns true if and only if a row is attributed to this filter.
Utility class for creating new RC entries.
Interface for objects which can provide a MediaWiki context on request.