Merge "Added a separate error message for mkdir failures"
[lhc/web/wiklou.git] / includes / auth / ConfirmLinkAuthenticationRequest.php
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 class ConfirmLinkAuthenticationRequest extends AuthenticationRequest {
25 /** @var AuthenticationRequest[] */
26 protected $linkRequests;
27
28 /** @var string[] List of unique IDs of the confirmed accounts. */
29 public $confirmedLinkIDs = [];
30
31 /**
32 * @param AuthenticationRequest[] $linkRequests A list of autolink requests
33 * which need to be confirmed.
34 */
35 public function __construct( array $linkRequests ) {
36 if ( !$linkRequests ) {
37 throw new \InvalidArgumentException( '$linkRequests must not be empty' );
38 }
39 $this->linkRequests = $linkRequests;
40 }
41
42 public function getFieldInfo() {
43 $options = [];
44 foreach ( $this->linkRequests as $req ) {
45 $description = $req->describeCredentials();
46 $options[$req->getUniqueId()] = wfMessage(
47 'authprovider-confirmlink-option',
48 $description['provider']->text(), $description['account']->text()
49 );
50 }
51 return [
52 'confirmedLinkIDs' => [
53 'type' => 'multiselect',
54 'options' => $options,
55 'label' => wfMessage( 'authprovider-confirmlink-request-label' ),
56 'help' => wfMessage( 'authprovider-confirmlink-request-help' ),
57 'optional' => true,
58 ]
59 ];
60 }
61
62 public function getUniqueId() {
63 return parent::getUniqueId() . ':' . implode( '|', array_map( function ( $req ) {
64 return $req->getUniqueId();
65 }, $this->linkRequests ) );
66 }
67
68 /**
69 * Implementing this mainly for use from the unit tests.
70 * @param array $data
71 * @return AuthenticationRequest
72 */
73 public static function __set_state( $data ) {
74 $ret = new static( $data['linkRequests'] );
75 foreach ( $data as $k => $v ) {
76 $ret->$k = $v;
77 }
78 return $ret;
79 }
80 }