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.
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.
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
21 namespace MediaWiki\Specials
;
24 use MediaWiki\Auth\AuthManager
;
25 use MediaWiki\Language\FormatterFactory
;
26 use MediaWiki\Logger\LoggerFactory
;
27 use MediaWiki\SpecialPage\LoginSignupSpecialPage
;
28 use MediaWiki\Title\Title
;
29 use MediaWiki\User\UserIdentity
;
30 use MediaWiki\User\UserIdentityUtils
;
34 * Implements Special:CreateAccount
36 * @ingroup SpecialPage
39 class SpecialCreateAccount
extends LoginSignupSpecialPage
{
41 protected static $allowedActions = [
42 AuthManager
::ACTION_CREATE
,
43 AuthManager
::ACTION_CREATE_CONTINUE
47 protected static $messages = [
48 'authform-newtoken' => 'nocookiesfornew',
49 'authform-notoken' => 'sessionfailure',
50 'authform-wrongtoken' => 'sessionfailure',
53 private FormatterFactory
$formatterFactory;
55 private UserIdentityUtils
$identityUtils;
58 * @param AuthManager $authManager
59 * @param FormatterFactory $formatterFactory
60 * @param UserIdentityUtils $identityUtils
62 public function __construct(
63 AuthManager
$authManager,
64 FormatterFactory
$formatterFactory,
65 UserIdentityUtils
$identityUtils
67 parent
::__construct( 'CreateAccount', 'createaccount' );
69 $this->setAuthManager( $authManager );
70 $this->formatterFactory
= $formatterFactory;
71 $this->identityUtils
= $identityUtils;
74 public function doesWrites() {
78 public function checkPermissions() {
79 parent
::checkPermissions();
81 $performer = $this->getAuthority();
82 $authManager = $this->getAuthManager();
84 $status = $this->mPosted ?
85 $authManager->authorizeCreateAccount( $performer ) :
86 $authManager->probablyCanCreateAccount( $performer );
88 if ( !$status->isGood() ) {
89 $formatter = $this->formatterFactory
->getStatusFormatter( $this->getContext() );
90 throw new ErrorPageError(
92 $formatter->getMessage( $status )
97 protected function getLoginSecurityLevel() {
101 protected function getDefaultAction( $subPage ) {
102 return AuthManager
::ACTION_CREATE
;
105 public function getDescription() {
106 return $this->msg( 'createaccount' );
109 protected function isSignup() {
114 * Run any hooks registered for logins, then display a message welcoming
116 * @param bool $direct True if the action was successful just now; false if that happened
117 * pre-redirection (so this handler was called already)
118 * @param StatusValue|null $extraMessages
120 protected function successfulAction( $direct = false, $extraMessages = null ) {
121 $session = $this->getRequest()->getSession();
122 $user = $this->targetUser ?
: $this->getUser();
126 # Only save preferences if the user is not creating an account for someone else.
127 if ( !$this->proxyAccountCreation
) {
128 $this->getHookRunner()->onAddNewAccount( $user, false );
130 // If the user does not have a session cookie at this point, they probably need to
131 // do something to their browser.
132 if ( !$this->hasSessionCookie() ) {
133 $this->mainLoginForm( [ /*?*/ ], $session->getProvider()->whyNoSession() );
134 // TODO something more specific? This used to use nocookiesnew
135 // FIXME should redirect to login page instead?
139 $byEmail = false; // FIXME no way to set this
141 $this->getHookRunner()->onAddNewAccount( $user, $byEmail );
143 $out = $this->getOutput();
144 // @phan-suppress-next-line PhanImpossibleCondition
145 $out->setPageTitleMsg( $this->msg( $byEmail ?
'accmailtitle' : 'accountcreated' ) );
146 // @phan-suppress-next-line PhanImpossibleCondition
148 $out->addWikiMsg( 'accmailtext', $user->getName(), $user->getEmail() );
150 $out->addWikiMsg( 'accountcreatedtext', $user->getName() );
153 $rt = Title
::newFromText( $this->mReturnTo
);
155 ( $rt && !$rt->isExternal() ) ?
$rt : $this->getPageTitle(),
156 wfCgiToArray( $this->mReturnToQuery
)
160 $this->getHookRunner()->onUserLoginComplete( $user, $injected_html, $direct );
165 # Run any hooks; display injected HTML
166 $welcome_creation_msg = 'welcomecreation-msg';
168 * Let any extensions change what message is shown.
169 * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeWelcomeCreation
172 $this->getHookRunner()->onBeforeWelcomeCreation( $welcome_creation_msg, $injected_html );
174 $this->showSuccessPage( 'signup',
175 // T308471: ensure username is plaintext (aka escaped)
176 $this->msg( 'welcomeuser' )->plaintextParams( $this->getUser()->getName() ),
177 $welcome_creation_msg, $injected_html, $extraMessages );
180 protected function getToken() {
181 return $this->getRequest()->getSession()->getToken( '', 'createaccount' );
184 protected function clearToken() {
185 $this->getRequest()->getSession()->resetToken( 'createaccount' );
188 protected function getTokenName() {
189 return 'wpCreateaccountToken';
192 protected function getGroupName() {
196 protected function logAuthResult( $success, UserIdentity
$performer, $status = null ) {
197 LoggerFactory
::getInstance( 'authevents' )->info( 'Account creation attempt', [
198 'event' => 'accountcreation',
199 'successful' => $success,
200 'accountType' => $this->identityUtils
->getShortUserTypeInternal( $performer ),
201 'status' => strval( $status ),
206 /** @deprecated class alias since 1.41 */
207 class_alias( SpecialCreateAccount
::class, 'SpecialCreateAccount' );