jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/341732 )
Change subject: Add ORES filters to new RCFilters
......................................................................
Add ORES filters to new RCFilters
And port old-style filter to the new hooks.
Bug: T158459
Depends-On: Iec2d82f6a830403d1c948a280efa58992e0cdee7
Change-Id: I82516b0bb5be3b4f3c1a9782b87978a6f01b0c4f
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Hooks.php
M tests/phpunit/includes/HooksTest.php
5 files changed, 320 insertions(+), 439 deletions(-)
Approvals:
Mattflaschen: Looks good to me, approved
Sbisson: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index d0336f0..16c0db0 100644
--- a/extension.json
+++ b/extension.json
@@ -27,8 +27,8 @@
"BeforePageDisplay": [
"ORES\\Hooks::onBeforePageDisplay"
],
- "ChangesListSpecialPageFilters": [
- "ORES\\Hooks::onChangesListSpecialPageFilters"
+ "ChangesListSpecialPageStructuredFilters": [
+ "ORES\\Hooks::onChangesListSpecialPageStructuredFilters"
],
"ChangesListSpecialPageQuery": [
"ORES\\Hooks::onChangesListSpecialPageQuery"
diff --git a/i18n/en.json b/i18n/en.json
index d9e9dbf..7fb37e3 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -17,6 +17,22 @@
"ores-pref-damaging": "ORES sensitivity",
"ores-pref-rc-hidenondamaging": "Hide probably good edits from recent
changes",
"ores-pref-watchlist-hidenondamaging": "Hide probably good edits from
the watchlist",
+ "ores-rcfilters-damaging-title": "Contribution quality predictions",
+ "ores-rcfilters-damaging-likelygood-label": "Very likely good",
+ "ores-rcfilters-damaging-likelygood-desc": "Highly accurate at finding
almost all problem-free edits.",
+ "ores-rcfilters-damaging-maybebad-label": "May have problems",
+ "ores-rcfilters-damaging-maybebad-desc": "Finds most flawed or damaging
edits but with lower accuracy.",
+ "ores-rcfilters-damaging-likelybad-label": "Likely have problems",
+ "ores-rcfilters-damaging-likelybad-desc": "Finds half of flawed or
damaging edits with medium accuracy.",
+ "ores-rcfilters-damaging-verylikelybad-label": "Very likely have
problems",
+ "ores-rcfilters-damaging-verylikelybad-desc": "Highly accurate at
finding the most obvious 10% of flawed or damaging edits.",
+ "ores-rcfilters-goodfaith-title": "User intent predictions",
+ "ores-rcfilters-goodfaith-good-label": "Very likely good faith",
+ "ores-rcfilters-goodfaith-good-desc": "Highly accurate at finding
almost all good-faith edits.",
+ "ores-rcfilters-goodfaith-maybebad-label": "May be bad faith",
+ "ores-rcfilters-goodfaith-maybebad-desc": "Finds most bad-faith edits
but with a lower accuracy.",
+ "ores-rcfilters-goodfaith-bad-label": "Likely bad faith",
+ "ores-rcfilters-goodfaith-bad-desc": "With medium accuracy, finds the
most obvious obvious 25% of bad-faith edits.",
"prefs-ores" : "Revision scoring",
"apihelp-query+ores-description": "Return ORES configuration and model
data for this wiki.",
"apihelp-query+ores-example-simple": "Fetch ORES data:",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index a7c63ba..1a58bfd 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -21,6 +21,22 @@
"ores-pref-damaging": "Part asking for damaging threshold",
"ores-pref-rc-hidenondamaging": "Display message for user preferences
to make hidenondamaging default in recent changes",
"ores-pref-watchlist-hidenondamaging": "Display message for user
preferences to make hidenondamaging default in the watchlist",
+ "ores-rcfilters-damaging-title": "Title for the filter group for ORES
damaging score.",
+ "ores-rcfilters-damaging-likelygood-label": "Label for the filter for
showing edits that are very likely to be non-damaging.",
+ "ores-rcfilters-damaging-likelygood-desc": "Description for the filter
for showing edits that are very likely to be non-damaging.",
+ "ores-rcfilters-damaging-maybebad-label": "Label for the filter for
showing edits that are somewhat likely to be damaging.",
+ "ores-rcfilters-damaging-maybebad-desc": "Description for the filter
for showing edits that are somewhat likely to be damaging.",
+ "ores-rcfilters-damaging-likelybad-label": "Label for the filter for
showing edits that are somewhat likely to be damaging.",
+ "ores-rcfilters-damaging-likelybad-desc": "Description for the filter
for showing edits that are somewhat likely to be damaging.",
+ "ores-rcfilters-damaging-verylikelybad-label": "Label for the filter
for showing edits that are somewhat likely to be damaging.",
+ "ores-rcfilters-damaging-verylikelybad-desc": "Description for the
filter for showing edits that are somewhat likely to be damaging.",
+ "ores-rcfilters-goodfaith-title": "Title for the filter group for ORES
good faith score.",
+ "ores-rcfilters-goodfaith-good-label": "Label for the filter for
showing edits that are very likely to be good faith.",
+ "ores-rcfilters-goodfaith-good-desc": "Description for the filter for
showing edits that are very likely to be good faith.",
+ "ores-rcfilters-goodfaith-maybebad-label": "Label for the filter for
showing edits that are somewhat likely to be bad faith.",
+ "ores-rcfilters-goodfaith-maybebad-desc": "Description for the filter
for showing edits that are somewhat likely to be bad faith.",
+ "ores-rcfilters-goodfaith-bad-label": "Label for the filter for showing
edits that are likely to be bad faith.",
+ "ores-rcfilters-goodfaith-bad-desc": "Description for the filter for
showing edits that are likely to be bad faith.",
"prefs-ores": "Name of ORES section in preferences",
"apihelp-query+ores-description":
"{{doc-apihelp-description|query+ores}}",
"apihelp-query+ores-example-simple":
"{{doc-apihelp-example|query+ores}}",
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 09e3916..975331f 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -4,7 +4,10 @@
use BetaFeatures;
use ChangesList;
+use ChangesListBooleanFilterGroup;
+use ChangesListFilterGroup;
use ChangesListSpecialPage;
+use ChangesListStringOptionsFilterGroup;
use ContribsPager;
use DatabaseUpdater;
use EnhancedChangesList;
@@ -77,56 +80,179 @@
}
}
- /**
- * Add an ORES filter to the recent changes results
- *
- * @param ChangesListSpecialPage $clsp
- * @param $filters
- */
- public static function onChangesListSpecialPageFilters(
- ChangesListSpecialPage $clsp,
- &$filters
+ public static function onChangesListSpecialPageStructuredFilters(
+ ChangesListSpecialPage $clsp
) {
if ( !self::oresEnabled( $clsp->getUser() ) ) {
return;
}
+ $stats = Stats::newFromGlobalState();
if ( self::isModelEnabled( 'damaging' ) ) {
- switch ( $clsp->getName() ) {
- case 'Watchlist':
- $default = $clsp->getUser()->getOption(
'oresWatchlistHideNonDamaging' );
- break;
- case 'Recentchanges':
- $default = $clsp->getUser()->getOption(
'oresRCHideNonDamaging' );
- break;
- default:
- $default = false;
+ $damagingLevels = $stats->getThresholds( 'damaging' );
+ $newDamagingGroup = new
ChangesListStringOptionsFilterGroup( [
+ 'name' => 'damaging',
+ 'title' => 'ores-rcfilters-damaging-title',
+ 'priority' => 2,
+ 'filters' => [
+ [
+ 'name' => 'likelygood',
+ 'label' =>
'ores-rcfilters-damaging-likelygood-label',
+ 'description' =>
'ores-rcfilters-damaging-likelygood-desc',
+ 'cssClassSuffix' =>
'damaging-likelygood',
+ 'isRowApplicableCallable' =>
self::makeApplicableCallback(
+ 'damaging',
+
$damagingLevels['likelygood']
+ ),
+ ],
+ [
+ 'name' => 'maybebad',
+ 'label' =>
'ores-rcfilters-damaging-maybebad-label',
+ 'description' =>
'ores-rcfilters-damaging-maybebad-desc',
+ 'cssClassSuffix' =>
'damaging-maybebad',
+ 'isRowApplicableCallable' =>
self::makeApplicableCallback(
+ 'damaging',
+
$damagingLevels['maybebad']
+ ),
+ ],
+ [
+ 'name' => 'likelybad',
+ 'label' =>
'ores-rcfilters-damaging-likelybad-label',
+ 'description' =>
'ores-rcfilters-damaging-likelybad-desc',
+ 'cssClassSuffix' =>
'damaging-likelybad',
+ 'isRowApplicableCallable' =>
self::makeApplicableCallback(
+ 'damaging',
+
$damagingLevels['likelybad']
+ ),
+ ],
+ [
+ 'name' => 'verylikelybad',
+ 'label' =>
'ores-rcfilters-damaging-verylikelybad-label',
+ 'description' =>
'ores-rcfilters-damaging-verylikelybad-desc',
+ 'cssClassSuffix' =>
'damaging-verylikelybad',
+ 'isRowApplicableCallable' =>
self::makeApplicableCallback(
+ 'damaging',
+
$damagingLevels['verylikelybad']
+ ),
+ ],
+ ],
+ 'default' =>
ChangesListStringOptionsFilterGroup::NONE,
+ 'isFullCoverage' => false,
+ 'queryCallable' => function (
$specialClassName, $ctx, $dbr, &$tables, &$fields,
+ &$conds, &$query_options,
&$join_conds, $selectedValues ) {
+ $condition = self::buildRangeFilter(
'damaging', $selectedValues );
+ if ( $condition ) {
+ $conds[] = $condition;
+
$join_conds['ores_damaging_mdl'][0] = 'INNER JOIN';
+
$join_conds['ores_damaging_cls'][0] = 'INNER JOIN';
+ // Performance hack: add
STRAIGHT_JOIN (146111)
+ $query_options[] =
'STRAIGHT_JOIN';
+ }
+ },
+ ] );
+ $newDamagingGroup->getFilter( 'maybebad'
)->setAsSupersetOf(
+ $newDamagingGroup->getFilter( 'likelybad' )
+ );
+ $newDamagingGroup->getFilter( 'likelybad'
)->setAsSupersetOf(
+ $newDamagingGroup->getFilter( 'verylikelybad' )
+ );
+ // Transitive closure
+ $newDamagingGroup->getFilter( 'maybebad'
)->setAsSupersetOf(
+ $newDamagingGroup->getFilter( 'verylikelybad' )
+ );
+ $clsp->registerFilterGroup( $newDamagingGroup );
+
+ if ( $clsp->getName() === 'Recentchanges' ) {
+ $damagingDefault = $clsp->getUser()->getOption(
'oresRCHideNonDamaging' );
+ } elseif ( $clsp->getName() === 'Watchlist' ) {
+ $damagingDefault = $clsp->getUser()->getOption(
'oresWatchlistHideNonDamaging' );
+ } else {
+ $damagingDefault = false;
}
- $filters['hidenondamaging'] = [
- 'msg' => 'ores-damaging-filter',
- 'default' => $default,
- ];
+ $legacyDamagingGroup = new
ChangesListBooleanFilterGroup( [
+ 'name' => 'ores',
+ 'filters' => [
+ [
+ 'name' => 'hidenondamaging',
+ 'showHide' =>
'ores-damaging-filter',
+ 'isReplacedInStructuredUi' =>
true,
+ 'default' => $damagingDefault,
+ 'queryCallable' => function (
$specialClassName, $ctx, $dbr, &$tables,
+ &$fields,
&$conds, &$query_options, &$join_conds ) {
+
self::hideNonDamagingFilter( $fields, $conds, true, $ctx->getUser() );
+ $conds['rc_patrolled']
= 0;
+
$join_conds['ores_damaging_mdl'][0] = 'INNER JOIN';
+
$join_conds['ores_damaging_cls'][0] = 'INNER JOIN';
+ // Performance hack:
add STRAIGHT_JOIN (146111)
+ $query_options[] =
'STRAIGHT_JOIN';
+ },
+ ]
+ ],
- $filters['damaging'] = [ 'msg' => false, 'default' =>
'all' ];
+ ] );
+ $clsp->registerFilterGroup( $legacyDamagingGroup );
}
-
if ( self::isModelEnabled( 'goodfaith' ) ) {
- $filters['goodfaith'] = [ 'msg' => false, 'default' =>
'all' ];
+ $goodfaithLevels = $stats->getThresholds( 'goodfaith' );
+ $goodfaithGroup = new
ChangesListStringOptionsFilterGroup( [
+ 'name' => 'goodfaith',
+ 'title' => 'ores-rcfilters-goodfaith-title',
+ 'priority' => 1,
+ 'filters' => [
+ [
+ 'name' => 'good',
+ 'label' =>
'ores-rcfilters-goodfaith-good-label',
+ 'description' =>
'ores-rcfilters-goodfaith-good-desc',
+ 'cssClassSuffix' =>
'goodfaith-good',
+ 'isRowApplicableCallable' =>
self::makeApplicableCallback(
+ 'goodfaith',
+ $goodfaithLevels['good']
+ ),
+ ],
+ [
+ // HACK the front-end doesn't
support StringOptionsFilters with the same name
+ 'name' => 'maybebadfaith',
+ 'label' =>
'ores-rcfilters-goodfaith-maybebad-label',
+ 'description' =>
'ores-rcfilters-goodfaith-maybebad-desc',
+ 'cssClassSuffix' =>
'goodfaith-maybebad',
+ 'isRowApplicableCallable' =>
self::makeApplicableCallback(
+ 'goodfaith',
+
$goodfaithLevels['maybebad']
+ ),
+ ],
+ [
+ 'name' => 'bad',
+ 'label' =>
'ores-rcfilters-goodfaith-bad-label',
+ 'description' =>
'ores-rcfilters-goodfaith-bad-desc',
+ 'cssClassSuffix' =>
'goodfaith-bad',
+ 'isRowApplicableCallable' =>
self::makeApplicableCallback(
+ 'goodfaith',
+ $goodfaithLevels['bad']
+ ),
+ ],
+ ],
+ 'default' =>
ChangesListStringOptionsFilterGroup::NONE,
+ 'isFullCoverage' => false,
+ 'queryCallable' => function (
$specialClassName, $ctx, $dbr, &$tables, &$fields,
+ &$conds, &$query_options,
&$join_conds, $selectedValues ) {
+ $condition = self::buildRangeFilter(
'goodfaith', $selectedValues );
+ if ( $condition ) {
+ $conds[] = $condition;
+
$join_conds['ores_goodfaith_mdl'][0] = 'INNER JOIN';
+
$join_conds['ores_goodfaith_cls'][0] = 'INNER JOIN';
+ // Performance hack: add
STRAIGHT_JOIN (146111)
+ $query_options[] =
'STRAIGHT_JOIN';
+ }
+ },
+ ] );
+ $goodfaithGroup->getFilter( 'maybebadfaith'
)->setAsSupersetOf(
+ $goodfaithGroup->getFilter( 'bad' )
+ );
+ $clsp->registerFilterGroup( $goodfaithGroup );
}
}
- /**
- * Pull in ORES score columns during recent changes queries
- *
- * @param string $name
- * @param array $tables
- * @param array $fields
- * @param array $conds
- * @param array $query_options
- * @param array $join_conds
- * @param FormOptions $opts
- */
public static function onChangesListSpecialPageQuery(
$name, array &$tables, array &$fields, array &$conds,
array &$query_options, array &$join_conds, FormOptions $opts
@@ -138,7 +264,6 @@
}
if ( self::isModelEnabled( 'damaging' ) ) {
-
self::joinWithOresTables(
'damaging',
'rc_this_oldid',
@@ -146,35 +271,7 @@
$fields,
$join_conds
);
-
- $damaging = $opts->getValue( 'damaging' );
- $hideNonDamaging = $opts->getValue( 'hidenondamaging' );
-
- $filtering = false;
-
- if ( $damaging !== 'all' ) {
- $damagingCondition = self::buildRangeFilter(
- 'damaging',
- $damaging
- );
- if ( $damagingCondition ) {
- $conds[] = $damagingCondition;
- $filtering = true;
- }
- } elseif ( $hideNonDamaging ) {
- self::hideNonDamagingFilter( $fields, $conds,
$hideNonDamaging, $wgUser );
- $conds['rc_patrolled'] = 0;
- $filtering = true;
- }
-
- if ( $filtering ) {
- $join_conds["ores_damaging_mdl"][0] = 'INNER
JOIN';
- $join_conds["ores_damaging_cls"][0] = 'INNER
JOIN';
- // Performance hack: add STRAIGHT_JOIN (146111)
- $query_options[] = 'STRAIGHT_JOIN';
- }
}
-
if ( self::isModelEnabled( 'goodfaith' ) ) {
self::joinWithOresTables(
'goodfaith',
@@ -183,17 +280,6 @@
$fields,
$join_conds
);
- $condition = self::buildRangeFilter(
- 'goodfaith',
- $opts->getValue( 'goodfaith' )
- );
- if ( $condition ) {
- $conds[] = $condition;
- $join_conds["ores_goodfaith_mdl"][0] = 'INNER
JOIN';
- $join_conds["ores_goodfaith_cls"][0] = 'INNER
JOIN';
- // Performance hack: add STRAIGHT_JOIN (146111)
- $query_options[] = 'STRAIGHT_JOIN';
- }
}
}
@@ -271,10 +357,6 @@
$parts[1] = ChangesList::flag( 'damaging' ) . $parts[1];
$s = implode( $separator, $parts );
}
-
- $stats = Stats::newFromGlobalState();
- self::addClasses( 'goodfaith', $rc, $classes );
- self::addClasses( 'damaging', $rc, $classes );
return true;
}
@@ -402,10 +484,6 @@
$classes[] = 'damaging';
$data['recentChangesFlags']['damaging'] = true;
}
-
- $stats = Stats::newFromGlobalState();
- self::addClasses( 'goodfaith', $rcObj, $classes );
- self::addClasses( 'damaging', $rcObj, $classes );
}
/**
@@ -631,7 +709,8 @@
$stats = Stats::newFromGlobalState();
$thresholds = $stats->getThresholds( $name );
- $selectedLevels = explode( ',', strtolower( $filterValue ) );
+ $selectedLevels = is_array( $filterValue ) ? $filterValue :
+ explode( ',', strtolower( $filterValue ) );
$selectedLevels = array_intersect(
$selectedLevels,
array_keys( $thresholds )
@@ -672,36 +751,14 @@
}
}
- private static function addClasses( $model, $rc, &$classes ) {
- if ( !self::isModelEnabled( $model ) ) {
- return;
- }
-
- $score = $rc->getAttribute( "ores_{$model}_score" );
- if ( $score === null ) {
- return;
- }
-
- $stats = Stats::newFromGlobalState();
- $levelsDefinition = $stats->getThresholds( $model );
- if ( !$levelsDefinition ) {
- return;
- }
-
- $levels = array_keys(
- array_filter(
- $levelsDefinition,
- function ( $level ) use ( $score ) {
- return $level['min'] <= $score &&
$score <= $level['max'];
- }
- )
- );
-
- if ( $levels ) {
- foreach ( $levels as $level ) {
- $classes[] = "mw-changeslist-$model-$level";
+ private static function makeApplicableCallback( $model, array
$levelData ) {
+ return function ( $ctx, $rc ) use ( $model, $levelData ) {
+ $score = $rc->getAttribute( "ores_{$model}_score" );
+ if ( $score === null ) {
+ return false;
}
- }
+ return $levelData['min'] <= $score && $score <=
$levelData['max'];
+ };
}
}
diff --git a/tests/phpunit/includes/HooksTest.php
b/tests/phpunit/includes/HooksTest.php
index 7b1122d..9155431 100644
--- a/tests/phpunit/includes/HooksTest.php
+++ b/tests/phpunit/includes/HooksTest.php
@@ -63,127 +63,14 @@
$this->assertFalse( ORES\Hooks::getScoreRecentChangesList( $rc,
$this->context ) );
}
- public function testOnChangesListSpecialPageFilters() {
- $filters = [];
- $clsp = $this->getMock( ChangesListSpecialPage::class );
-
- $clsp->expects( $this->any() )
- ->method( 'getUser' )
- ->will( $this->returnValue( $this->user ) );
-
- $clsp->expects( $this->any() )
- ->method( 'getContext' )
- ->will( $this->returnValue( $this->context ) );
-
- ORES\Hooks::onChangesListSpecialPageFilters( $clsp, $filters );
- $expected = [
- 'hidenondamaging' => [ 'msg' => 'ores-damaging-filter',
'default' => false ],
- 'damaging' => [ 'msg' => false, 'default' => 'all' ],
- 'goodfaith' => [ 'msg' => false, 'default' => 'all' ],
- ];
- $this->assertSame( $expected, $filters );
- }
-
- public function testOnChangesListSpecialPageQuery_hidenondamaging() {
- $this->setMwGlobals( [
- 'wgUser' => $this->user,
- 'wgOresModels' => [
- 'damaging' => true,
- 'goodfaith' => false,
- ]
- ] );
-
- $opts = new FormOptions();
-
- $opts->add( 'hidenondamaging', true, 2 );
- $opts->add( 'damaging', 'all' );
- $opts->add( 'goodfaith', 'all' );
-
- $tables = [];
- $fields = [];
- $conds = [];
- $query_options = [];
- $join_conds = [];
- ORES\Hooks::onChangesListSpecialPageQuery(
- '',
- $tables,
- $fields,
- $conds,
- $query_options,
- $join_conds,
- $opts
- );
- $expected = [
- 'tables' => [
- 'ores_damaging_mdl' => 'ores_model',
- 'ores_damaging_cls' => 'ores_classification'
- ],
- 'fields' => [
- 'ores_damaging_score' =>
'ores_damaging_cls.oresc_probability',
- 'ores_damaging_threshold' => "'0.7'"
- ],
- 'conds' => [
- "ores_damaging_cls.oresc_probability > '0.7'",
- 'rc_patrolled' => 0,
- ],
- 'query_options' => [ 'STRAIGHT_JOIN' ],
- 'join_conds' => [
- 'ores_damaging_mdl' => [ 'INNER JOIN',
- [
-
'ores_damaging_mdl.oresm_is_current' => 1,
- 'ores_damaging_mdl.oresm_name'
=> 'damaging'
- ]
- ],
- 'ores_damaging_cls' => [ 'INNER JOIN',
- [
- 'ores_damaging_cls.oresc_model
= ores_damaging_mdl.oresm_id',
- 'rc_this_oldid =
ores_damaging_cls.oresc_rev',
- 'ores_damaging_cls.oresc_class'
=> 1
- ]
- ]
- ],
- ];
- $this->assertSame( $expected['tables'], $tables );
- $this->assertSame( $expected['fields'], $fields );
- $this->assertSame( $expected['conds'], $conds );
- $this->assertSame( $expected['query_options'], $query_options );
- $this->assertSame( $expected['join_conds'], $join_conds );
- }
-
- public function onChangesListSpecialPageQuery_goodfaith_provider() {
- return [
- [ 'good', 0.35, 1 ],
- [ 'maybebad', 0, 0.65 ],
- [ 'bad', 0, 0.15 ],
- [ 'good,maybebad', 0, 1 ],
- [ 'maybebad,bad', 0, 0.65 ],
- [ 'good,maybebad,bad', 0, 1 ],
- ];
- }
-
/**
- * @dataProvider onChangesListSpecialPageQuery_goodfaith_provider
+ * @dataProvider onChangesListSpecialPageQuery_provider
*/
- public function testOnChangesListSpecialPageQuery_goodfaith(
- $goodfaithValue,
- $expectedMin,
- $expectedMax
- ) {
+ public function testOnChangesListSpecialPageQuery( $modelConfig,
$expectedQuery ) {
$this->setMwGlobals( [
'wgUser' => $this->user,
- 'wgOresModels' => [
- 'damaging' => false,
- 'goodfaith' => true,
- ]
+ 'wgOresModels' => $modelConfig
] );
-
- $this->mockStatsInCache();
-
- $opts = new FormOptions();
-
- $opts->add( 'hidenondamaging', false );
- $opts->add( 'goodfaith', $goodfaithValue );
-
$tables = [];
$fields = [];
$conds = [];
@@ -196,196 +83,121 @@
$conds,
$query_options,
$join_conds,
- $opts
+ new FormOptions()
);
- $expected = [
- 'tables' => [
- 'ores_goodfaith_mdl' => 'ores_model',
- 'ores_goodfaith_cls' => 'ores_classification'
+ $this->assertSame( $expectedQuery['tables'], $tables );
+ $this->assertSame( $expectedQuery['fields'], $fields );
+ $this->assertSame( $expectedQuery['join_conds'], $join_conds );
+ }
+
+ public function onChangesListSpecialPageQuery_provider() {
+ return [
+ [
+ [ 'damaging' => false, 'goodfaith' => false ],
+ [
+ 'tables' => [],
+ 'fields' => [],
+ 'join_conds' => []
+ ]
],
- 'fields' => [
- 'ores_goodfaith_score' =>
'ores_goodfaith_cls.oresc_probability',
- ],
- 'conds' => [
- "(ores_goodfaith_cls.oresc_probability BETWEEN
$expectedMin AND $expectedMax)"
- ],
- 'join_conds' => [
- 'ores_goodfaith_mdl' => [ 'INNER JOIN',
- [
-
'ores_goodfaith_mdl.oresm_is_current' => 1,
- 'ores_goodfaith_mdl.oresm_name'
=> 'goodfaith'
- ]
- ],
- 'ores_goodfaith_cls' => [ 'INNER JOIN',
- [
- 'ores_goodfaith_cls.oresc_model
= ores_goodfaith_mdl.oresm_id',
- 'rc_this_oldid =
ores_goodfaith_cls.oresc_rev',
-
'ores_goodfaith_cls.oresc_class' => 1
+ [
+ [ 'damaging' => true, 'goodfaith' => false ],
+ [
+ 'tables' => [
+ 'ores_damaging_mdl' =>
'ores_model',
+ 'ores_damaging_cls' =>
'ores_classification'
+ ],
+ 'fields' => [
+ 'ores_damaging_score' =>
'ores_damaging_cls.oresc_probability',
+ ],
+ 'join_conds' => [
+ 'ores_damaging_mdl' => [ 'LEFT
JOIN',
+ [
+
'ores_damaging_mdl.oresm_is_current' => 1,
+
'ores_damaging_mdl.oresm_name' => 'damaging'
+ ]
+ ],
+ 'ores_damaging_cls' => [ 'LEFT
JOIN',
+ [
+
'ores_damaging_cls.oresc_model = ores_damaging_mdl.oresm_id',
+ 'rc_this_oldid
= ores_damaging_cls.oresc_rev',
+
'ores_damaging_cls.oresc_class' => 1
+ ]
+ ]
]
]
],
- ];
- $this->assertSame( $expected['tables'], $tables );
- $this->assertSame( $expected['fields'], $fields );
- $this->assertSame( $expected['conds'], $conds );
- $this->assertSame( $expected['join_conds'], $join_conds );
- }
-
- public function testOnChangesListSpecialPageQuery_damaging() {
- $this->setMwGlobals( [
- 'wgUser' => $this->user,
- 'wgOresModels' => [
- 'damaging' => true,
- 'goodfaith' => false,
+ [
+ [ 'damaging' => false, 'goodfaith' => true ],
+ [
+ 'tables' => [
+ 'ores_goodfaith_mdl' =>
'ores_model',
+ 'ores_goodfaith_cls' =>
'ores_classification'
+ ],
+ 'fields' => [
+ 'ores_goodfaith_score' =>
'ores_goodfaith_cls.oresc_probability',
+ ],
+ 'join_conds' => [
+ 'ores_goodfaith_mdl' => [ 'LEFT
JOIN',
+ [
+
'ores_goodfaith_mdl.oresm_is_current' => 1,
+
'ores_goodfaith_mdl.oresm_name' => 'goodfaith'
+ ]
+ ],
+ 'ores_goodfaith_cls' => [ 'LEFT
JOIN',
+ [
+
'ores_goodfaith_cls.oresc_model = ores_goodfaith_mdl.oresm_id',
+ 'rc_this_oldid
= ores_goodfaith_cls.oresc_rev',
+
'ores_goodfaith_cls.oresc_class' => 1
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [ 'damaging' => true, 'goodfaith' => true ],
+ [
+ 'tables' => [
+ 'ores_damaging_mdl' =>
'ores_model',
+ 'ores_damaging_cls' =>
'ores_classification',
+ 'ores_goodfaith_mdl' =>
'ores_model',
+ 'ores_goodfaith_cls' =>
'ores_classification'
+ ],
+ 'fields' => [
+ 'ores_damaging_score' =>
'ores_damaging_cls.oresc_probability',
+ 'ores_goodfaith_score' =>
'ores_goodfaith_cls.oresc_probability',
+ ],
+ 'join_conds' => [
+ 'ores_damaging_mdl' => [ 'LEFT
JOIN',
+ [
+
'ores_damaging_mdl.oresm_is_current' => 1,
+
'ores_damaging_mdl.oresm_name' => 'damaging'
+ ]
+ ],
+ 'ores_damaging_cls' => [ 'LEFT
JOIN',
+ [
+
'ores_damaging_cls.oresc_model = ores_damaging_mdl.oresm_id',
+ 'rc_this_oldid
= ores_damaging_cls.oresc_rev',
+
'ores_damaging_cls.oresc_class' => 1
+ ]
+ ],
+ 'ores_goodfaith_mdl' => [ 'LEFT
JOIN',
+ [
+
'ores_goodfaith_mdl.oresm_is_current' => 1,
+
'ores_goodfaith_mdl.oresm_name' => 'goodfaith'
+ ]
+ ],
+ 'ores_goodfaith_cls' => [ 'LEFT
JOIN',
+ [
+
'ores_goodfaith_cls.oresc_model = ores_goodfaith_mdl.oresm_id',
+ 'rc_this_oldid
= ores_goodfaith_cls.oresc_rev',
+
'ores_goodfaith_cls.oresc_class' => 1
+ ]
+ ]
+ ]
+ ]
]
- ] );
-
- $this->mockStatsInCache();
-
- $opts = new FormOptions();
-
- $opts->add( 'hidenondamaging', false );
- $opts->add( 'damaging', 'maybebad' );
-
- $tables = [];
- $fields = [];
- $conds = [];
- $query_options = [];
- $join_conds = [];
- ORES\Hooks::onChangesListSpecialPageQuery(
- '',
- $tables,
- $fields,
- $conds,
- $query_options,
- $join_conds,
- $opts
- );
- $expected = [
- 'tables' => [
- 'ores_damaging_mdl' => 'ores_model',
- 'ores_damaging_cls' => 'ores_classification',
- ],
- 'fields' => [
- 'ores_damaging_score' =>
'ores_damaging_cls.oresc_probability',
- ],
- 'conds' => [
- '(ores_damaging_cls.oresc_probability BETWEEN
0.16 AND 1)',
- ],
- 'join_conds' => [
- 'ores_damaging_mdl' => [ 'INNER JOIN',
- [
-
'ores_damaging_mdl.oresm_is_current' => 1,
- 'ores_damaging_mdl.oresm_name'
=> 'damaging',
- ]
- ],
- 'ores_damaging_cls' => [ 'INNER JOIN',
- [
- 'ores_damaging_cls.oresc_model
= ores_damaging_mdl.oresm_id',
- 'rc_this_oldid =
ores_damaging_cls.oresc_rev',
- 'ores_damaging_cls.oresc_class'
=> 1,
- ]
- ]
- ],
];
- $this->assertSame( $expected['tables'], $tables );
- $this->assertSame( $expected['fields'], $fields );
- $this->assertSame( $expected['conds'], $conds );
- $this->assertSame( $expected['join_conds'], $join_conds );
- }
-
- public function testOnChangesListSpecialPageQuery_goodfaith_goodbad() {
- $this->setMwGlobals( [
- 'wgUser' => $this->user,
- 'wgOresModels' => [
- 'damaging' => false,
- 'goodfaith' => true,
- ]
- ] );
-
- $this->mockStatsInCache();
-
- $opts = new FormOptions();
-
- $opts->add( 'hidenondamaging', false );
- $opts->add( 'goodfaith', 'good,bad' );
-
- $tables = [];
- $fields = [];
- $conds = [];
- $query_options = [];
- $join_conds = [];
- ORES\Hooks::onChangesListSpecialPageQuery(
- '',
- $tables,
- $fields,
- $conds,
- $query_options,
- $join_conds,
- $opts
- );
- $expected = [
- 'tables' => [
- 'ores_goodfaith_mdl' => 'ores_model',
- 'ores_goodfaith_cls' => 'ores_classification'
- ],
- 'fields' => [
- 'ores_goodfaith_score' =>
'ores_goodfaith_cls.oresc_probability',
- ],
- 'conds' => [
- "(ores_goodfaith_cls.oresc_probability BETWEEN
0.35 AND 1) OR " .
- "(ores_goodfaith_cls.oresc_probability BETWEEN
0 AND 0.15)",
- ],
- 'join_conds' => [
- 'ores_goodfaith_mdl' => [ 'INNER JOIN',
- [
-
'ores_goodfaith_mdl.oresm_is_current' => 1,
- 'ores_goodfaith_mdl.oresm_name'
=> 'goodfaith'
- ]
- ],
- 'ores_goodfaith_cls' => [ 'INNER JOIN',
- [
- 'ores_goodfaith_cls.oresc_model
= ores_goodfaith_mdl.oresm_id',
- 'rc_this_oldid =
ores_goodfaith_cls.oresc_rev',
-
'ores_goodfaith_cls.oresc_class' => 1
- ]
- ]
- ],
- ];
- $this->assertSame( $expected['tables'], $tables );
- $this->assertSame( $expected['fields'], $fields );
- $this->assertSame( $expected['conds'], $conds );
- $this->assertSame( $expected['join_conds'], $join_conds );
- }
-
- public function testOnEnhancedChangesListModifyLineDataGoodfaith() {
- $row = new \stdClass();
- $row->ores_goodfaith_score = 0.3;
- $row->rc_patrolled = 1;
- $row->rc_timestamp = '20150921134808';
- $row->rc_deleted = 0;
- $rc = RecentChange::newFromRow( $row );
- $rc = RCCacheEntry::newFromParent( $rc );
-
- $ecl = $this->getMockBuilder( EnhancedChangesList::class )
- ->disableOriginalConstructor()
- ->getMock();
-
- $ecl->expects( $this->any() )
- ->method( 'getUser' )
- ->will( $this->returnValue( $this->user ) );
-
- $ecl->expects( $this->any() )
- ->method( 'getContext' )
- ->will( $this->returnValue( $this->context ) );
-
- $data = [];
- $block = [];
- $classes = [];
-
- ORES\Hooks::onEnhancedChangesListModifyLineData( $ecl, $data,
$block, $rc, $classes );
-
- $this->assertSame( [ 'mw-changeslist-goodfaith-maybebad' ],
$classes );
}
public function testOnEnhancedChangesListModifyLineDataDamaging() {
@@ -418,14 +230,7 @@
$this->assertSame( [ 'recentChangesFlags' => [ 'damaging' =>
true ] ], $data );
$this->assertSame( [], $block );
- $this->assertSame(
- [
- 'damaging',
- 'mw-changeslist-damaging-likelygood',
- 'mw-changeslist-damaging-maybebad',
- ],
- $classes
- );
+ $this->assertSame( [ 'damaging' ], $classes );
}
public function testOnEnhancedChangesListModifyLineDataNonDamaging() {
@@ -458,10 +263,7 @@
$this->assertSame( [], $data );
$this->assertSame( [], $block );
- $this->assertSame(
- [ 'mw-changeslist-damaging-likelygood',
'mw-changeslist-damaging-maybebad' ],
- $classes
- );
+ $this->assertSame( [], $classes );
}
public function testOnOldChangesListModifyLineDataDamaging() {
@@ -496,14 +298,7 @@
' <abbr class="ores-damaging" title="This edit needs
review">r</abbr>',
$s
);
- $this->assertSame(
- [
- 'damaging',
- 'mw-changeslist-damaging-likelygood',
- 'mw-changeslist-damaging-maybebad',
- ],
- $classes
- );
+ $this->assertSame( [ 'damaging' ], $classes );
}
public function testOnOldChangesListModifyLineDataNonDamaging() {
@@ -534,10 +329,7 @@
ORES\Hooks::onOldChangesListRecentChangesLine( $cl, $s, $rc,
$classes );
$this->assertSame( ' <span class="mw-changeslist-separator">.
.</span> ', $s );
- $this->assertSame(
- [ 'mw-changeslist-damaging-likelygood',
'mw-changeslist-damaging-maybebad' ],
- $classes
- );
+ $this->assertSame( [], $classes );
}
public function provideOnContribsGetQueryInfo() {
--
To view, visit https://gerrit.wikimedia.org/r/341732
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I82516b0bb5be3b4f3c1a9782b87978a6f01b0c4f
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits