Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / auth / CheckBlocksSecondaryAuthenticationProvider.php
blob64e6f2f56afc4a052a43920910a1a9dbfe04d6c5
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Auth
22 namespace MediaWiki\Auth;
24 use MediaWiki\MainConfigNames;
25 use MediaWiki\Message\Message;
27 /**
28 * Check if the user is blocked, and prevent authentication if so.
30 * Not all scenarios are covered by this class, AuthManager does some block checks itself
31 * via AuthManager::authorizeCreateAccount().
33 * @ingroup Auth
34 * @since 1.27
36 class CheckBlocksSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider {
38 /** @var bool */
39 protected $blockDisablesLogin = null;
41 /**
42 * @param array $params
43 * - blockDisablesLogin: (bool) Whether blocked accounts can log in,
44 * defaults to $wgBlockDisablesLogin
46 public function __construct( $params = [] ) {
47 if ( isset( $params['blockDisablesLogin'] ) ) {
48 $this->blockDisablesLogin = (bool)$params['blockDisablesLogin'];
52 /** @inheritDoc */
53 protected function postInitSetup() {
54 $this->blockDisablesLogin ??= $this->config->get( MainConfigNames::BlockDisablesLogin );
57 /** @inheritDoc */
58 public function getAuthenticationRequests( $action, array $options ) {
59 return [];
62 /** @inheritDoc */
63 public function beginSecondaryAuthentication( $user, array $reqs ) {
64 if ( !$this->blockDisablesLogin ) {
65 return AuthenticationResponse::newAbstain();
67 $block = $user->getBlock();
68 // Ignore IP blocks and partial blocks, $wgBlockDisablesLogin was meant for
69 // blocks banning specific users.
70 if ( $block && $block->isSitewide() && $block->isBlocking( $user ) ) {
71 return AuthenticationResponse::newFail(
72 new Message( 'login-userblocked', [ $user->getName() ] )
74 } else {
75 return AuthenticationResponse::newPass();
79 /** @inheritDoc */
80 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
81 return AuthenticationResponse::newAbstain();