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