Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / auth / CheckBlocksSecondaryAuthenticationProvider.php
blob54ccdf4aed4bfb74ba05c1b6adf55c365013dc43
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 Config;
25 use StatusValue;
26 use User;
28 /**
29 * Check if the user is blocked, and prevent authentication if so.
31 * @ingroup Auth
32 * @since 1.27
34 class CheckBlocksSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider {
36 /** @var bool */
37 protected $blockDisablesLogin = null;
39 /**
40 * @param array $params
41 * - blockDisablesLogin: (bool) Whether blocked accounts can log in,
42 * defaults to $wgBlockDisablesLogin
44 public function __construct( $params = [] ) {
45 if ( isset( $params['blockDisablesLogin'] ) ) {
46 $this->blockDisablesLogin = (bool)$params['blockDisablesLogin'];
50 public function setConfig( Config $config ) {
51 parent::setConfig( $config );
53 if ( $this->blockDisablesLogin === null ) {
54 $this->blockDisablesLogin = $this->config->get( 'BlockDisablesLogin' );
58 public function getAuthenticationRequests( $action, array $options ) {
59 return [];
62 public function beginSecondaryAuthentication( $user, array $reqs ) {
63 if ( !$this->blockDisablesLogin ) {
64 return AuthenticationResponse::newAbstain();
65 } elseif ( $user->isBlocked() ) {
66 return AuthenticationResponse::newFail(
67 new \Message( 'login-userblocked', [ $user->getName() ] )
69 } else {
70 return AuthenticationResponse::newPass();
74 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
75 return AuthenticationResponse::newAbstain();
78 public function testUserForCreation( $user, $autocreate, array $options = [] ) {
79 $block = $user->isBlockedFromCreateAccount();
80 if ( $block ) {
81 $errorParams = [
82 $block->getTarget(),
83 $block->mReason ?: \Message::newFromKey( 'blockednoreason' )->text(),
84 $block->getByName()
87 if ( $block->getType() === \Block::TYPE_RANGE ) {
88 $errorMessage = 'cantcreateaccount-range-text';
89 $errorParams[] = $this->manager->getRequest()->getIP();
90 } else {
91 $errorMessage = 'cantcreateaccount-text';
94 return StatusValue::newFatal(
95 new \Message( $errorMessage, $errorParams )
97 } else {
98 return StatusValue::newGood();