Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / auth / TemporaryPasswordAuthenticationRequest.php
blob42f0e702235d89c710d56501b680cc54cd7123b8
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 /**
25 * This represents the intention to set a temporary password for the user.
26 * @ingroup Auth
27 * @since 1.27
29 class TemporaryPasswordAuthenticationRequest extends AuthenticationRequest {
30 /** @var string|null Temporary password */
31 public $password;
33 /** @var bool Email password to the user. */
34 public $mailpassword = false;
36 /**
37 * @var bool Do not fail certain operations if the password cannot be mailed, there is a
38 * backchannel present.
40 public $hasBackchannel = false;
42 /** @var string Username or IP address of the caller */
43 public $caller;
45 public function getFieldInfo() {
46 return [
47 'mailpassword' => [
48 'type' => 'checkbox',
49 'label' => wfMessage( 'createaccountmail' ),
50 'help' => wfMessage( 'createaccountmail-help' ),
55 /**
56 * @param string|null $password
58 public function __construct( $password = null ) {
59 $this->password = $password;
60 if ( $password ) {
61 $this->mailpassword = true;
65 /**
66 * Return an instance with a new, random password
67 * @return TemporaryPasswordAuthenticationRequest
69 public static function newRandom() {
70 $config = \ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
72 // get the min password length
73 $minLength = $config->get( 'MinimalPasswordLength' );
74 $policy = $config->get( 'PasswordPolicy' );
75 foreach ( $policy['policies'] as $p ) {
76 if ( isset( $p['MinimalPasswordLength'] ) ) {
77 $minLength = max( $minLength, $p['MinimalPasswordLength'] );
79 if ( isset( $p['MinimalPasswordLengthToLogin'] ) ) {
80 $minLength = max( $minLength, $p['MinimalPasswordLengthToLogin'] );
84 $password = \PasswordFactory::generateRandomPasswordString( $minLength );
86 return new self( $password );
89 /**
90 * Return an instance with an invalid password
91 * @return TemporaryPasswordAuthenticationRequest
93 public static function newInvalid() {
94 $request = new self( null );
95 return $request;
98 public function describeCredentials() {
99 return [
100 'provider' => wfMessage( 'authmanager-provider-temporarypassword' ),
101 'account' => new \RawMessage( '$1', [ $this->username ] ),
102 ] + parent::describeCredentials();