MediaWiki  master
CheckBlocksSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Auth;
23 
25 use StatusValue;
26 
34 
36  protected $blockDisablesLogin = null;
37 
43  public function __construct( $params = [] ) {
44  if ( isset( $params['blockDisablesLogin'] ) ) {
45  $this->blockDisablesLogin = (bool)$params['blockDisablesLogin'];
46  }
47  }
48 
49  protected function postInitSetup() {
50  if ( $this->blockDisablesLogin === null ) {
51  $this->blockDisablesLogin = $this->config->get( 'BlockDisablesLogin' );
52  }
53  }
54 
55  public function getAuthenticationRequests( $action, array $options ) {
56  return [];
57  }
58 
59  public function beginSecondaryAuthentication( $user, array $reqs ) {
60  // @TODO Partial blocks should not prevent the user from logging in.
61  // see: https://phabricator.wikimedia.org/T208895
62  if ( !$this->blockDisablesLogin ) {
64  } elseif ( $user->getBlock() ) {
66  new \Message( 'login-userblocked', [ $user->getName() ] )
67  );
68  } else {
70  }
71  }
72 
73  public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
75  }
76 
77  public function testUserForCreation( $user, $autocreate, array $options = [] ) {
78  $block = $user->isBlockedFromCreateAccount();
79  if ( $block ) {
80  $formatter = MediaWikiServices::getInstance()->getBlockErrorFormatter();
81 
82  $language = \RequestContext::getMain()->getUser()->isSafeToLoad() ?
83  \RequestContext::getMain()->getLanguage() :
84  MediaWikiServices::getInstance()->getContentLanguage();
85 
86  $ip = $this->manager->getRequest()->getIP();
87 
88  return StatusValue::newFatal(
89  $formatter->getMessage( $block, $user, $language, $ip )
90  );
91  } else {
92  return StatusValue::newGood();
93  }
94  }
95 
96 }
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\testUserForCreation
testUserForCreation( $user, $autocreate, array $options=[])
Determine whether an account may be created.User being created (not added to the database yet)....
Definition: CheckBlocksSecondaryAuthenticationProvider.php:77
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider
Check if the user is blocked, and prevent authentication if so.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:33
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:70
MediaWiki\Auth\AbstractSecondaryAuthenticationProvider
A base class that implements some of the boilerplate for a SecondaryAuthenticationProvider.
Definition: AbstractSecondaryAuthenticationProvider.php:33
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:200
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\$blockDisablesLogin
bool $blockDisablesLogin
Definition: CheckBlocksSecondaryAuthenticationProvider.php:36
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\__construct
__construct( $params=[])
Definition: CheckBlocksSecondaryAuthenticationProvider.php:43
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:261
MediaWiki\Auth\AuthenticationResponse\newAbstain
static newAbstain()
Definition: AuthenticationResponse.php:170
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:484
MediaWiki\$action
string $action
Cache what action this request is.
Definition: MediaWiki.php:45
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:73
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:138
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\postInitSetup
postInitSetup()
A provider can override this to do any necessary setup after init() is called.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:49
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\beginSecondaryAuthentication
beginSecondaryAuthentication( $user, array $reqs)
Start an authentication flow.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:59
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationResponse\newPass
static newPass( $username=null)
Definition: AuthenticationResponse.php:134
MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProvider\getAuthenticationRequests
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
Definition: CheckBlocksSecondaryAuthenticationProvider.php:55