MediaWiki  master
UserDataAuthenticationRequest.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Auth;
23 
25 use StatusValue;
26 use User;
27 
37  public $email;
38 
40  public $realname;
41 
46  public function getFieldInfo() {
47  $config = MediaWikiServices::getInstance()->getMainConfig();
48  $ret = [
49  'email' => [
50  'type' => 'string',
51  'label' => wfMessage( 'authmanager-email-label' ),
52  'help' => wfMessage( 'authmanager-email-help' ),
53  'optional' => true,
54  ],
55  'realname' => [
56  'type' => 'string',
57  'label' => wfMessage( 'authmanager-realname-label' ),
58  'help' => wfMessage( 'authmanager-realname-help' ),
59  'optional' => true,
60  ],
61  ];
62 
63  if ( !$config->get( 'EnableEmail' ) ) {
64  unset( $ret['email'] );
65  }
66 
67  if ( in_array( 'realname', $config->get( 'HiddenPrefs' ), true ) ) {
68  unset( $ret['realname'] );
69  }
70 
71  return $ret;
72  }
73 
82  public function populateUser( $user ) {
83  if ( $this->email !== null && $this->email !== '' ) {
84  if ( !\Sanitizer::validateEmail( $this->email ) ) {
85  return StatusValue::newFatal( 'invalidemailaddress' );
86  }
87  $user->setEmail( $this->email );
88  }
89  if ( $this->realname !== null && $this->realname !== '' ) {
90  $user->setRealName( $this->realname );
91  }
92  return StatusValue::newGood();
93  }
94 
95 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\Auth\UserDataAuthenticationRequest\$email
string null $email
Email address.
Definition: UserDataAuthenticationRequest.php:37
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:70
MediaWiki\Auth\UserDataAuthenticationRequest\$realname
string null $realname
Real name.
Definition: UserDataAuthenticationRequest.php:40
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:155
MediaWiki\Auth\UserDataAuthenticationRequest\getFieldInfo
getFieldInfo()
Fetch input field info.The field info is an associative array mapping field names to info arrays....
Definition: UserDataAuthenticationRequest.php:46
Sanitizer\validateEmail
static validateEmail( $addr)
Does a string look like an e-mail address?
Definition: Sanitizer.php:1941
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1219
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:186
Config\get
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
MediaWiki\Auth\UserDataAuthenticationRequest
This represents additional user data requested on the account creation form.
Definition: UserDataAuthenticationRequest.php:35
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\Auth\UserDataAuthenticationRequest\populateUser
populateUser( $user)
Add data to the User object Stable to override.
Definition: UserDataAuthenticationRequest.php:82
MediaWiki\$config
Config $config
Definition: MediaWiki.php:42
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:55
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:38