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 | * 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. |
7 | * |
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. |
12 | * |
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 |
17 | * |
18 | * @file |
19 | * @ingroup Auth |
20 | */ |
21 | |
22 | namespace MediaWiki\Auth; |
23 | |
24 | /** |
25 | * @stable to extend |
26 | */ |
27 | class ConfirmLinkAuthenticationRequest extends AuthenticationRequest { |
28 | /** @var AuthenticationRequest[] */ |
29 | protected $linkRequests; |
30 | |
31 | /** @var string[] List of unique IDs of the confirmed accounts. */ |
32 | public $confirmedLinkIDs = []; |
33 | |
34 | /** |
35 | * @stable to call |
36 | * @param AuthenticationRequest[] $linkRequests A list of autolink requests |
37 | * which need to be confirmed. |
38 | */ |
39 | public function __construct( array $linkRequests ) { |
40 | if ( !$linkRequests ) { |
41 | throw new \InvalidArgumentException( '$linkRequests must not be empty' ); |
42 | } |
43 | $this->linkRequests = $linkRequests; |
44 | } |
45 | |
46 | /** |
47 | * @inheritDoc |
48 | * @stable to override |
49 | */ |
50 | public function getFieldInfo() { |
51 | $options = []; |
52 | foreach ( $this->linkRequests as $req ) { |
53 | $description = $req->describeCredentials(); |
54 | $options[$req->getUniqueId()] = wfMessage( |
55 | 'authprovider-confirmlink-option', |
56 | $description['provider']->text(), $description['account']->text() |
57 | ); |
58 | } |
59 | return [ |
60 | 'confirmedLinkIDs' => [ |
61 | 'type' => 'multiselect', |
62 | 'options' => $options, |
63 | 'label' => wfMessage( 'authprovider-confirmlink-request-label' ), |
64 | 'help' => wfMessage( 'authprovider-confirmlink-request-help' ), |
65 | 'optional' => true, |
66 | ] |
67 | ]; |
68 | } |
69 | |
70 | /** |
71 | * @inheritDoc |
72 | * @stable to override |
73 | */ |
74 | public function getUniqueId() { |
75 | $ids = []; |
76 | foreach ( $this->linkRequests as $req ) { |
77 | $ids[] = $req->getUniqueId(); |
78 | } |
79 | return parent::getUniqueId() . ':' . implode( '|', $ids ); |
80 | } |
81 | |
82 | /** |
83 | * Implementing this mainly for use from the unit tests. |
84 | * @param array $data |
85 | * @return AuthenticationRequest |
86 | */ |
87 | public static function __set_state( $data ) { |
88 | $ret = new static( $data['linkRequests'] ); |
89 | foreach ( $data as $k => $v ) { |
90 | $ret->$k = $v; |
91 | } |
92 | return $ret; |
93 | } |
94 | } |