X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fchanges%2FChangesListBooleanFilter.php;h=2a7ba8849f209b476261923e496bcad0ab0fab20;hb=5179c299bc112b292f51084ee80afea3878e7386;hp=73c0fb01efc5522b22dde7a9bd6e2b0a790e4724;hpb=16a9c7076f5eb5279d6eb1384751a08a4e33f532;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/changes/ChangesListBooleanFilter.php b/includes/changes/ChangesListBooleanFilter.php index 73c0fb01ef..2a7ba8849f 100644 --- a/includes/changes/ChangesListBooleanFilter.php +++ b/includes/changes/ChangesListBooleanFilter.php @@ -66,6 +66,13 @@ class ChangesListBooleanFilter extends ChangesListFilter { */ protected $queryCallable; + /** + * Value that defined when this filter is considered active + * + * @var bool $activeValue + */ + protected $activeValue; + /** * Create a new filter with the specified configuration. * @@ -90,6 +97,8 @@ class ChangesListBooleanFilter extends ChangesListFilter { * to true. It does not need to be set if the exact same filter is simply visible * on both. * * $filterDefinition['default'] bool Default + * * $filterDefinition['activeValue'] bool This filter is considered active when + * its value is equal to its activeValue. Default is true. * * $filterDefinition['priority'] int Priority integer. Higher value means higher * up in the group's filter list. * * $filterDefinition['queryCallable'] callable Callable accepting parameters, used @@ -118,7 +127,7 @@ class ChangesListBooleanFilter extends ChangesListFilter { } if ( isset( $filterDefinition['default'] ) ) { - $this->defaultValue = $filterDefinition['default']; + $this->setDefault( $filterDefinition['default'] ); } else { throw new MWException( 'You must set a default' ); } @@ -126,6 +135,12 @@ class ChangesListBooleanFilter extends ChangesListFilter { if ( isset( $filterDefinition['queryCallable'] ) ) { $this->queryCallable = $filterDefinition['queryCallable']; } + + if ( isset( $filterDefinition['activeValue'] ) ) { + $this->activeValue = $filterDefinition['activeValue']; + } else { + $this->activeValue = true; + } } /** @@ -136,17 +151,19 @@ class ChangesListBooleanFilter extends ChangesListFilter { */ public function getDefault( $structuredUI = false ) { return $this->isReplacedInStructuredUi && $structuredUI ? - false : + !$this->activeValue : $this->defaultValue; } /** - * Sets default + * Sets default. It must be a boolean. + * + * It will be coerced to boolean. * * @param bool $defaultValue */ public function setDefault( $defaultValue ) { - $this->defaultValue = $defaultValue; + $this->defaultValue = (bool)$defaultValue; } /** @@ -157,14 +174,14 @@ class ChangesListBooleanFilter extends ChangesListFilter { } /** - * @inheritdoc + * @inheritDoc */ public function displaysOnUnstructuredUi() { return !!$this->showHide; } /** - * @inheritdoc + * @inheritDoc */ public function isFeatureAvailableOnStructuredUi() { return $this->isReplacedInStructuredUi || @@ -184,8 +201,8 @@ class ChangesListBooleanFilter extends ChangesListFilter { * @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 ) { - + &$tables, &$fields, &$conds, &$query_options, &$join_conds + ) { if ( $this->queryCallable === null ) { return; } @@ -206,7 +223,7 @@ class ChangesListBooleanFilter extends ChangesListFilter { } /** - * @inheritdoc + * @inheritDoc */ public function getJsData() { $output = parent::getJsData(); @@ -217,12 +234,28 @@ class ChangesListBooleanFilter extends ChangesListFilter { } /** - * @inheritdoc + * @inheritDoc */ public function isSelected( FormOptions $opts ) { return !$opts[ $this->getName() ] && - array_filter( $this->getSiblings(), function ( $sibling ) use ( $opts ) { - return $opts[ $sibling->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; } }