}
}
- $opts->add( 'namespace', '', FormOptions::INTNULL );
+ $opts->add( 'namespace', '', FormOptions::STRING );
$opts->add( 'invert', false );
$opts->add( 'associated', false );
}
// Namespace filtering
- if ( $opts['namespace'] !== '' ) {
- $selectedNS = $dbr->addQuotes( $opts['namespace'] );
- $operator = $opts['invert'] ? '!=' : '=';
- $boolean = $opts['invert'] ? 'AND' : 'OR';
-
- // Namespace association (T4429)
- if ( !$opts['associated'] ) {
- $condition = "rc_namespace $operator $selectedNS";
- } else {
- // Also add the associated namespace
- $associatedNS = $dbr->addQuotes(
- MWNamespace::getAssociated( $opts['namespace'] )
+ if ( $opts[ 'namespace' ] !== '' ) {
+ $namespaces = explode( ',', $opts[ 'namespace' ] );
+
+ if ( $opts[ 'associated' ] ) {
+ $associatedNamespaces = array_map(
+ function ( $ns ) {
+ return MWNamespace::getAssociated( $ns );
+ },
+ $namespaces
);
- $condition = "(rc_namespace $operator $selectedNS "
- . $boolean
- . " rc_namespace $operator $associatedNS)";
+ $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
}
- $conds[] = $condition;
+ if ( count( $namespaces ) === 1 ) {
+ $operator = $opts[ 'invert' ] ? '!=' : '=';
+ $value = $dbr->addQuotes( reset( $namespaces ) );
+ } else {
+ $operator = $opts[ 'invert' ] ? 'NOT IN' : 'IN';
+ sort( $namespaces );
+ $value = '(' . $dbr->makeList( $namespaces ) . ')';
+ }
+ $conds[] = "rc_namespace $operator $value";
}
}
[
'namespace' => NS_MAIN,
],
- "rc conditions with no options (aka default setting)"
+ "rc conditions with one namespace"
);
}
);
}
- /**
- * T4429
- * @dataProvider provideNamespacesAssociations
- */
- public function testRcNsFilterAssociation( $ns1, $ns2 ) {
+ public function testRcNsFilterMultiple() {
$this->assertConditions(
[ # expected
- "(rc_namespace = '$ns1' OR rc_namespace = '$ns2')",
+ "rc_namespace IN ('1','2','3')",
],
[
- 'namespace' => $ns1,
+ 'namespace' => '1,2,3',
+ ],
+ "rc conditions with multiple namespaces"
+ );
+ }
+
+ public function testRcNsFilterMultipleAssociated() {
+ $this->assertConditions(
+ [ # expected
+ "rc_namespace IN ('0','1','4','5','6','7')",
+ ],
+ [
+ 'namespace' => '1,4,7',
'associated' => 1,
],
- "rc conditions with namespace inverted"
+ "rc conditions with multiple namespaces and associated"
);
}
- /**
- * T4429
- * @dataProvider provideNamespacesAssociations
- */
- public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
+ public function testRcNsFilterMultipleAssociatedInvert() {
$this->assertConditions(
[ # expected
- "(rc_namespace != '$ns1' AND rc_namespace != '$ns2')",
+ "rc_namespace NOT IN ('2','3','8','9')",
],
[
- 'namespace' => $ns1,
+ 'namespace' => '2,3,9',
'associated' => 1,
- 'invert' => 1,
+ 'invert' => 1
],
- "rc conditions with namespace inverted"
+ "rc conditions with multiple namespaces, associated and inverted"
);
}
- /**
- * Provides associated namespaces to test recent changes
- * namespaces association filtering.
- */
- public static function provideNamespacesAssociations() {
- return [ # (NS => Associated_NS)
- [ NS_MAIN, NS_TALK ],
- [ NS_TALK, NS_MAIN ],
- ];
+ public function testRcNsFilterMultipleInvert() {
+ $this->assertConditions(
+ [ # expected
+ "rc_namespace NOT IN ('1','2','3')",
+ ],
+ [
+ 'namespace' => '1,2,3',
+ 'invert' => 1,
+ ],
+ "rc conditions with multiple namespaces inverted"
+ );
}
public function testRcHidemyselfFilter() {