}
private static function normalizeCondition( $conds ) {
+ $dbr = wfGetDB( DB_REPLICA );
$normalized = array_map(
- function ( $k, $v ) {
- return is_numeric( $k ) ? $v : "$k = $v";
+ function ( $k, $v ) use ( $dbr ) {
+ if ( is_array( $v ) ) {
+ sort( $v );
+ }
+ // (Ab)use makeList() to format only this entry
+ return $dbr->makeList( [ $k => $v ], Database::LIST_AND );
},
array_keys( $conds ),
$conds
return $normalized;
}
- /** return false if condition begin with 'rc_timestamp ' */
+ /** return false if condition begins with 'rc_timestamp ' */
private static function filterOutRcTimestampCondition( $var ) {
- return ( false === strpos( $var, 'rc_timestamp ' ) );
+ return ( is_array( $var ) || false === strpos( $var, 'rc_timestamp ' ) );
}
public function testRcNsFilter() {
}
public function testRcHidemyselfFilter() {
+ $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_WRITE_BOTH );
+ $this->overrideMwServices();
+
$user = $this->getTestUser()->getUser();
+ $user->getActorId( wfGetDB( DB_MASTER ) );
$this->assertConditions(
[ # expected
- "rc_user_text != '{$user->getName()}'",
+ "NOT((rc_actor = '{$user->getActorId()}') OR "
+ . "(rc_actor = '0' AND rc_user = '{$user->getId()}'))",
],
[
'hidemyself' => 1,
);
$user = User::newFromName( '10.11.12.13', false );
+ $id = $user->getActorId( wfGetDB( DB_MASTER ) );
$this->assertConditions(
[ # expected
- "rc_user_text != '10.11.12.13'",
+ "NOT((rc_actor = '$id') OR (rc_actor = '0' AND rc_user_text = '10.11.12.13'))",
],
[
'hidemyself' => 1,
}
public function testRcHidebyothersFilter() {
+ $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_WRITE_BOTH );
+ $this->overrideMwServices();
+
$user = $this->getTestUser()->getUser();
+ $user->getActorId( wfGetDB( DB_MASTER ) );
$this->assertConditions(
[ # expected
- "rc_user_text = '{$user->getName()}'",
+ "(rc_actor = '{$user->getActorId()}') OR "
+ . "(rc_actor = '0' AND rc_user_text = '{$user->getName()}')",
],
[
'hidebyothers' => 1,
);
$user = User::newFromName( '10.11.12.13', false );
+ $id = $user->getActorId( wfGetDB( DB_MASTER ) );
$this->assertConditions(
[ # expected
- "rc_user_text = '10.11.12.13'",
+ "(rc_actor = '$id') OR (rc_actor = '0' AND rc_user_text = '10.11.12.13')",
],
[
'hidebyothers' => 1,
$user = $this->getTestSysop()->getUser();
$this->assertConditions(
[ # expected
- "rc_patrolled = 0",
+ 'rc_patrolled' => 0,
],
[
'hidepatrolled' => 1,
$user = $this->getTestSysop()->getUser();
$this->assertConditions(
[ # expected
- "rc_patrolled = 1",
+ 'rc_patrolled' => [ 1, 2 ],
],
[
'hideunpatrolled' => 1,
);
}
+ public function testRcReviewStatusFilter() {
+ $user = $this->getTestSysop()->getUser();
+ $this->assertConditions(
+ [ #expected
+ 'rc_patrolled' => 1,
+ ],
+ [
+ 'reviewStatus' => 'manual'
+ ],
+ "rc conditions: reviewStatus=manual",
+ $user
+ );
+ $this->assertConditions(
+ [ #expected
+ 'rc_patrolled' => [ 0, 2 ],
+ ],
+ [
+ 'reviewStatus' => 'unpatrolled;auto'
+ ],
+ "rc conditions: reviewStatus=unpatrolled;auto",
+ $user
+ );
+ }
+
public function testRcHideminorFilter() {
$this->assertConditions(
[ # expected
}
public function testFilterUserExpLevelAllExperienceLevels() {
+ $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_WRITE_BOTH );
+ $this->overrideMwServices();
+
$this->assertConditions(
[
# expected
- 'rc_user != 0',
+ 'COALESCE( actor_rc_user.actor_user, rc_user ) != 0',
],
[
'userExpLevel' => 'newcomer;learner;experienced',
}
public function testFilterUserExpLevelRegistrered() {
+ $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_WRITE_BOTH );
+ $this->overrideMwServices();
+
$this->assertConditions(
[
# expected
- 'rc_user != 0',
+ 'COALESCE( actor_rc_user.actor_user, rc_user ) != 0',
],
[
'userExpLevel' => 'registered',
}
public function testFilterUserExpLevelUnregistrered() {
+ $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_WRITE_BOTH );
+ $this->overrideMwServices();
+
$this->assertConditions(
[
# expected
- 'rc_user' => 0,
+ 'COALESCE( actor_rc_user.actor_user, rc_user ) = 0',
],
[
'userExpLevel' => 'unregistered',
}
public function testFilterUserExpLevelRegistreredOrLearner() {
+ $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_WRITE_BOTH );
+ $this->overrideMwServices();
+
$this->assertConditions(
[
# expected
- 'rc_user != 0',
+ 'COALESCE( actor_rc_user.actor_user, rc_user ) != 0',
],
[
'userExpLevel' => 'registered;learner',
}
public function testFilterUserExpLevelUnregistreredOrExperienced() {
+ $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_WRITE_BOTH );
+ $this->overrideMwServices();
+
$conds = $this->buildQuery( [ 'userExpLevel' => 'unregistered;experienced' ] );
$this->assertRegExp(
- '/\(rc_user = 0\) OR \(\(user_editcount >= 500\) AND \(user_registration <= \'[^\']+\'\)\)/',
+ '/\(COALESCE\( actor_rc_user.actor_user, rc_user \) = 0\) OR '
+ . '\(\(user_editcount >= 500\) AND \(user_registration <= \'[^\']+\'\)\)/',
reset( $conds ),
"rc conditions: userExpLevel=unregistered;experienced"
);
]
);
+ // @todo: This is not at all safe or sane. It just blindly assumes
+ // nothing in $conds depends on any other tables.
$result = wfGetDB( DB_MASTER )->select(
- $tables,
+ 'user',
'user_name',
array_filter( $conds ) + [ 'user_email' => 'ut' ]
);