[MediaWiki-commits] [Gerrit] mediawiki...Echo[master]: Use User Ids instead of User Names for Echo Mute
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/374871 ) Change subject: Use User Ids instead of User Names for Echo Mute .. Use User Ids instead of User Names for Echo Mute The echo mute list uses user names which are not stable. User ids should be used instead. Bug: T173475 Change-Id: I947bcf37a8f85aaa105776d368dbd0ab76823aeb --- M Hooks.php M extension.json M includes/ContainmentSet.php A maintenance/updatePerUserBlacklist.php 4 files changed, 131 insertions(+), 5 deletions(-) Approvals: Dmaza: Looks good to me, but someone else must approve EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/Hooks.php b/Hooks.php index 8e3db35..4a7c06a 100644 --- a/Hooks.php +++ b/Hooks.php @@ -490,10 +490,15 @@ } if ( $wgEchoPerUserBlacklist ) { + $lookup = CentralIdLookup::factory(); + $ids = $user->getOption( 'echo-notifications-blacklist', [] ); + $names = $ids ? $lookup->namesFromCentralIds( $ids, $user ) : []; + $preferences['echo-notifications-blacklist'] = [ 'type' => 'usersmultiselect', 'label-message' => 'echo-pref-notifications-blacklist', 'section' => 'echo/blocknotificationslist', + 'default' => implode( "\n", $names ) ]; } @@ -1252,6 +1257,10 @@ $options['echo-subscriptions-email-edit-user-talk'] = $options['enotifusertalkpages']; } + if ( isset( $options['echo-notifications-blacklist'] ) ) { + $options['echo-notifications-blacklist'] = array_map( 'intval', explode( "\n", $options['echo-notifications-blacklist'] ) ); + } + return true; } @@ -1270,6 +1279,28 @@ unset( $options['echo-subscriptions-email-edit-user-talk'] ); } + // Convert usernames to ids. + if ( isset( $options['echo-notifications-blacklist'] ) ) { + if ( $options['echo-notifications-blacklist'] ) { + $value = $options['echo-notifications-blacklist']; + // Notification Blacklist may be an array of ids or a string of new line + // delimnated user names. + if ( is_array( $value ) ) { + $ids = array_filter( $value, 'is_numeric' ); + } else { + $lookup = CentralIdLookup::factory(); + $names = explode( "\n", $value ); + $ids = $lookup->centralIdsFromNames( $names, $user ); + } + + $user->setOption( 'echo-notifications-blacklist', $ids ); + $options['echo-notifications-blacklist'] = implode( "\n", $user->getOption( 'echo-notifications-blacklist' ) ); + } else { + // If the blacklist is empty, set it to null rather than an empty string. + $options['echo-notifications-blacklist'] = null; + } + } + return true; } diff --git a/extension.json b/extension.json index 39606db..dc21551 100644 --- a/extension.json +++ b/extension.json @@ -1019,6 +1019,7 @@ "SpecialNotificationsMarkRead": "includes/special/SpecialNotificationsMarkRead.php", "SuppressionMaintenanceTest": "tests/phpunit/maintenance/SupressionMaintenanceTest.php", "TestDiscussionParser": "maintenance/testDiscussionParser.php", - "UpdateEchoSchemaForSuppression": "maintenance/updateEchoSchemaForSuppression.php" + "UpdateEchoSchemaForSuppression": "maintenance/updateEchoSchemaForSuppression.php", + "EchoUpdatePerUserBlacklist": "maintenance/updatePerUserBlacklist.php" } } diff --git a/includes/ContainmentSet.php b/includes/ContainmentSet.php index 4b6ce1f..d5cfff5 100644 --- a/includes/ContainmentSet.php +++ b/includes/ContainmentSet.php @@ -71,12 +71,12 @@ * @param string $preferenceName */ public function addFromUserOption( $preferenceName ) { - $preference = $this->recipient->getOption( $preferenceName ); + $preference = $this->recipient->getOption( $preferenceName, [] ); if ( $preference ) { - $items = explode( "\n", $preference ); - - $this->addArray( $items ); + $lookup =
[MediaWiki-commits] [Gerrit] mediawiki...Echo[master]: Use User Ids instead of User Names for Echo Mute
Dbarratt has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374871 ) Change subject: Use User Ids instead of User Names for Echo Mute .. Use User Ids instead of User Names for Echo Mute The echo mute list uses user names which are not stable. User ids should be used instead. Bug: T173475 Change-Id: I947bcf37a8f85aaa105776d368dbd0ab76823aeb --- M Hooks.php M extension.json M includes/ContainmentSet.php A maintenance/updatePerUserBlacklist.php 4 files changed, 134 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/71/374871/1 diff --git a/Hooks.php b/Hooks.php index 8e3db35..8c310b0 100644 --- a/Hooks.php +++ b/Hooks.php @@ -490,10 +490,14 @@ } if ( $wgEchoPerUserBlacklist ) { + $lookup = CentralIdLookup::factory(); + $ids = $user->getOption( 'echo-notifications-blacklist', [] ); + $names = $ids ? $lookup->lookupCentralIds( array_flip( $ids ), $user ) : []; $preferences['echo-notifications-blacklist'] = [ 'type' => 'usersmultiselect', 'label-message' => 'echo-pref-notifications-blacklist', 'section' => 'echo/blocknotificationslist', + 'default' => implode( "\n", array_values( $names ) ) ]; } @@ -1252,6 +1256,10 @@ $options['echo-subscriptions-email-edit-user-talk'] = $options['enotifusertalkpages']; } + if ( isset( $options['echo-notifications-blacklist'] ) ) { + $options['echo-notifications-blacklist'] = array_map( 'intval', explode( "\n", $options['echo-notifications-blacklist'] ) ); + } + return true; } @@ -1270,6 +1278,31 @@ unset( $options['echo-subscriptions-email-edit-user-talk'] ); } + // Convert usernames to ids. + if ( isset( $options['echo-notifications-blacklist'] ) ) { + if ( $options['echo-notifications-blacklist'] ) { + $value = $options['echo-notifications-blacklist']; + // Notification Blacklist may be an array of ids or a string of new line + // delimnated user names. + if ( is_array( $value ) ) { + $ids = array_filter( $value, 'is_numeric' ); + } else { + $lookup = CentralIdLookup::factory(); + $names = explode( "\n", $value ); + $nameToId = array_flip( $names ); + $nameToId = array_fill_keys( array_keys( $nameToId ), false ); + $ids = array_filter( $lookup->lookupUserNames( $nameToId, $this ), function ( $id ) { + return $id !== false; + } ); + } + $user->setOption( 'echo-notifications-blacklist', array_unique( array_values( $ids ) ) ); + $options['echo-notifications-blacklist'] = implode( "\n", $user->getOption( 'echo-notifications-blacklist' ) ); + } else { + // If the blacklist is empty, set it to null rather than an empty string. + $options['echo-notifications-blacklist'] = null; + } + } + return true; } diff --git a/extension.json b/extension.json index 39606db..2ae045f 100644 --- a/extension.json +++ b/extension.json @@ -1019,6 +1019,7 @@ "SpecialNotificationsMarkRead": "includes/special/SpecialNotificationsMarkRead.php", "SuppressionMaintenanceTest": "tests/phpunit/maintenance/SupressionMaintenanceTest.php", "TestDiscussionParser": "maintenance/testDiscussionParser.php", - "UpdateEchoSchemaForSuppression": "maintenance/updateEchoSchemaForSuppression.php" + "UpdateEchoSchemaForSuppression": "maintenance/updateEchoSchemaForSuppression.php", + "EchoUpdatePerUserBlocklist": "maintenance/updatePerUserBlocklist.php" } } diff --git a/includes/ContainmentSet.php b/includes/ContainmentSet.php index 4b6ce1f..d5cfff5 100644 --- a/includes/ContainmentSet.php +++ b/includes/ContainmentSet.php @@ -71,12 +71,12 @@ * @param string $preferenceName */ public function addFromUserOption( $preferenceName ) { -