X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fspecialpage%2FChangesListSpecialPage.php;h=67f68ea10aa26fc5a61c435a228b9702826d60a6;hp=df6a1c173c3fdc37ca114fbad9ed5ea0abe403c0;hb=d94c0484302f80cf30ef107b2fdb6b84293e1937;hpb=f027550aa3c47326bc81c39e99b28399f1e381c2 diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index df6a1c173c..67f68ea10a 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -629,7 +629,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) { // Only load queries that are 'version' 2, since those // have parameter representation - if ( $savedQueries[ 'version' ] === '2' ) { + if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) { $savedQueryDefaultID = $savedQueries[ 'default' ]; $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ]; @@ -970,6 +970,23 @@ abstract class ChangesListSpecialPage extends SpecialPage { return $unstructuredGroupDefinition; } + /** + * @return array The legacy show/hide toggle filters + */ + protected function getLegacyShowHideFilters() { + $filters = []; + foreach ( $this->filterGroups as $group ) { + if ( $group instanceof ChangesListBooleanFilterGroup ) { + foreach ( $group->getFilters() as $key => $filter ) { + if ( $filter->displaysOnUnstructuredUi( $this ) ) { + $filters[ $key ] = $filter; + } + } + } + } + return $filters; + } + /** * Register all the filters, including legacy hook-driven ones. * Then create a FormOptions object with options as specified by the user @@ -1010,19 +1027,9 @@ abstract class ChangesListSpecialPage extends SpecialPage { // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2; - // Add all filters /** @var ChangesListFilterGroup $filterGroup */ foreach ( $this->filterGroups as $filterGroup ) { - // URL parameters can be per-group, like 'userExpLevel', - // or per-filter, like 'hideminor'. - if ( $filterGroup->isPerGroupRequestParameter() ) { - $opts->add( $filterGroup->getName(), $useDefaults ? $filterGroup->getDefault() : '' ); - } else { - /** @var ChangesListBooleanFilter $filter */ - foreach ( $filterGroup->getFilters() as $filter ) { - $opts->add( $filter->getName(), $useDefaults ? $filter->getDefault( $structuredUI ) : false ); - } - } + $filterGroup->addOptions( $opts, $useDefaults, $structuredUI ); } $opts->add( 'namespace', '', FormOptions::STRING ); @@ -1153,9 +1160,9 @@ abstract class ChangesListSpecialPage extends SpecialPage { // or per-filter, like 'hideminor'. foreach ( $this->filterGroups as $filterGroup ) { - if ( $filterGroup->isPerGroupRequestParameter() ) { + if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup ) { $stringParameterNameSet[$filterGroup->getName()] = true; - } elseif ( $filterGroup->getType() === ChangesListBooleanFilterGroup::TYPE ) { + } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup ) { foreach ( $filterGroup->getFilters() as $filter ) { $hideParameterNameSet[$filter->getName()] = true; } @@ -1185,7 +1192,10 @@ abstract class ChangesListSpecialPage extends SpecialPage { * @param FormOptions $opts */ public function validateOptions( FormOptions $opts ) { - if ( $this->fixContradictoryOptions( $opts ) ) { + $isContradictory = $this->fixContradictoryOptions( $opts ); + $isReplaced = $this->replaceOldOptions( $opts ); + + if ( $isContradictory || $isReplaced ) { $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) ); $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) ); } @@ -1256,6 +1266,34 @@ abstract class ChangesListSpecialPage extends SpecialPage { return false; } + /** + * Replace old options 'hideanons' or 'hideliu' with structured UI equivalent + * + * @param FormOptions $opts + * @return bool True if the change was made + */ + public function replaceOldOptions( FormOptions $opts ) { + if ( !$this->isStructuredFilterUiEnabled() ) { + return false; + } + + // At this point 'hideanons' and 'hideliu' cannot be both true, + // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case + if ( $opts[ 'hideanons' ] ) { + $opts->reset( 'hideanons' ); + $opts[ 'userExpLevel' ] = 'registered'; + return true; + } + + if ( $opts[ 'hideliu' ] ) { + $opts->reset( 'hideliu' ); + $opts[ 'userExpLevel' ] = 'unregistered'; + return true; + } + + return false; + } + /** * Convert parameters values from true/false to 1/0 * so they are not omitted by wfArrayToCgi() @@ -1291,20 +1329,10 @@ abstract class ChangesListSpecialPage extends SpecialPage { $dbr = $this->getDB(); $isStructuredUI = $this->isStructuredFilterUiEnabled(); + /** @var ChangesListFilterGroup $filterGroup */ foreach ( $this->filterGroups as $filterGroup ) { - // URL parameters can be per-group, like 'userExpLevel', - // or per-filter, like 'hideminor'. - if ( $filterGroup->isPerGroupRequestParameter() ) { - $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds, - $query_options, $join_conds, $opts[$filterGroup->getName()] ); - } else { - foreach ( $filterGroup->getFilters() as $filter ) { - if ( $filter->isActive( $opts, $isStructuredUI ) ) { - $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds, - $query_options, $join_conds ); - } - } - } + $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds, + $query_options, $join_conds, $opts, $isStructuredUI ); } // Namespace filtering