MediaWiki  1.34.0
CheckBlocksSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Auth;
23 
24 use Config;
26 use 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 }
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\testUserForCreation
testUserForCreation( $user, $autocreate, array $options=[])
Determine whether an account may be created.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:80
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider
Check if the user is blocked, and prevent authentication if so.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:34
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:42
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:69
MediaWiki\Auth\AbstractSecondaryAuthenticationProvider
A base class that implements some of the boilerplate for a SecondaryAuthenticationProvider.
Definition: AbstractSecondaryAuthenticationProvider.php:30
getUser
getUser()
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\$blockDisablesLogin
bool $blockDisablesLogin
Definition: CheckBlocksSecondaryAuthenticationProvider.php:37
Message
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\__construct
__construct( $params=[])
Definition: CheckBlocksSecondaryAuthenticationProvider.php:44
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\setConfig
setConfig(Config $config)
Set configuration.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:50
MediaWiki\Auth\AuthenticationResponse\newAbstain
static newAbstain()
Definition: AuthenticationResponse.php:170
MediaWiki\Block\AbstractBlock\TYPE_RANGE
const TYPE_RANGE
Definition: AbstractBlock.php:86
Config
Interface for configuration instances.
Definition: Config.php:28
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:54
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:431
MediaWiki\$action
string $action
Cache what action this request is.
Definition: MediaWiki.php:48
MediaWiki\Auth\AuthenticationResponse\newFail
static newFail(Message $msg)
Definition: AuthenticationResponse.php:146
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\beginSecondaryAccountCreation
beginSecondaryAccountCreation( $user, $creator, array $reqs)
Start an account creation flow.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:76
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\beginSecondaryAuthentication
beginSecondaryAuthentication( $user, array $reqs)
Start an authentication flow.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:62
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationResponse\newPass
static newPass( $username=null)
Definition: AuthenticationResponse.php:134
MediaWiki\Auth\AbstractAuthenticationProvider\$config
Config $config
Definition: AbstractAuthenticationProvider.php:38
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\getAuthenticationRequests
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:58