CheckBlocksSecondaryAuthenticationProvider: Avoid user language during auto-creation
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 5 Oct 2017 18:50:44 +0000 (14:50 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 5 Oct 2017 18:50:44 +0000 (14:50 -0400)
If a user being auto-created is blocked from account creation without a
reason given, CheckBlocksPrimaryAuthProvider is triggering a
"User::loadFromSession called before the end of Setup.php" log message
when trying to fill in a reason using 'blockednoreason'.

In this situation, use the content language instead.

Bug: T124367
Change-Id: Id94c919cdba5e4218b709ba8ac9d0fa17f0c3f8e

includes/auth/CheckBlocksSecondaryAuthenticationProvider.php

index f7a7ec1..7488fba 100644 (file)
@@ -77,9 +77,19 @@ class CheckBlocksSecondaryAuthenticationProvider extends AbstractSecondaryAuthen
        public function testUserForCreation( $user, $autocreate, array $options = [] ) {
                $block = $user->isBlockedFromCreateAccount();
                if ( $block ) {
+                       if ( $block->mReason ) {
+                               $reason = $block->mReason;
+                       } else {
+                               $msg = \Message::newFromKey( 'blockednoreason' );
+                               if ( !\RequestContext::getMain()->getUser()->isSafeToLoad() ) {
+                                       $msg->inContentLanguage();
+                               }
+                               $reason = $msg->text();
+                       }
+
                        $errorParams = [
                                $block->getTarget(),
-                               $block->mReason ?: \Message::newFromKey( 'blockednoreason' )->text(),
+                               $reason,
                                $block->getByName()
                        ];