queryCallable = $groupDefinition['queryCallable']; if ( isset( $groupDefinition['default'] ) ) { $this->setDefault( $groupDefinition['default'] ); } else { throw new MWException( 'You must specify a default' ); } } /** * Sets default of filter group. * * @param string $defaultValue */ public function setDefault( $defaultValue ) { $this->defaultValue = $defaultValue; } /** * Gets default of filter group * * @return string $defaultValue */ public function getDefault() { return $this->defaultValue; } /** * @inheritDoc */ protected function createFilter( array $filterDefinition ) { return new ChangesListStringOptionsFilter( $filterDefinition ); } /** * Registers a filter in this group * * @param ChangesListStringOptionsFilter $filter */ public function registerFilter( ChangesListStringOptionsFilter $filter ) { $this->filters[$filter->getName()] = $filter; } /** * @inheritDoc */ public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts, $isStructuredFiltersEnabled ) { if ( !$this->isActive( $isStructuredFiltersEnabled ) ) { return; } $value = $opts[ $this->getName() ]; $allowedFilterNames = []; foreach ( $this->filters as $filter ) { $allowedFilterNames[] = $filter->getName(); } if ( $value === self::ALL ) { $selectedValues = $allowedFilterNames; } else { $selectedValues = explode( self::SEPARATOR, strtolower( $value ) ); // remove values that are not recognized or not currently allowed $selectedValues = array_intersect( $selectedValues, $allowedFilterNames ); } // If there are now no values, because all are disallowed or invalid (also, // the user may not have selected any), this is a no-op. // If everything is unchecked, the group always has no effect, regardless // of full-coverage. if ( count( $selectedValues ) === 0 ) { return; } sort( $selectedValues ); call_user_func_array( $this->queryCallable, [ get_class( $specialPage ), $specialPage->getContext(), $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ] ); } /** * @inheritDoc */ public function getJsData() { $output = parent::getJsData(); $output['separator'] = self::SEPARATOR; $output['default'] = $this->getDefault(); return $output; } /** * @inheritDoc */ public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) { $opts->add( $this->getName(), $allowDefaults ? $this->getDefault() : '' ); } /** * Check if this filter group is currently active * * @param bool $isStructuredUI Is structured filters UI current enabled * @return bool */ private function isActive( $isStructuredUI ) { // STRING_OPTIONS filter groups are exclusively active on Structured UI return $isStructuredUI; } }