Show better error for anons on Special:EmailUser
authorEddie Greiner-Petter <git@eddie-sh.de>
Mon, 13 Mar 2017 17:33:35 +0000 (18:33 +0100)
committerEddieGP <wikimedia.org@eddie-sh.de>
Thu, 16 Mar 2017 13:22:51 +0000 (13:22 +0000)
When a anon user visits Special:EmailUser, the PermissionError message
is shown (as only members of the group "user" (all logged in users) are
allowed to do this). There is a better error message, which tells "You
must be logged in and have a valid email adress in your preferences."
available, but was only shown to users who are logged in but did not
have a valid mail adress in their settings, because the check for the
permission "emailuser" happened before the check for the valid mail
(which returns false for anon users). Exchanging the order of those
makes the right error message appear.

Bug: T160309
Change-Id: I26175df1f7577937d9781950058ca458984ce2cb

includes/specials/SpecialEmailuser.php

index 085b68d..a69406c 100644 (file)
@@ -231,14 +231,15 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        return 'usermaildisabled';
                }
 
-               if ( !$user->isAllowed( 'sendemail' ) ) {
-                       return 'badaccess';
-               }
-
+               // Run this before $user->isAllowed, to show appropriate message to anons (T160309)
                if ( !$user->isEmailConfirmed() ) {
                        return 'mailnologin';
                }
 
+               if ( !$user->isAllowed( 'sendemail' ) ) {
+                       return 'badaccess';
+               }
+
                if ( $user->isBlockedFromEmailuser() ) {
                        wfDebug( "User is blocked from sending e-mail.\n" );