r83110 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83109‎ | r83110 | r83111 >
Date:20:40, 2 March 2011
Author:hashar
Status:resolved (Comments)
Tags:
Comment:
Bug 2429 allow selection of associated namespace in recent changes

Done by adding yet another checkbox in Special:RecentChanges. The feature
also support namespace inversion. For example, if you have selected
the TALK namespace with inversion and associated namespace, you will
be shown any changes which is not NS_MAIN or NS_TALK.

Tests:

SpecialRecentchanges tests only this feature. I had to filter out
the rc_timestamp condition which might cause trouble if the test
suite is run on another day. A better solution remains to be implemented.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRecentchanges.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/specials (added) (history)
  • /trunk/phase3/tests/phpunit/includes/specials/SpecialRecentchanges.php (added) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1989,6 +1989,7 @@
19901990 'nsform' => array(
19911991 'namespace',
19921992 'invert',
 1993+ 'namespace_association',
19931994 'blanknamespace',
19941995 ),
19951996 '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
1136 + native
Index: trunk/phase3/includes/specials/SpecialRecentchanges.php
@@ -55,6 +55,7 @@
5656
5757 $opts->add( 'namespace', '', FormOptions::INTNULL );
5858 $opts->add( 'invert', false );
 59+ $opts->add( 'associated', false );
5960
6061 $opts->add( 'categories', '' );
6162 $opts->add( 'categories_any', false );
@@ -284,13 +285,26 @@
285286
286287 # Namespace filtering
287288 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";
290296 } 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)";
292304 }
 305+
 306+ $conds[] = $condition;
293307 }
294 -
 308+wfVarDump( $conds );
295309 return $conds;
296310 }
297311
@@ -463,7 +477,7 @@
464478
465479 $defaults = $opts->getAllValues();
466480 $nondefaults = $opts->getChangedValues();
467 - $opts->consumeValues( array( 'namespace', 'invert', 'tagfilter',
 481+ $opts->consumeValues( array( 'namespace', 'invert', 'associated', 'tagfilter',
468482 'categories', 'categories_any' ) );
469483
470484 $panel = array();
@@ -555,6 +569,7 @@
556570 /**
557571 * Creates the choose namespace selection
558572 *
 573+ * @todo Uses radio buttons (HASHAR)
559574 * @param $opts FormOptions
560575 * @return String
561576 */
@@ -562,7 +577,8 @@
563578 $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
564579 $nsLabel = Xml::label( wfMsg('namespace'), 'namespace' );
565580 $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" );
567583 }
568584
569585 /**
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2964,6 +2964,7 @@
29652965 # Namespace form on various pages
29662966 'namespace' => 'Namespace:',
29672967 'invert' => 'Invert selection',
 2968+'namespace_association' => 'Associated namespace',
29682969 'blanknamespace' => '(Main)',
29692970
29702971 # Contributions
Index: trunk/phase3/RELEASE-NOTES
@@ -81,6 +81,7 @@
8282 safely enabled. A ZIP file reader was added which can scan a ZIP file for
8383 potentially dangerous Java applets. This allows applets to be blocked
8484 specifically, rather than all ZIP files being blocked.
 85+* (bug 2429) Allow selection of associated namespace in recent changes
8586
8687 === Bug fixes in 1.18 ===
8788 * (bug 23119) WikiError class and subclasses are now marked as deprecated

Follow-up revisions

RevisionCommit summaryAuthorDate
r83111remove wfVarDump() statement...hashar20:41, 2 March 2011
r87998bug 2429 fix up index by using IN / NOT IN instead of (!= and !=)...hashar15:56, 13 May 2011
r90670Add tooltips to the Special:Recentchanges checkboxes...hashar20:00, 23 June 2011

Comments

#Comment by Hashar (talk | contribs)   20:42, 2 March 2011

I guess the perfect commit is not for today (see r83111) :-(

#Comment by Bawolff (talk | contribs)   19:41, 6 March 2011

I find the default text of the namespace_association message to be confusing. 'Include associated talk namespace' might be better if a bit long. Associated Namespace by itself is unclear imo.

Also don't we normally use dashes not underscores in message names?

#Comment by Hashar (talk | contribs)   07:30, 8 March 2011

I tried to keep it at a short length, and since english is probably not my best skill: feel free to alter the message to get a better wording.

#Comment by Aaron Schulz (talk | contribs)   05:40, 22 June 2011

Please add a title attribute to this checkbox (and the invert one while you're at it). UX is too confusing here.

#Comment by Hashar (talk | contribs)   20:00, 23 June 2011

r90670 adds tooltip to the SpecialRecentchanges checkboxes (fixme -> new)

Status & tagging log