[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[wmf/1.30.0-wmf.1]: Fix default notification preference
Aude has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/356629 ) Change subject: Fix default notification preference .. Fix default notification preference Making it default preference was wrong because default preferences are fallback for missing preferences, whereas it was missing for all users when the feature was deployed. Bug: T166657 Change-Id: I5a475b35c5b8392f799b4ff8f64de684b9833544 --- M client/WikibaseClient.hooks.php M client/includes/Hooks/EchoNotificationsHandlers.php M client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php 3 files changed, 62 insertions(+), 10 deletions(-) Approvals: Aude: Verified; Looks good to me, approved diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php index 646bbc0..850a46e 100644 --- a/client/WikibaseClient.hooks.php +++ b/client/WikibaseClient.hooks.php @@ -458,7 +458,7 @@ // These hooks should only be run if we use the Echo extension if ( class_exists( EchoEvent::class ) ) { - $wgHooks['UserGetDefaultOptions'][] = EchoNotificationsHandlers::class . '::onUserGetDefaultOptions'; + $wgHooks['LocalUserCreated'][] = EchoNotificationsHandlers::class . '::onLocalUserCreated'; $wgHooks['WikibaseHandleChange'][] = EchoNotificationsHandlers::class . '::onWikibaseHandleChange'; } diff --git a/client/includes/Hooks/EchoNotificationsHandlers.php b/client/includes/Hooks/EchoNotificationsHandlers.php index 35842dc..3c0ff36 100644 --- a/client/includes/Hooks/EchoNotificationsHandlers.php +++ b/client/includes/Hooks/EchoNotificationsHandlers.php @@ -165,22 +165,24 @@ } /** -* Handler for UserGetDefaultOptions hook -* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserGetDefaultOptions -* -* @param bool[] &$defaultOptions Array of preference keys and their default values. +* Handler for LocalUserCreated hook. +* @see https://www.mediawiki.org/wiki/Manual:Hooks/LocalUserCreated +* @param User $user User object that was created. +* @param bool $autocreated True when account was auto-created */ - public static function onUserGetDefaultOptions( array &$defaultOptions ) { + public static function onLocalUserCreated( User $user, $autocreated ) { $self = self::newFromGlobalState(); - $self->doUserGetDefaultOptions( $defaultOptions ); + $self->doLocalUserCreated( $user, $autocreated ); } /** -* @param bool[] &$defaultOptions +* @param User $user +* @param bool $autocreated */ - public function doUserGetDefaultOptions( array &$defaultOptions ) { + public function doLocalUserCreated( User $user, $autocreated ) { if ( $this->sendEchoNotification === true ) { - $defaultOptions['echo-subscriptions-web-wikibase-action'] = true; + $user->setOption( 'echo-subscriptions-web-wikibase-action', true ); + $user->saveSettings(); } } diff --git a/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php b/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php index c120e44..c32418a 100644 --- a/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php +++ b/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php @@ -5,6 +5,7 @@ use EchoEvent; use MediaWikiTestCase; use Title; +use User; use Wikibase\ChangeRow; use Wikibase\Client\Hooks\EchoNotificationsHandlers; use Wikibase\Client\RepoLinker; @@ -219,4 +220,53 @@ } } + public function localUserCreatedProvider() { + return [ + 'disabled no auto' => [ + 'enabled' => false, + 'times' => 0, + 'auto' => false, + ], + 'disabled auto' => [ + 'enabled' => false, + 'times' => 0, + 'auto' => true, + ], + 'enabled no auto' => [ + 'enabled' => true, + 'times' => 1, + 'auto' => false, + ], + 'enabled auto' => [ + 'enabled' => true, + 'times' => 1, + 'auto' => true, + ] + ]; + } + + /** +* @dataProvider localUserCreatedProvider +*/ + public function testLocalUserCreated( $enabled, $times, $auto ) { +
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[wmf/1.30.0-wmf.1]: Fix default notification preference
Thiemo Mättig (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/356629 ) Change subject: Fix default notification preference .. Fix default notification preference Making it default preference was wrong because default preferences are fallback for missing preferences, whereas it was missing for all users when the feature was deployed. Bug: T166657 Change-Id: I5a475b35c5b8392f799b4ff8f64de684b9833544 --- M client/WikibaseClient.hooks.php M client/includes/Hooks/EchoNotificationsHandlers.php M client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php 3 files changed, 62 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/29/356629/1 diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php index 646bbc0..850a46e 100644 --- a/client/WikibaseClient.hooks.php +++ b/client/WikibaseClient.hooks.php @@ -458,7 +458,7 @@ // These hooks should only be run if we use the Echo extension if ( class_exists( EchoEvent::class ) ) { - $wgHooks['UserGetDefaultOptions'][] = EchoNotificationsHandlers::class . '::onUserGetDefaultOptions'; + $wgHooks['LocalUserCreated'][] = EchoNotificationsHandlers::class . '::onLocalUserCreated'; $wgHooks['WikibaseHandleChange'][] = EchoNotificationsHandlers::class . '::onWikibaseHandleChange'; } diff --git a/client/includes/Hooks/EchoNotificationsHandlers.php b/client/includes/Hooks/EchoNotificationsHandlers.php index 35842dc..3c0ff36 100644 --- a/client/includes/Hooks/EchoNotificationsHandlers.php +++ b/client/includes/Hooks/EchoNotificationsHandlers.php @@ -165,22 +165,24 @@ } /** -* Handler for UserGetDefaultOptions hook -* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserGetDefaultOptions -* -* @param bool[] &$defaultOptions Array of preference keys and their default values. +* Handler for LocalUserCreated hook. +* @see https://www.mediawiki.org/wiki/Manual:Hooks/LocalUserCreated +* @param User $user User object that was created. +* @param bool $autocreated True when account was auto-created */ - public static function onUserGetDefaultOptions( array &$defaultOptions ) { + public static function onLocalUserCreated( User $user, $autocreated ) { $self = self::newFromGlobalState(); - $self->doUserGetDefaultOptions( $defaultOptions ); + $self->doLocalUserCreated( $user, $autocreated ); } /** -* @param bool[] &$defaultOptions +* @param User $user +* @param bool $autocreated */ - public function doUserGetDefaultOptions( array &$defaultOptions ) { + public function doLocalUserCreated( User $user, $autocreated ) { if ( $this->sendEchoNotification === true ) { - $defaultOptions['echo-subscriptions-web-wikibase-action'] = true; + $user->setOption( 'echo-subscriptions-web-wikibase-action', true ); + $user->saveSettings(); } } diff --git a/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php b/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php index c120e44..c32418a 100644 --- a/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php +++ b/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php @@ -5,6 +5,7 @@ use EchoEvent; use MediaWikiTestCase; use Title; +use User; use Wikibase\ChangeRow; use Wikibase\Client\Hooks\EchoNotificationsHandlers; use Wikibase\Client\RepoLinker; @@ -219,4 +220,53 @@ } } + public function localUserCreatedProvider() { + return [ + 'disabled no auto' => [ + 'enabled' => false, + 'times' => 0, + 'auto' => false, + ], + 'disabled auto' => [ + 'enabled' => false, + 'times' => 0, + 'auto' => true, + ], + 'enabled no auto' => [ + 'enabled' => true, + 'times' => 1, + 'auto' => false, + ], + 'enabled auto' => [ + 'enabled' => true, + 'times' => 1, + 'auto' => true, + ] + ]; + } + + /** +* @dataProvider localUserCreatedProvider +*/ + public function