X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fspecialpage%2FChangesListSpecialPage.php;h=645fbb288f0d128a46a6edfd61fdf34aa5d4b1c8;hp=1b561ef643e0626be8bed083930a3a83fbdf069c;hb=89539f2aa1b158fdcc703ad053e2580cb97a6385;hpb=15a57aaa1d1f940c57f907d30fed993873890681 diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 1b561ef643..645fbb288f 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -22,6 +22,7 @@ */ use MediaWiki\Logger\LoggerFactory; use Wikimedia\Rdbms\ResultWrapper; +use Wikimedia\Rdbms\FakeResultWrapper; use Wikimedia\Rdbms\IDatabase; /** @@ -85,40 +86,30 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'filters' => [ [ 'name' => 'hideliu', - 'label' => 'rcfilters-filter-registered-label', - 'description' => 'rcfilters-filter-registered-description', // rcshowhideliu-show, rcshowhideliu-hide, // wlshowhideliu 'showHideSuffix' => 'showhideliu', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_user = 0'; }, - 'cssClassSuffix' => 'liu', - 'isRowApplicableCallable' => function ( $ctx, $rc ) { - return $rc->getAttribute( 'rc_user' ); - }, + 'isReplacedInStructuredUi' => true, ], [ 'name' => 'hideanons', - 'label' => 'rcfilters-filter-unregistered-label', - 'description' => 'rcfilters-filter-unregistered-description', // rcshowhideanons-show, rcshowhideanons-hide, // wlshowhideanons 'showHideSuffix' => 'showhideanons', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_user != 0'; }, - 'cssClassSuffix' => 'anon', - 'isRowApplicableCallable' => function ( $ctx, $rc ) { - return !$rc->getAttribute( 'rc_user' ); - }, + 'isReplacedInStructuredUi' => true, ] ], ], @@ -127,9 +118,26 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'name' => 'userExpLevel', 'title' => 'rcfilters-filtergroup-userExpLevel', 'class' => ChangesListStringOptionsFilterGroup::class, - // Excludes unregistered users - 'isFullCoverage' => false, + 'isFullCoverage' => true, 'filters' => [ + [ + 'name' => 'unregistered', + 'label' => 'rcfilters-filter-user-experience-level-unregistered-label', + 'description' => 'rcfilters-filter-user-experience-level-unregistered-description', + 'cssClassSuffix' => 'user-unregistered', + 'isRowApplicableCallable' => function ( $ctx, $rc ) { + return !$rc->getAttribute( 'rc_user' ); + } + ], + [ + 'name' => 'registered', + 'label' => 'rcfilters-filter-user-experience-level-registered-label', + 'description' => 'rcfilters-filter-user-experience-level-registered-description', + 'cssClassSuffix' => 'user-registered', + 'isRowApplicableCallable' => function ( $ctx, $rc ) { + return $rc->getAttribute( 'rc_user' ); + } + ], [ 'name' => 'newcomer', 'label' => 'rcfilters-filter-user-experience-level-newcomer-label', @@ -182,8 +190,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'showHideSuffix' => 'showhidemine', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $user = $ctx->getUser(); $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() ); }, @@ -198,8 +206,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'description' => 'rcfilters-filter-editsbyother-description', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $user = $ctx->getUser(); $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() ); }, @@ -225,8 +233,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'showHideSuffix' => 'showhidebots', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_bot = 0'; }, 'cssClassSuffix' => 'bot', @@ -240,8 +248,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'description' => 'rcfilters-filter-humans-description', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_bot = 1'; }, 'cssClassSuffix' => 'human', @@ -269,8 +277,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'showHideSuffix' => 'showhideminor', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_minor = 0'; }, 'cssClassSuffix' => 'minor', @@ -284,8 +292,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'description' => 'rcfilters-filter-major-description', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_minor = 1'; }, 'cssClassSuffix' => 'major', @@ -347,8 +355,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'default' => false, 'priority' => -2, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT ); }, 'cssClassSuffix' => 'src-mw-edit', @@ -363,8 +371,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'default' => false, 'priority' => -3, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW ); }, 'cssClassSuffix' => 'src-mw-new', @@ -382,8 +390,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'default' => false, 'priority' => -5, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG ); }, 'cssClassSuffix' => 'src-mw-log', @@ -412,8 +420,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'showHideSuffix' => 'showhidepatr', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_patrolled = 0'; }, 'cssClassSuffix' => 'patrolled', @@ -427,8 +435,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'description' => 'rcfilters-filter-unpatrolled-description', 'default' => false, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_patrolled = 1'; }, 'cssClassSuffix' => 'unpatrolled', @@ -450,8 +458,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'default' => false, 'priority' => -4, 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, - &$query_options, &$join_conds ) { - + &$query_options, &$join_conds + ) { $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE ); }, 'cssClassSuffix' => 'src-mw-categorize', @@ -470,7 +478,6 @@ abstract class ChangesListSpecialPage extends SpecialPage { $opts = $this->getOptions(); /** @var ChangesListFilterGroup $group */ foreach ( $this->getFilterGroups() as $group ) { - if ( $group->getConflictingGroups() ) { wfLogWarning( $group->getName() . @@ -487,7 +494,6 @@ abstract class ChangesListSpecialPage extends SpecialPage { /** @var ChangesListFilter $filter */ foreach ( $group->getFilters() as $filter ) { - /** @var ChangesListFilter $conflictingFilter */ foreach ( $filter->getConflictingFilters() as $conflictingFilter ) { if ( @@ -520,13 +526,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { $rows = $this->getRows(); $opts = $this->getOptions(); if ( $rows === false ) { - if ( !$this->including() ) { - $this->doHeader( $opts, 0 ); - $this->outputNoResults(); - $this->getOutput()->setStatusCode( 404 ); - } - - return; + $rows = new FakeResultWrapper( [] ); } $batch = new LinkBatch; @@ -639,19 +639,10 @@ abstract class ChangesListSpecialPage extends SpecialPage { $this->registerFiltersFromDefinitions( [ $unstructuredGroupDefinition ] ); $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' ); - - $registration = $this->getFilterGroup( 'registration' ); - $anons = $registration->getFilter( 'hideanons' ); - - // This means there is a conflict between any item in user experience level - // being checked and only anons being *shown* (hideliu=1&hideanons=0 in the - // URL, or equivalent). - $userExperienceLevel->conflictsWith( - $anons, - 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered-global', - 'rcfilters-filtergroup-user-experience-level-conflicts-unregistered', - 'rcfilters-filter-unregistered-conflicts-user-experience-level' - ); + $registered = $userExperienceLevel->getFilter( 'registered' ); + $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) ); + $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) ); + $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) ); $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' ); $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' ); @@ -1061,8 +1052,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { * @param FormOptions $opts */ protected function buildQuery( &$tables, &$fields, &$conds, &$query_options, - &$join_conds, FormOptions $opts ) { - + &$join_conds, FormOptions $opts + ) { $dbr = $this->getDB(); $user = $this->getUser(); @@ -1121,8 +1112,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { * @return bool|ResultWrapper Result or false */ protected function doMainQuery( $tables, $fields, $conds, - $query_options, $join_conds, FormOptions $opts ) { - + $query_options, $join_conds, FormOptions $opts + ) { $tables[] = 'recentchanges'; $fields = array_merge( RecentChange::selectFields(), $fields ); @@ -1289,9 +1280,14 @@ abstract class ChangesListSpecialPage extends SpecialPage { $legend .= Html::closeElement( 'dl' ) . "\n"; # Collapsibility + $legendHeading = $this->getUser()->getOption( + 'rcenhancedfilters' + ) ? + $context->msg( 'rcfilters-legend-heading' )->parse() : + $context->msg( 'recentchanges-legend-heading' )->parse(); $legend = '
' . - $context->msg( 'recentchanges-legend-heading' )->parse() . + $legendHeading . '
' . $legend . '
' . '
'; @@ -1332,22 +1328,42 @@ abstract class ChangesListSpecialPage extends SpecialPage { * (optional) */ public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr, - &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0 ) { - + &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0 + ) { global $wgLearnerEdits, $wgExperiencedUserEdits, $wgLearnerMemberSince, $wgExperiencedUserMemberSince; - $LEVEL_COUNT = 3; + $LEVEL_COUNT = 5; - // If all levels are selected, all logged-in users are included (but no - // anons), so we can short-circuit. + // If all levels are selected, don't filter if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) { + return; + } + + // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered' + if ( + in_array( 'registered', $selectedExpLevels ) && + in_array( 'unregistered', $selectedExpLevels ) + ) { + return; + } + + // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered' + if ( + in_array( 'registered', $selectedExpLevels ) && + !in_array( 'unregistered', $selectedExpLevels ) + ) { $conds[] = 'rc_user != 0'; return; } + if ( $selectedExpLevels === [ 'unregistered' ] ) { + $conds[] = 'rc_user = 0'; + return; + } + $tables[] = 'user'; $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ]; @@ -1375,24 +1391,39 @@ abstract class ChangesListSpecialPage extends SpecialPage { IDatabase::LIST_AND ); + $conditions = []; + + if ( in_array( 'unregistered', $selectedExpLevels ) ) { + $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] ); + $conditions[] = 'rc_user = 0'; + } + if ( $selectedExpLevels === [ 'newcomer' ] ) { - $conds[] = "NOT ( $aboveNewcomer )"; + $conditions[] = "NOT ( $aboveNewcomer )"; } elseif ( $selectedExpLevels === [ 'learner' ] ) { - $conds[] = $dbr->makeList( + $conditions[] = $dbr->makeList( [ $aboveNewcomer, "NOT ( $aboveLearner )" ], IDatabase::LIST_AND ); } elseif ( $selectedExpLevels === [ 'experienced' ] ) { - $conds[] = $aboveLearner; + $conditions[] = $aboveLearner; } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) { - $conds[] = "NOT ( $aboveLearner )"; + $conditions[] = "NOT ( $aboveLearner )"; } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) { - $conds[] = $dbr->makeList( + $conditions[] = $dbr->makeList( [ "NOT ( $aboveNewcomer )", $aboveLearner ], IDatabase::LIST_OR ); } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) { - $conds[] = $aboveNewcomer; + $conditions[] = $aboveNewcomer; + } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) { + $conditions[] = 'rc_user != 0'; + } + + if ( count( $conditions ) > 1 ) { + $conds[] = $dbr->makeList( $conditions, IDatabase::LIST_OR ); + } elseif ( count( $conditions ) === 1 ) { + $conds[] = reset( $conditions ); } } }