| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Auth; |
| 23 |
|
| 24 |
use MediaWiki\MainConfigNames; |
| 25 |
use MediaWiki\MediaWikiServices; |
| 26 |
use MediaWiki\Parser\Sanitizer; |
| 27 |
use MediaWiki\User\User; |
| 28 |
use StatusValue; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
class UserDataAuthenticationRequest extends AuthenticationRequest { |
| 38 |
|
| 39 |
public $email; |
| 40 |
|
| 41 |
|
| 42 |
public $realname; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 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, |
| 56 |
], |
| 57 |
'realname' => [ |
| 58 |
'type' => 'string', |
| 59 |
'label' => wfMessage( 'authmanager-realname-label' ), |
| 60 |
'help' => wfMessage( 'authmanager-realname-help' ), |
| 61 |
'optional' => true, |
| 62 |
], |
| 63 |
]; |
| 64 |
|
| 65 |
if ( !$config->get( MainConfigNames::EnableEmail ) ) { |
| 66 |
unset( $ret['email'] ); |
| 67 |
} |
| 68 |
|
| 69 |
if ( in_array( 'realname', $config->get( MainConfigNames::HiddenPrefs ), true ) ) { |
| 70 |
unset( $ret['realname'] ); |
| 71 |
} |
| 72 |
|
| 73 |
return $ret; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public function populateUser( $user ) { |
| 85 |
if ( $this->email !== null && $this->email !== '' ) { |
| 86 |
if ( !Sanitizer::validateEmail( $this->email ) ) { |
| 87 |
return StatusValue::newFatal( 'invalidemailaddress' ); |
| 88 |
} |
| 89 |
$user->setEmail( $this->email ); |
| 90 |
} |
| 91 |
if ( $this->realname !== null && $this->realname !== '' ) { |
| 92 |
$user->setRealName( $this->realname ); |
| 93 |
} |
| 94 |
return StatusValue::newGood(); |
| 95 |
} |
| 96 |
|
| 97 |
} |