MediaWiki  master
CheckBlocksSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Auth;
23 
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  protected function postInitSetup() {
51  if ( $this->blockDisablesLogin === null ) {
52  $this->blockDisablesLogin = $this->config->get( MainConfigNames::BlockDisablesLogin );
53  }
54  }
55 
56  public function getAuthenticationRequests( $action, array $options ) {
57  return [];
58  }
59 
60  public function beginSecondaryAuthentication( $user, array $reqs ) {
61  // @TODO Partial blocks should not prevent the user from logging in.
62  // see: https://phabricator.wikimedia.org/T208895
63  if ( !$this->blockDisablesLogin ) {
65  } elseif ( $user->getBlock() ) {
67  new \Message( 'login-userblocked', [ $user->getName() ] )
68  );
69  } else {
71  }
72  }
73 
74  public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
76  }
77 
78  public function testUserForCreation( $user, $autocreate, array $options = [] ) {
79  $block = $user->isBlockedFromCreateAccount();
80  if ( $block ) {
81  $formatter = MediaWikiServices::getInstance()->getBlockErrorFormatter();
82 
83  $language = \RequestContext::getMain()->getUser()->isSafeToLoad() ?
84  \RequestContext::getMain()->getLanguage() :
85  MediaWikiServices::getInstance()->getContentLanguage();
86 
87  $ip = $this->manager->getRequest()->getIP();
88 
89  return StatusValue::newFatal(
90  $formatter->getMessage( $block, $user, $language, $ip )
91  );
92  } else {
93  return StatusValue::newGood();
94  }
95  }
96 
97 }
A base class that implements some of the boilerplate for a SecondaryAuthenticationProvider.
static newFail(Message $msg, array $failReasons=[])
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.User being created (not added to the database yet)....
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
beginSecondaryAuthentication( $user, array $reqs)
Start an authentication flow.
postInitSetup()
A provider can override this to do any necessary setup after init() is called.
A class containing constants representing the names of configuration variables.
const BlockDisablesLogin
Name constant for the BlockDisablesLogin setting, for use with Config::get()
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
string null $action
Cache what action this request is.
Definition: MediaWiki.php:47
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:141
static getMain()
Get the RequestContext object associated with the main request.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:70
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82