MediaWiki REL1_35
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 $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}
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.StatusValue Stable to override Stable to override
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:161
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Interface for configuration instances.
Definition Config.php:30