Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| ConfirmLinkAuthenticationRequest | |
100.00% |
27 / 27 |
|
100.00% |
4 / 4 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getFieldInfo | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
2 | |||
| getUniqueId | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| __set_state | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Auth; |
| 8 | |
| 9 | use InvalidArgumentException; |
| 10 | |
| 11 | /** |
| 12 | * @stable to extend |
| 13 | * @ingroup Auth |
| 14 | */ |
| 15 | class ConfirmLinkAuthenticationRequest extends AuthenticationRequest { |
| 16 | /** @var AuthenticationRequest[] */ |
| 17 | protected $linkRequests; |
| 18 | |
| 19 | /** @var string[] List of unique IDs of the confirmed accounts. */ |
| 20 | public $confirmedLinkIDs = []; |
| 21 | |
| 22 | /** |
| 23 | * @stable to call |
| 24 | * @param AuthenticationRequest[] $linkRequests A list of autolink requests |
| 25 | * which need to be confirmed. |
| 26 | */ |
| 27 | public function __construct( array $linkRequests ) { |
| 28 | if ( !$linkRequests ) { |
| 29 | throw new InvalidArgumentException( '$linkRequests must not be empty' ); |
| 30 | } |
| 31 | $this->linkRequests = $linkRequests; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @inheritDoc |
| 36 | * @stable to override |
| 37 | */ |
| 38 | public function getFieldInfo() { |
| 39 | $options = []; |
| 40 | foreach ( $this->linkRequests as $req ) { |
| 41 | $description = $req->describeCredentials(); |
| 42 | $options[$req->getUniqueId()] = wfMessage( |
| 43 | 'authprovider-confirmlink-option', |
| 44 | $description['provider']->text(), $description['account']->text() |
| 45 | ); |
| 46 | } |
| 47 | return [ |
| 48 | 'confirmedLinkIDs' => [ |
| 49 | 'type' => 'multiselect', |
| 50 | 'options' => $options, |
| 51 | 'label' => wfMessage( 'authprovider-confirmlink-request-label' ), |
| 52 | 'help' => wfMessage( 'authprovider-confirmlink-request-help' ), |
| 53 | 'optional' => true, |
| 54 | ] |
| 55 | ]; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @inheritDoc |
| 60 | * @stable to override |
| 61 | */ |
| 62 | public function getUniqueId() { |
| 63 | $ids = []; |
| 64 | foreach ( $this->linkRequests as $req ) { |
| 65 | $ids[] = $req->getUniqueId(); |
| 66 | } |
| 67 | return parent::getUniqueId() . ':' . implode( '|', $ids ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Implementing this mainly for use from the unit tests. |
| 72 | * @param array $data |
| 73 | * @return AuthenticationRequest |
| 74 | */ |
| 75 | public static function __set_state( $data ) { |
| 76 | $ret = new static( $data['linkRequests'] ); |
| 77 | foreach ( $data as $k => $v ) { |
| 78 | $ret->$k = $v; |
| 79 | } |
| 80 | return $ret; |
| 81 | } |
| 82 | } |