Dbarratt has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391032 )

Change subject: Prevent loading or saving of zeros in the database.
......................................................................

Prevent loading or saving of zeros in the database.

When intval() fails, the function returns a zero. We should remove
the failures from the blacklist.

Bug: T178512
Change-Id: I89ad680a287da16c2fbd6aa4d53a725142429144
---
M Hooks.php
M includes/ContainmentSet.php
2 files changed, 21 insertions(+), 5 deletions(-)


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

diff --git a/Hooks.php b/Hooks.php
index cdf0255..d96140e 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -1252,7 +1252,11 @@
                }
 
                if ( isset( $options['echo-notifications-blacklist'] ) ) {
-                       $options['echo-notifications-blacklist'] = array_map( 
'intval', explode( "\n", $options['echo-notifications-blacklist'] ) );
+                       $ids = array_map( 'intval', explode( "\n", 
$options['echo-notifications-blacklist'] ) );
+                       $ids = array_filter( $ids, function ( $id ) {
+                               return $id !== 0;
+                       } );
+                       $options['echo-notifications-blacklist'] = $ids;
                }
 
                return true;
@@ -1287,8 +1291,20 @@
                                        $ids = $lookup->centralIdsFromNames( 
$names, $user );
                                }
 
-                               $user->setOption( 
'echo-notifications-blacklist', $ids );
-                               $options['echo-notifications-blacklist'] = 
implode( "\n", $user->getOption( 'echo-notifications-blacklist' ) );
+                               $ids = array_map( 'intval', $ids );
+                               // Ensure there are no empty values.
+                               $ids = array_filter( $ids, function ( $id ) {
+                                       return $id !== 0;
+                               } );
+
+                               if ( count( $ids ) > 0 ) {
+                                       $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;
+                               }
                        } else {
                                // If the blacklist is empty, set it to null 
rather than an empty string.
                                $options['echo-notifications-blacklist'] = null;
diff --git a/includes/ContainmentSet.php b/includes/ContainmentSet.php
index 0803da0..5b779d0 100644
--- a/includes/ContainmentSet.php
+++ b/includes/ContainmentSet.php
@@ -75,8 +75,8 @@
 
                if ( $preference ) {
                        $lookup = CentralIdLookup::factory();
-                       $names = $lookup->lookupCentralIds( array_flip( 
$preference ), $this->recipient );
-                       $this->addArray( array_values( $names ) );
+                       $names = $lookup->namesFromCentralIds( $preference, 
$this->recipient );
+                       $this->addArray( $names );
                }
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/391032
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I89ad680a287da16c2fbd6aa4d53a725142429144
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Dbarratt <dbarr...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to