Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/254167
Change subject: Make Wikibase watchlist filter in client work with new checkboxes ...................................................................... Make Wikibase watchlist filter in client work with new checkboxes The way that core generally handles this is to check if action=submit is in the request, and if so then don't set the default to whatever the user preference is. We need to add a similar check in the hook handler. RecentChanges doesn't (yet) have the checkboxes and doesn't have action=submit when submitting the form, so will just keep doing what was done before there. If/when the checkboxes get introduced there, then our code will already be compatible. Also added tests and refactored the tests some to make them more clear. Bug: T118459 Change-Id: Ife7a52f3bea0a4a28ed7cc4bc6433709f8beb41b (cherry picked from commit a672a5cd8ab68df74d419d8f63a2e2e738f410d7) --- M client/includes/Hooks/ChangesListSpecialPageFilterHandler.php M client/tests/phpunit/includes/Hooks/ChangesListSpecialPageFilterHandlerTest.php 2 files changed, 76 insertions(+), 22 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/67/254167/1 diff --git a/client/includes/Hooks/ChangesListSpecialPageFilterHandler.php b/client/includes/Hooks/ChangesListSpecialPageFilterHandler.php index 0b0ecad..04bbc18 100644 --- a/client/includes/Hooks/ChangesListSpecialPageFilterHandler.php +++ b/client/includes/Hooks/ChangesListSpecialPageFilterHandler.php @@ -96,10 +96,12 @@ */ public function addFilterIfEnabled( array &$filters ) { if ( $this->shouldAddFilter() ) { - // if preference enabled, then Wikibase edits are included by default and - // the toggle default value needs to be the inverse to hide them, and vice versa. - $toggleDefault = !$this->hasShowWikibaseEditsPrefEnabled(); - $this->addFilter( $filters, $toggleDefault ); + $filterName = $this->getFilterName(); + + $filters[$filterName] = array( + 'msg' => 'wikibase-rc-hide-wikidata', + 'default' => $this->getToggleDefault() + ); } } @@ -111,16 +113,16 @@ } /** - * @param array &$filters - * @param bool $toggleDefault + * @return bool */ - private function addFilter( array &$filters, $toggleDefault ) { - $filterName = $this->getFilterName(); + private function getToggleDefault() { + if ( $this->request->getVal( 'action' ) === 'submit' ) { + return $this->request->getBool( $this->getFilterName() ); + } - $filters[$filterName] = array( - 'msg' => 'wikibase-rc-hide-wikidata', - 'default' => $toggleDefault - ); + // if preference enabled, then Wikibase edits are included by default and + // the toggle default value needs to be the inverse to hide them, and vice versa. + return !$this->hasShowWikibaseEditsPrefEnabled(); } /** diff --git a/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageFilterHandlerTest.php b/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageFilterHandlerTest.php index eb18101..a5e9f2c 100644 --- a/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageFilterHandlerTest.php +++ b/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageFilterHandlerTest.php @@ -78,12 +78,13 @@ } /** - * @dataProvider filterAddedWhenNotUsingEnhancedChangesProvider + * @dataProvider filter_withoutShowWikibaseEditsByDefaultPreference */ - public function testFilterAddedWhenNotUsingEnhancedChanges_notShowWikibaseEditsByDefault( + public function testFilter_withoutShowWikibaseEditsByDefaultPreference( array $requestParams, array $userPreferences, $expectedFilterName, + $expectedToggleDefault, $specialPageName ) { $hookHandler = new ChangesListSpecialPageFilterHandler( @@ -99,46 +100,72 @@ $expected = array( $expectedFilterName => array( 'msg' => 'wikibase-rc-hide-wikidata', - 'default' => true + 'default' => $expectedToggleDefault ) ); $this->assertSame( $expected, $filters ); } - public function filterAddedWhenNotUsingEnhancedChangesProvider() { + public function filter_withoutShowWikibaseEditsByDefaultPreference() { return array( array( array(), array( 'usenewrc' => 0 ), 'hideWikibase', + true, 'Watchlist' ), array( array( 'enhanced' => 0 ), array( 'usenewrc' => 1 ), 'hidewikidata', + true, 'RecentChanges' ), array( array(), array( 'usenewrc' => 0 ), 'hidewikidata', + true, 'RecentChangesLinked' + ), + array( + array( 'action' => 'submit', 'hideWikibase' => 0 ), + array( 'usenewrc' => 0 ), + 'hideWikibase', + false, + 'Watchlist' + ), + array( + array( 'action' => 'submit', 'hideWikibase' => 1 ), + array( 'usenewrc' => 0 ), + 'hideWikibase', + true, + 'Watchlist' + ), + array( + array( 'action' => 'submit' ), + array( 'usenewrc' => 0 ), + 'hideWikibase', + false, + 'Watchlist' ) ); } /** - * @dataProvider filterAddedInNonEnhanced_withPrefToShowWikibaseEditsByDefaultProvider + * @dataProvider filter_withShowWikibaseEditsByDefaultPreference */ - public function testFilterAddedInNonEnhanced_withPrefToShowWikibaseEditsByDefault( + public function testFilter_withShowWikibaseEditsByDefaultPreference( + array $requestParams, array $userPreferences, $expectedFilterName, + $expectedToggleDefault, $specialPageName ) { $hookHandler = new ChangesListSpecialPageFilterHandler( - $this->getRequest( array() ), + $this->getRequest( $requestParams ), $this->getUser( $userPreferences ), $specialPageName, true @@ -150,24 +177,49 @@ $expected = array( $expectedFilterName => array( 'msg' => 'wikibase-rc-hide-wikidata', - 'default' => false + 'default' => $expectedToggleDefault ) ); $this->assertSame( $expected, $filters ); } - public function filterAddedInNonEnhanced_withPrefToShowWikibaseEditsByDefaultProvider() { + public function filter_withShowWikibaseEditsByDefaultPreference() { return array( array( + array(), array( 'wlshowwikibase' => 1, 'usenewrc' => 0 ), 'hideWikibase', + false, 'Watchlist' ), array( + array( 'enhanced' => 0 ), + array( 'rcshowwikidata' => 1, 'usenewrc' => 1 ), + 'hidewikidata', + false, + 'RecentChanges' + ), + array( + array(), array( 'rcshowwikidata' => 1, 'usenewrc' => 0 ), 'hidewikidata', - 'RecentChanges' + false, + 'RecentChangesLinked' + ), + array( + array( 'action' => 'submit', 'hideWikibase' => 0 ), + array( 'wlshowwikibase' => 1, 'usenewrc' => 0 ), + 'hideWikibase', + false, + 'Watchlist' + ), + array( + array( 'action' => 'submit' ), + array( 'wlshowwikibase' => 1, 'usenewrc' => 0 ), + 'hideWikibase', + false, + 'Watchlist' ) ); } -- To view, visit https://gerrit.wikimedia.org/r/254167 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ife7a52f3bea0a4a28ed7cc4bc6433709f8beb41b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: wmf/1.27.0-wmf.7 Gerrit-Owner: Aude <aude.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits