Index: trunk/phase3/maintenance/language/messages.inc |
— | — | @@ -1989,6 +1989,7 @@ |
1990 | 1990 | 'nsform' => array( |
1991 | 1991 | 'namespace', |
1992 | 1992 | 'invert', |
| 1993 | + 'namespace_association', |
1993 | 1994 | 'blanknamespace', |
1994 | 1995 | ), |
1995 | 1996 | 'contributions' => array( |
Index: trunk/phase3/tests/phpunit/includes/specials/SpecialRecentchanges.php |
— | — | @@ -0,0 +1,134 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Test class for SpecialRecentchanges class |
| 5 | + * |
| 6 | + * Copyright © 2011, Ashar Voultoiz |
| 7 | + * |
| 8 | + * @author Ashar Voultoiz |
| 9 | + */ |
| 10 | +class SpecialRecentchangesTest extends MediaWikiTestCase { |
| 11 | + |
| 12 | + /** |
| 13 | + * @var SpecialRecentChanges |
| 14 | + */ |
| 15 | + protected $rc; |
| 16 | + |
| 17 | + function setUp() { |
| 18 | + } |
| 19 | + |
| 20 | + /** helper to test SpecialRecentchanges::buildMainQueryConds() */ |
| 21 | + private function assertConditions( $expected, $requestOptions = null, $message = '' ) { |
| 22 | + global $wgRequest; |
| 23 | + $savedGlobal = $wgRequest; |
| 24 | + |
| 25 | + # Initialize a WebRequest object ... |
| 26 | + $wgRequest = new FauxRequest( $requestOptions ); |
| 27 | + # ... then setup the rc object (which use wgRequest internally) |
| 28 | + $this->rc = new SpecialRecentChanges(); |
| 29 | + $formOptions = $this->rc->setup( null ); |
| 30 | + |
| 31 | + # Filter out rc_timestamp conditions which depends on the test runtime |
| 32 | + # This condition is not needed as of march 2, 2011 -- hashar |
| 33 | + # FIXME: find a way to generate the correct rc_timestamp |
| 34 | + $queryConditions = array_filter( |
| 35 | + $this->rc->buildMainQueryConds( $formOptions ), |
| 36 | + 'SpecialRecentchangesTest::filterOutRcTimestampCondition' |
| 37 | + ); |
| 38 | + |
| 39 | + $this->assertEquals( |
| 40 | + $expected, |
| 41 | + $queryConditions, |
| 42 | + $message |
| 43 | + ); |
| 44 | + |
| 45 | + $wgRequest = $savedGlobal; |
| 46 | + } |
| 47 | + |
| 48 | + /** return false if condition begin with 'rc_timestamp ' */ |
| 49 | + private static function filterOutRcTimestampCondition( $var ) { |
| 50 | + return (false === strpos( $var, 'rc_timestamp ' )); |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + public function testRcNsFilter() { |
| 55 | + $this->assertConditions( |
| 56 | + array( # expected |
| 57 | + 'rc_bot' => 0, |
| 58 | + #0 => "rc_timestamp >= '20110223000000'", |
| 59 | + 1 => "rc_namespace = '0'", |
| 60 | + ), |
| 61 | + array( |
| 62 | + 'namespace' => NS_MAIN, |
| 63 | + ), |
| 64 | + "rc conditions with no options (aka default setting)" |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + public function testRcNsFilterInversion() { |
| 69 | + $this->assertConditions( |
| 70 | + array( # expected |
| 71 | + #0 => "rc_timestamp >= '20110223000000'", |
| 72 | + 'rc_bot' => 0, |
| 73 | + 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ), |
| 74 | + ), |
| 75 | + array( |
| 76 | + 'namespace' => NS_MAIN, |
| 77 | + 'invert' => 1, |
| 78 | + ), |
| 79 | + "rc conditions with namespace inverted" |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @bug 2429 |
| 85 | + * @dataProvider provideNamespacesAssociations |
| 86 | + */ |
| 87 | + public function testRcNsFilterAssociation( $ns1, $ns2 ) { |
| 88 | + $this->assertConditions( |
| 89 | + array( # expected |
| 90 | + #0 => "rc_timestamp >= '20110223000000'", |
| 91 | + 'rc_bot' => 0, |
| 92 | + 1 => sprintf( "(rc_namespace = '%s' OR rc_namespace = '%s')", $ns1, $ns2 ), |
| 93 | + ), |
| 94 | + array( |
| 95 | + 'namespace' => $ns1, |
| 96 | + 'associated' => 1, |
| 97 | + ), |
| 98 | + "rc conditions with namespace inverted" |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * @bug 2429 |
| 104 | + * @dataProvider provideNamespacesAssociations |
| 105 | + */ |
| 106 | + public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) { |
| 107 | + $this->assertConditions( |
| 108 | + array( # expected |
| 109 | + #0 => "rc_timestamp >= '20110223000000'", |
| 110 | + 'rc_bot' => 0, |
| 111 | + 1 => sprintf( "(rc_namespace != '%s' AND rc_namespace != '%s')", $ns1, $ns2 ), |
| 112 | + ), |
| 113 | + array( |
| 114 | + 'namespace' => $ns1, |
| 115 | + 'associated' => 1, |
| 116 | + 'invert' => 1, |
| 117 | + ), |
| 118 | + "rc conditions with namespace inverted" |
| 119 | + ); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Provides associated namespaces to test recent changes |
| 124 | + * namespaces association filtering. |
| 125 | + */ |
| 126 | + public function provideNamespacesAssociations() { |
| 127 | + return array( # (NS => Associated_NS) |
| 128 | + array( NS_MAIN, NS_TALK), |
| 129 | + array( NS_TALK, NS_MAIN), |
| 130 | + ); |
| 131 | + } |
| 132 | + |
| 133 | +} |
| 134 | + |
| 135 | + |
Property changes on: trunk/phase3/tests/phpunit/includes/specials/SpecialRecentchanges.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 136 | + native |
Index: trunk/phase3/includes/specials/SpecialRecentchanges.php |
— | — | @@ -55,6 +55,7 @@ |
56 | 56 | |
57 | 57 | $opts->add( 'namespace', '', FormOptions::INTNULL ); |
58 | 58 | $opts->add( 'invert', false ); |
| 59 | + $opts->add( 'associated', false ); |
59 | 60 | |
60 | 61 | $opts->add( 'categories', '' ); |
61 | 62 | $opts->add( 'categories_any', false ); |
— | — | @@ -284,13 +285,26 @@ |
285 | 286 | |
286 | 287 | # Namespace filtering |
287 | 288 | if( $opts['namespace'] !== '' ) { |
288 | | - if( !$opts['invert'] ) { |
289 | | - $conds[] = 'rc_namespace = ' . $dbr->addQuotes( $opts['namespace'] ); |
| 289 | + $selectedNS = $dbr->addQuotes( $opts['namespace'] ); |
| 290 | + $operator = $opts['invert'] ? '!=' : '='; |
| 291 | + $boolean = $opts['invert'] ? 'AND' : 'OR'; |
| 292 | + |
| 293 | + # namespace association (bug 2429) |
| 294 | + if( !$opts['associated'] ) { |
| 295 | + $condition = "rc_namespace $operator $selectedNS"; |
290 | 296 | } else { |
291 | | - $conds[] = 'rc_namespace != ' . $dbr->addQuotes( $opts['namespace'] ); |
| 297 | + # Also add the associated namespace |
| 298 | + $associatedNS = $dbr->addQuotes( |
| 299 | + MWNamespace::getAssociated( $opts['namespace'] ) |
| 300 | + ); |
| 301 | + $condition = "(rc_namespace $operator $selectedNS " |
| 302 | + . $boolean |
| 303 | + . " rc_namespace $operator $associatedNS)"; |
292 | 304 | } |
| 305 | + |
| 306 | + $conds[] = $condition; |
293 | 307 | } |
294 | | - |
| 308 | +wfVarDump( $conds ); |
295 | 309 | return $conds; |
296 | 310 | } |
297 | 311 | |
— | — | @@ -463,7 +477,7 @@ |
464 | 478 | |
465 | 479 | $defaults = $opts->getAllValues(); |
466 | 480 | $nondefaults = $opts->getChangedValues(); |
467 | | - $opts->consumeValues( array( 'namespace', 'invert', 'tagfilter', |
| 481 | + $opts->consumeValues( array( 'namespace', 'invert', 'associated', 'tagfilter', |
468 | 482 | 'categories', 'categories_any' ) ); |
469 | 483 | |
470 | 484 | $panel = array(); |
— | — | @@ -555,6 +569,7 @@ |
556 | 570 | /** |
557 | 571 | * Creates the choose namespace selection |
558 | 572 | * |
| 573 | + * @todo Uses radio buttons (HASHAR) |
559 | 574 | * @param $opts FormOptions |
560 | 575 | * @return String |
561 | 576 | */ |
— | — | @@ -562,7 +577,8 @@ |
563 | 578 | $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' ); |
564 | 579 | $nsLabel = Xml::label( wfMsg('namespace'), 'namespace' ); |
565 | 580 | $invert = Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $opts['invert'] ); |
566 | | - return array( $nsLabel, "$nsSelect $invert" ); |
| 581 | + $associated = Xml::checkLabel( wfMsg('namespace_association'), 'associated', 'nsassociated', $opts['associated'] ); |
| 582 | + return array( $nsLabel, "$nsSelect $invert $associated" ); |
567 | 583 | } |
568 | 584 | |
569 | 585 | /** |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -2964,6 +2964,7 @@ |
2965 | 2965 | # Namespace form on various pages |
2966 | 2966 | 'namespace' => 'Namespace:', |
2967 | 2967 | 'invert' => 'Invert selection', |
| 2968 | +'namespace_association' => 'Associated namespace', |
2968 | 2969 | 'blanknamespace' => '(Main)', |
2969 | 2970 | |
2970 | 2971 | # Contributions |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -81,6 +81,7 @@ |
82 | 82 | safely enabled. A ZIP file reader was added which can scan a ZIP file for |
83 | 83 | potentially dangerous Java applets. This allows applets to be blocked |
84 | 84 | specifically, rather than all ZIP files being blocked. |
| 85 | +* (bug 2429) Allow selection of associated namespace in recent changes |
85 | 86 | |
86 | 87 | === Bug fixes in 1.18 === |
87 | 88 | * (bug 23119) WikiError class and subclasses are now marked as deprecated |