queryCallable = $groupDefinition['queryCallable']; if ( isset( $groupDefinition['default'] ) ) { $this->setDefault( $groupDefinition['default'] ); } else { throw new MWException( 'You must specify a default' ); } } /** * @inheritDoc */ public function isPerGroupRequestParameter() { return true; } /** * 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 ChangesListStringOptionsFilter */ public function registerFilter( ChangesListStringOptionsFilter $filter ) { $this->filters[$filter->getName()] = $filter; } /** * Modifies the query to include the filter group. * * The modification is only done if the filter group is in effect. This means that * one or more valid and allowed filters were selected. * * @param IDatabase $dbr Database, for addQuotes, makeList, and similar * @param ChangesListSpecialPage $specialPage Current special page * @param array &$tables Array of tables; see IDatabase::select $table * @param array &$fields Array of fields; see IDatabase::select $vars * @param array &$conds Array of conditions; see IDatabase::select $conds * @param array &$query_options Array of query options; see IDatabase::select $options * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds * @param string $value URL parameter value */ public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds, $value ) { $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; } /** * Check if this filter group is currently active * * @param {boolean} $isStructuredUI Is structured filters UI current enabled */ public function isActive( $isStructuredUI ) { // STRING_OPTIONS filter groups are exclusively active on Structured UI return $isStructuredUI; } }