110 private const RESERVED_NAME_CHAR =
'_';
144 if ( isset( $filterDefinition[
'group'] ) ) {
145 $this->group = $filterDefinition[
'group'];
147 throw new MWException(
'You must use \'group\' to specify the ' .
148 'ChangesListFilterGroup this filter belongs to' );
151 if ( strpos( $filterDefinition[
'name'], self::RESERVED_NAME_CHAR ) !==
false ) {
152 throw new MWException(
'Filter names may not contain \'' .
153 self::RESERVED_NAME_CHAR .
154 '\'. Use the naming convention: \
'lowercase\''
158 if ( $this->group->getFilter( $filterDefinition[
'name'] ) ) {
159 throw new MWException(
'Two filters in a group cannot have the ' .
160 "same name: '{$filterDefinition['name']}'" );
163 $this->name = $filterDefinition[
'name'];
165 if ( isset( $filterDefinition[
'cssClassSuffix'] ) ) {
166 $this->cssClassSuffix = $filterDefinition[
'cssClassSuffix'];
168 $this->isRowApplicableCallable = $filterDefinition[
'isRowApplicableCallable'];
171 if ( isset( $filterDefinition[
'label'] ) ) {
172 $this->label = $filterDefinition[
'label'];
173 $this->description = $filterDefinition[
'description'];
176 $this->priority = $filterDefinition[
'priority'];
178 $this->group->registerFilter( $this );
195 public function conflictsWith( $other, $globalKey, $forwardKey, $backwardKey ) {
196 if ( $globalKey ===
null || $forwardKey ===
null || $backwardKey ===
null ) {
197 throw new MWException(
'All messages must be specified' );
206 $other->setUnidirectionalConflict(
226 $this->conflictingGroups[] = [
227 'group' => $other->getName(),
228 'groupObject' => $other,
229 'globalDescription' => $globalDescription,
230 'contextDescription' => $contextDescription,
233 $this->conflictingFilters[] = [
234 'group' => $other->getGroup()->getName(),
235 'filter' => $other->getName(),
236 'filterObject' => $other,
237 'globalDescription' => $globalDescription,
238 'contextDescription' => $contextDescription,
241 throw new MWException(
'You can only pass in a ChangesListFilterGroup or a ChangesListFilter' );
255 if ( $other->
getGroup() !== $this->getGroup() ) {
256 throw new MWException(
'Supersets can only be defined for filters in the same group' );
259 $this->subsetFilters[] = [
262 'group' => $other->
getGroup()->getName(),
309 return $this->label !==
null;
336 if ( $this->cssClassSuffix !==
null ) {
351 if ( $this->isRowApplicableCallable ===
null ) {
355 if ( call_user_func( $this->isRowApplicableCallable, $ctx, $rc ) ) {
379 $output[
'messageKeys'] = [
384 $conflicts = array_merge(
385 $this->conflictingGroups,
386 $this->conflictingFilters
389 foreach ( $conflicts as $conflictInfo ) {
390 unset( $conflictInfo[
'filterObject'] );
391 unset( $conflictInfo[
'groupObject'] );
392 $output[
'conflicts'][] = $conflictInfo;
394 $output[
'messageKeys'],
395 $conflictInfo[
'globalDescription'],
396 $conflictInfo[
'contextDescription']
417 return array_column( $this->conflictingGroups,
'groupObject' );
426 return array_column( $this->conflictingFilters,
'filterObject' );
439 foreach ( $this->
getSiblings() as $siblingFilter ) {
440 if ( $siblingFilter->isSelected( $opts ) && !$siblingFilter->hasConflictWithGroup(
$group ) ) {
463 foreach ( $this->
getSiblings() as $siblingFilter ) {
465 $siblingFilter->isSelected( $opts ) &&
466 !$siblingFilter->hasConflictWithFilter( $filter )
488 function ( $filter ) {
489 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.
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.
conflictsWith( $other, $globalKey, $forwardKey, $backwardKey)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
Utility class for creating new RC entries.
Interface for objects which can provide a MediaWiki context on request.