MediaWiki  master
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  $formatter = MediaWikiServices::getInstance()->getBlockErrorFormatter();
84 
85  $language = \RequestContext::getMain()->getUser()->isSafeToLoad() ?
86  \RequestContext::getMain()->getLanguage() :
87  MediaWikiServices::getInstance()->getContentLanguage();
88 
89  $ip = $this->manager->getRequest()->getIP();
90 
91  return StatusValue::newFatal(
92  $formatter->getMessage( $block, $user, $language, $ip )
93  );
94  } else {
95  return StatusValue::newGood();
96  }
97  }
98 
99 }
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
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:130
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\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:161
MediaWiki\Auth\AuthenticationResponse\newAbstain
static newAbstain()
Definition: AuthenticationResponse.php:170
Config
Interface for configuration instances.
Definition: Config.php:28
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:447
MediaWiki\$action
string $action
Cache what action this request is.
Definition: MediaWiki.php:42
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