]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/auth/PasswordDomainAuthenticationRequest.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / auth / PasswordDomainAuthenticationRequest.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 /**
25  * This is a value object for authentication requests with a username, password, and domain
26  * @ingroup Auth
27  * @since 1.27
28  */
29 class PasswordDomainAuthenticationRequest extends PasswordAuthenticationRequest {
30         /** @var string[] Domains available */
31         private $domainList;
32
33         /** @var string Domain */
34         public $domain = null;
35
36         /**
37          * @param string[] $domainList List of available domains
38          */
39         public function __construct( array $domainList ) {
40                 $this->domainList = $domainList;
41         }
42
43         public function getFieldInfo() {
44                 $ret = parent::getFieldInfo();
45
46                 // Only add a domain field if we have the username field included
47                 if ( isset( $ret['username'] ) ) {
48                         $ret['domain'] = [
49                                 'type' => 'select',
50                                 'options' => [],
51                                 'label' => wfMessage( 'yourdomainname' ),
52                                 'help' => wfMessage( 'authmanager-domain-help' ),
53                         ];
54                         foreach ( $this->domainList as $domain ) {
55                                 $ret['domain']['options'][$domain] = new \RawMessage( '$1', [ $domain ] );
56                         }
57                 }
58
59                 return $ret;
60         }
61
62         public function describeCredentials() {
63                 return [
64                         'provider' => wfMessage( 'authmanager-provider-password-domain' ),
65                         'account' => wfMessage(
66                                 'authmanager-account-password-domain', [ $this->username, $this->domain ]
67                         ),
68                 ];
69         }
70
71         /**
72          * @codeCoverageIgnore
73          * @param array $data
74          * @return AuthenticationRequest|static
75          */
76         public static function __set_state( $data ) {
77                 $ret = new static( $data['domainList'] );
78                 foreach ( $data as $k => $v ) {
79                         if ( $k !== 'domainList' ) {
80                                 $ret->$k = $v;
81                         }
82                 }
83                 return $ret;
84         }
85 }