MediaWiki REL1_37
CheckBlocksSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
25use 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}
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.StatusValueto override
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
postInitSetup()
A provider can override this to do any necessary setup after init() is called.
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:138
Generic operation result class Has warning/error list, boolean status and arbitrary value.