*/
use MediaWiki\Logger\LoggerFactory;
use Wikimedia\Rdbms\ResultWrapper;
+use Wikimedia\Rdbms\FakeResultWrapper;
use Wikimedia\Rdbms\IDatabase;
/**
'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,
]
],
],
'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',
'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() );
},
'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() );
},
'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',
'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',
'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',
'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',
'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',
'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',
'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',
'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',
'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',
'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',
$opts = $this->getOptions();
/** @var ChangesListFilterGroup $group */
foreach ( $this->getFilterGroups() as $group ) {
-
if ( $group->getConflictingGroups() ) {
wfLogWarning(
$group->getName() .
/** @var ChangesListFilter $filter */
foreach ( $group->getFilters() as $filter ) {
-
/** @var ChangesListFilter $conflictingFilter */
foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
if (
$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;
LoggerFactory::getInstance( 'objectcache' )
) );
}
+
+ $this->includeRcFiltersApp();
+ }
+
+ /**
+ * Include the modules and configuration for the RCFilters app.
+ * Conditional on the user having the feature enabled.
+ */
+ protected function includeRcFiltersApp() {
+ if ( $this->isStructuredFilterUiEnabled() ) {
+ $out = $this->getOutput();
+ $jsData = $this->getStructuredFilterJsData();
+
+ $messages = [];
+ foreach ( $jsData['messageKeys'] as $key ) {
+ $messages[$key] = $this->msg( $key )->plain();
+ }
+
+ $out->addHTML(
+ ResourceLoader::makeInlineScript(
+ ResourceLoader::makeMessageSetScript( $messages )
+ )
+ );
+
+ $experimentalStructuredChangeFilters =
+ $this->getConfig()->get( 'StructuredChangeFiltersEnableExperimentalViews' );
+
+ $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
+ $out->addJsConfigVars(
+ 'wgStructuredChangeFiltersEnableExperimentalViews',
+ $experimentalStructuredChangeFilters
+ );
+ $out->addJsConfigVars(
+ 'wgStructuredChangeFiltersEnableLiveUpdate',
+ $this->getConfig()->get( 'StructuredChangeFiltersEnableLiveUpdate' )
+ );
+ $out->addJsConfigVars(
+ 'wgRCFiltersChangeTags',
+ $this->buildChangeTagList()
+ );
+ $out->addJsConfigVars(
+ 'StructuredChangeFiltersDisplayConfig',
+ [
+ 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
+ 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
+ 'limitDefault' => $this->getDefaultLimit(),
+ 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
+ 'daysDefault' => $this->getDefaultDays(),
+ ]
+ );
+ }
+ }
+
+ /**
+ * Fetch the change tags list for the front end
+ *
+ * @return Array Tag data
+ */
+ protected function buildChangeTagList() {
+ $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 );
+ $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 );
+
+ // Hit counts disabled for perf reasons, see T169997
+ /*
+ $tagStats = ChangeTags::tagUsageStatistics();
+ $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
+
+ // Sort by hits
+ arsort( $tagHitCounts );
+ */
+ $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
+
+ // Build the list and data
+ $result = [];
+ foreach ( $tagHitCounts as $tagName => $hits ) {
+ if (
+ // Only get active tags
+ isset( $explicitlyDefinedTags[ $tagName ] ) ||
+ isset( $softwareActivatedTags[ $tagName ] )
+ ) {
+ // Parse description
+ $desc = ChangeTags::tagLongDescriptionMessage( $tagName, $this->getContext() );
+
+ $result[] = [
+ 'name' => $tagName,
+ 'label' => Sanitizer::stripAllTags(
+ ChangeTags::tagDescription( $tagName, $this->getContext() )
+ ),
+ 'description' => $desc ? Sanitizer::stripAllTags( $desc->parse() ) : '',
+ 'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ),
+ 'hits' => $hits,
+ ];
+ }
+ }
+
+ // Instead of sorting by hit count (disabled, see above), sort by display name
+ usort( $result, function ( $a, $b ) {
+ return strcasecmp( $a['label'], $b['label'] );
+ } );
+
+ return $result;
}
/**
$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' );
* @return FormOptions
*/
public function getDefaultOptions() {
- $config = $this->getConfig();
$opts = new FormOptions();
- $structuredUI = $this->getUser()->getOption( 'rcenhancedfilters' );
+ $structuredUI = $this->isStructuredFilterUiEnabled();
// 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 );
}
$opts->add( 'invert', false );
$opts->add( 'associated', false );
$opts->add( 'urlversion', 1 );
+ $opts->add( 'tagfilter', '' );
return $opts;
}
'messageKeys' => [],
];
- $context = $this->getContext();
-
usort( $this->filterGroups, function ( $a, $b ) {
return $b->getPriority() - $a->getPriority();
} );
* @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();
+ $isStructuredUI = $this->isStructuredFilterUiEnabled();
- $context = $this->getContext();
foreach ( $this->filterGroups as $filterGroup ) {
// URL parameters can be per-group, like 'userExpLevel',
// or per-filter, like 'hideminor'.
$query_options, $join_conds, $opts[$filterGroup->getName()] );
} else {
foreach ( $filterGroup->getFilters() as $filter ) {
- if ( $opts[$filter->getName()] ) {
+ if ( $filter->isActive( $opts, $isStructuredUI ) ) {
$filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
$query_options, $join_conds );
}
* @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 );
) . "\n";
$legend .= Html::closeElement( 'dl' ) . "\n";
- # Collapsibility
+ $legendHeading = $this->isStructuredFilterUiEnabled() ?
+ $context->msg( 'rcfilters-legend-heading' )->parse() :
+ $context->msg( 'recentchanges-legend-heading' )->parse();
+
+ # Collapsible
$legend =
'<div class="mw-changeslist-legend">' .
- $context->msg( 'recentchanges-legend-heading' )->parse() .
+ $legendHeading .
'<div class="mw-collapsible-content">' . $legend . '</div>' .
'</div>';
'mediawiki.special.changeslist',
] );
$out->addModules( 'mediawiki.special.changeslist.legend.js' );
+
+ if ( $this->isStructuredFilterUiEnabled() ) {
+ $out->addModules( 'mediawiki.rcfilters.filters.ui' );
+ $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
+ }
}
protected function getGroupName() {
* (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' ];
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 );
+ }
+ }
+
+ /**
+ * Check whether the structured filter UI is enabled
+ *
+ * @return bool
+ */
+ public function isStructuredFilterUiEnabled() {
+ return $this->getUser()->getOption( 'rcenhancedfilters' );
}
+
+ abstract function getDefaultLimit();
+
+ abstract function getDefaultDays();
}