Gergő Tisza has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/351135 )

Change subject: Do not disable password reset for blocks meant to force login
......................................................................

Do not disable password reset for blocks meant to force login

Bug: T161860
Change-Id: Ic7e7e9b4ff7fe94001578a895962ef732b690384
---
M includes/user/PasswordReset.php
1 file changed, 31 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/35/351135/1

diff --git a/includes/user/PasswordReset.php b/includes/user/PasswordReset.php
index 4ee256c..44e45a1 100644
--- a/includes/user/PasswordReset.php
+++ b/includes/user/PasswordReset.php
@@ -100,7 +100,7 @@
                        } elseif ( !$user->isAllowed( 'editmyprivateinfo' ) ) {
                                // Maybe not all users have permission to 
change private data
                                $status = StatusValue::newFatal( 'badaccess' );
-                       } elseif ( $user->isBlocked() ) {
+                       } elseif ( $this->isBlocked( $user ) ) {
                                // Maybe the user is blocked (check this here 
rather than relying on the parent
                                // method as we have a more specific error 
message to use here
                                $status = StatusValue::newFatal( 
'blocked-mailpassword' );
@@ -251,6 +251,36 @@
        }
 
        /**
+        * Check whether the user is blocked.
+        * Ignores certain types of system blocks that are only meant to force 
users to log in.
+        * @param User $user
+        * @return bool
+        */
+       protected function isBlocked( User $user ) {
+               $block = $user->getBlock();
+               if ( !$block ) {
+                       return false;
+               }
+               $type = $block->getSystemBlockType();
+               if ( in_array( $type, [ null, 'global-block' ], true ) ) {
+                       // Normal block. Maybe it was meant for someone else 
and the user just needs to log in;
+                       // or maybe it was issued specifically to prevent some 
IP from messing with password
+                       // reset? Go out on a limb and use the registration 
allowed flag to decide.
+                       return $block->prevents( 'createaccount' );
+               } elseif ( $type === 'proxy-block' ) {
+                       // we disallow actions through proxy even if the user 
is logged in
+                       // so it makes sense to disallow password resets as well
+                       return true;
+               } elseif ( in_array( $type, [ 'dnsbl', 'wgSoftBlockRanges' ], 
true ) ) {
+                       // these are just meant to force login so let's not 
prevent that
+                       return false;
+               } else {
+                       // some extension - we'll have to guess
+                       return true;
+               }
+       }
+
+       /**
         * @param string $email
         * @return User[]
         * @throws MWException On unexpected database errors

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic7e7e9b4ff7fe94001578a895962ef732b690384
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: GergÅ‘ Tisza <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to