[MediaWiki-commits] [Gerrit] mediawiki...Echo[wmf/1.31.0-wmf.2]: Use User Ids instead of User Names for Echo Mute

2017-10-05 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/382508 )

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
(cherry picked from commit 3ba76f7faa97e47453895b3c002398c1288b6e89)
---
M Hooks.php
M extension.json
M includes/ContainmentSet.php
A maintenance/updatePerUserBlacklist.php
4 files changed, 131 insertions(+), 5 deletions(-)

Approvals:
  Thcipriani: 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 );
+   

[MediaWiki-commits] [Gerrit] mediawiki...Echo[wmf/1.31.0-wmf.2]: Use User Ids instead of User Names for Echo Mute

2017-10-05 Thread Thcipriani (Code Review)
Thcipriani has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/382508 )

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
(cherry picked from commit 3ba76f7faa97e47453895b3c002398c1288b6e89)
---
M Hooks.php
M extension.json
M includes/ContainmentSet.php
A maintenance/updatePerUserBlacklist.php
4 files changed, 131 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/08/382508/1

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 );
+