MediaWiki REL1_34
CheckBlocksSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
24use Config;
26use StatusValue;
27
35
37 protected $blockDisablesLogin = null;
38
44 public function __construct( $params = [] ) {
45 if ( isset( $params['blockDisablesLogin'] ) ) {
46 $this->blockDisablesLogin = (bool)$params['blockDisablesLogin'];
47 }
48 }
49
50 public function setConfig( Config $config ) {
51 parent::setConfig( $config );
52
53 if ( $this->blockDisablesLogin === null ) {
54 $this->blockDisablesLogin = $this->config->get( 'BlockDisablesLogin' );
55 }
56 }
57
58 public function getAuthenticationRequests( $action, array $options ) {
59 return [];
60 }
61
62 public function beginSecondaryAuthentication( $user, array $reqs ) {
63 // @TODO Partial blocks should not prevent the user from logging in.
64 // see: https://phabricator.wikimedia.org/T208895
65 if ( !$this->blockDisablesLogin ) {
67 } elseif ( $user->getBlock() ) {
69 new \Message( 'login-userblocked', [ $user->getName() ] )
70 );
71 } else {
73 }
74 }
75
76 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
78 }
79
80 public function testUserForCreation( $user, $autocreate, array $options = [] ) {
81 $block = $user->isBlockedFromCreateAccount();
82 if ( $block ) {
83 if ( $block->getReason() ) {
84 $reason = $block->getReason();
85 } else {
86 $msg = \Message::newFromKey( 'blockednoreason' );
87 if ( !\RequestContext::getMain()->getUser()->isSafeToLoad() ) {
88 $msg->inContentLanguage();
89 }
90 $reason = $msg->text();
91 }
92
93 $errorParams = [
94 $block->getTarget(),
95 $reason,
96 $block->getByName()
97 ];
98
99 if ( $block->getType() === DatabaseBlock::TYPE_RANGE ) {
100 $errorMessage = 'cantcreateaccount-range-text';
101 $errorParams[] = $this->manager->getRequest()->getIP();
102 } else {
103 $errorMessage = 'cantcreateaccount-text';
104 }
105
106 return StatusValue::newFatal(
107 new \Message( $errorMessage, $errorParams )
108 );
109 } else {
110 return StatusValue::newGood();
111 }
112 }
113
114}
getUser()
A base class that implements some of the boilerplate for a SecondaryAuthenticationProvider.
Check if the user is blocked, and prevent authentication if so.
beginSecondaryAccountCreation( $user, $creator, array $reqs)
Start an account creation flow.
testUserForCreation( $user, $autocreate, array $options=[])
Determine whether an account may be created.
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
The Message class provides methods which fulfil two basic services:
Definition Message.php:162
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Interface for configuration instances.
Definition Config.php:28