showHide = $filterDefinition['showHide']; } if ( isset( $filterDefinition['isReplacedInStructuredUi'] ) ) { $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi']; } else { $this->isReplacedInStructuredUi = false; } if ( isset( $filterDefinition['default'] ) ) { $this->setDefault( $filterDefinition['default'] ); } else { throw new MWException( 'You must set a default' ); } if ( isset( $filterDefinition['queryCallable'] ) ) { $this->queryCallable = $filterDefinition['queryCallable']; } if ( isset( $filterDefinition['activeValue'] ) ) { $this->activeValue = $filterDefinition['activeValue']; } else { $this->activeValue = true; } } /** * Get the default value * * @param bool $structuredUI Are we currently showing the structured UI * @return bool|null Default value */ public function getDefault( $structuredUI = false ) { return $this->isReplacedInStructuredUi && $structuredUI ? !$this->activeValue : $this->defaultValue; } /** * Sets default. It must be a boolean. * * It will be coerced to boolean. * * @param bool $defaultValue */ public function setDefault( $defaultValue ) { $this->defaultValue = (bool)$defaultValue; } /** * @return string Main i18n key for unstructured UI */ public function getShowHide() { return $this->showHide; } /** * @inheritDoc */ public function displaysOnUnstructuredUi() { return !!$this->showHide; } /** * @inheritDoc */ public function isFeatureAvailableOnStructuredUi() { return $this->isReplacedInStructuredUi || parent::isFeatureAvailableOnStructuredUi(); } /** * Modifies the query to include the filter. This is only called if the filter is * in effect (taking into account the default). * * @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 */ public function modifyQuery( IDatabase $dbr, ChangesListSpecialPage $specialPage, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { if ( $this->queryCallable === null ) { return; } call_user_func_array( $this->queryCallable, [ get_class( $specialPage ), $specialPage->getContext(), $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ] ); } /** * @inheritDoc */ public function getJsData() { $output = parent::getJsData(); $output['default'] = $this->defaultValue; return $output; } /** * @inheritDoc */ public function isSelected( FormOptions $opts ) { return !$opts[ $this->getName() ] && array_filter( $this->getSiblings(), function ( ChangesListBooleanFilter $sibling ) use ( $opts ) { return $opts[ $sibling->getName() ]; } ); } /** * @param FormOptions $opts Query parameters merged with defaults * @param bool $isStructuredUI Whether the structured UI is currently enabled * @return bool Whether this filter should be considered active */ public function isActive( FormOptions $opts, $isStructuredUI ) { if ( $this->isReplacedInStructuredUi && $isStructuredUI ) { return false; } return $opts[ $this->getName() ] === $this->activeValue; } }