Merge "Added a separate error message for mkdir failures"
[lhc/web/wiklou.git] / includes / auth / CreateFromLoginAuthenticationRequest.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 transfers state between the login and account creation flows.
26 *
27 * AuthManager::getAuthenticationRequests() won't return this type, but it
28 * may be passed to AuthManager::beginAuthentication() or
29 * AuthManager::beginAccountCreation() anyway.
30 *
31 * @ingroup Auth
32 * @since 1.27
33 */
34 class CreateFromLoginAuthenticationRequest extends AuthenticationRequest {
35 public $required = self::OPTIONAL;
36
37 /** @var AuthenticationRequest|null */
38 public $createRequest;
39
40 /** @var AuthenticationRequest[] */
41 public $maybeLink = [];
42
43 /**
44 * @param AuthenticationRequest|null $createRequest A request to use to
45 * begin creating the account
46 * @param AuthenticationRequest[] $maybeLink Additional accounts to link
47 * after creation.
48 */
49 public function __construct(
50 AuthenticationRequest $createRequest = null, array $maybeLink = []
51 ) {
52 $this->createRequest = $createRequest;
53 $this->maybeLink = $maybeLink;
54 $this->username = $createRequest ? $createRequest->username : null;
55 }
56
57 public function getFieldInfo() {
58 return [];
59 }
60
61 public function loadFromSubmission( array $data ) {
62 return true;
63 }
64
65 /**
66 * Indicate whether this request contains any state for the specified
67 * action.
68 * @param string $action One of the AuthManager::ACTION_* constants
69 * @return boolean
70 */
71 public function hasStateForAction( $action ) {
72 switch ( $action ) {
73 case AuthManager::ACTION_LOGIN:
74 return (bool)$this->maybeLink;
75 case AuthManager::ACTION_CREATE:
76 return $this->maybeLink || $this->createRequest;
77 default:
78 return false;
79 }
80 }
81
82 /**
83 * Indicate whether this request contains state for the specified
84 * action sufficient to replace other primary-required requests.
85 * @param string $action One of the AuthManager::ACTION_* constants
86 * @return boolean
87 */
88 public function hasPrimaryStateForAction( $action ) {
89 switch ( $action ) {
90 case AuthManager::ACTION_CREATE:
91 return (bool)$this->createRequest;
92 default:
93 return false;
94 }
95 }
96 }