Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / auth / UserDataAuthenticationRequest.php
blob2b70490af3756a6beb86774311e0369388d7082c
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\MediaWikiServices;
26 use MediaWiki\Parser\Sanitizer;
27 use MediaWiki\User\User;
28 use StatusValue;
30 /**
31 * This represents additional user data requested on the account creation form
33 * @stable to extend
34 * @ingroup Auth
35 * @since 1.27
37 class UserDataAuthenticationRequest extends AuthenticationRequest {
38 /** @var string|null Email address */
39 public $email;
41 /** @var string|null Real name */
42 public $realname;
44 /**
45 * @inheritDoc
46 * @stable to override
48 public function getFieldInfo() {
49 $config = MediaWikiServices::getInstance()->getMainConfig();
50 $ret = [
51 'email' => [
52 'type' => 'string',
53 'label' => wfMessage( 'authmanager-email-label' ),
54 'help' => wfMessage( 'authmanager-email-help' ),
55 'optional' => true,
57 'realname' => [
58 'type' => 'string',
59 'label' => wfMessage( 'authmanager-realname-label' ),
60 'help' => wfMessage( 'authmanager-realname-help' ),
61 'optional' => true,
65 if ( !$config->get( MainConfigNames::EnableEmail ) ) {
66 unset( $ret['email'] );
69 if ( in_array( 'realname', $config->get( MainConfigNames::HiddenPrefs ), true ) ) {
70 unset( $ret['realname'] );
73 return $ret;
76 /**
77 * Add data to the User object
78 * @stable to override
79 * @param User $user User being created (not added to the database yet).
80 * This may become a "UserValue" in the future, or User may be refactored
81 * into such.
82 * @return StatusValue
84 public function populateUser( $user ) {
85 if ( $this->email !== null && $this->email !== '' ) {
86 if ( !Sanitizer::validateEmail( $this->email ) ) {
87 return StatusValue::newFatal( 'invalidemailaddress' );
89 $user->setEmail( $this->email );
91 if ( $this->realname !== null && $this->realname !== '' ) {
92 $user->setRealName( $this->realname );
94 return StatusValue::newGood();