MediaWiki  master
SpecialCreateAccount.php
Go to the documentation of this file.
1 <?php
28 
35  protected static $allowedActions = [
36  AuthManager::ACTION_CREATE,
37  AuthManager::ACTION_CREATE_CONTINUE
38  ];
39 
40  protected static $messages = [
41  'authform-newtoken' => 'nocookiesfornew',
42  'authform-notoken' => 'sessionfailure',
43  'authform-wrongtoken' => 'sessionfailure',
44  ];
45 
47  private $permManager;
48 
53  parent::__construct( 'CreateAccount' );
54 
55  $this->permManager = $permManager;
56  }
57 
58  public function doesWrites() {
59  return true;
60  }
61 
62  public function isRestricted() {
63  return !$this->permManager->groupHasPermission( '*', 'createaccount' );
64  }
65 
66  public function userCanExecute( User $user ) {
67  return $this->permManager->userHasRight( $user, 'createaccount' );
68  }
69 
70  public function checkPermissions() {
71  parent::checkPermissions();
72 
73  $user = $this->getUser();
74  $status = MediaWikiServices::getInstance()->getAuthManager()
75  ->checkAccountCreatePermissions( $user );
76  if ( !$status->isGood() ) {
77  throw new ErrorPageError( 'createacct-error', $status->getMessage() );
78  }
79  }
80 
81  protected function getLoginSecurityLevel() {
82  return false;
83  }
84 
85  protected function getDefaultAction( $subPage ) {
86  return AuthManager::ACTION_CREATE;
87  }
88 
89  public function getDescription() {
90  return $this->msg( 'createaccount' )->text();
91  }
92 
93  protected function isSignup() {
94  return true;
95  }
96 
104  protected function successfulAction( $direct = false, $extraMessages = null ) {
105  $session = $this->getRequest()->getSession();
106  $user = $this->targetUser ?: $this->getUser();
107 
108  if ( $direct ) {
109  # Only save preferences if the user is not creating an account for someone else.
110  if ( !$this->proxyAccountCreation ) {
111  $this->getHookRunner()->onAddNewAccount( $user, false );
112 
113  // If the user does not have a session cookie at this point, they probably need to
114  // do something to their browser.
115  if ( !$this->hasSessionCookie() ) {
116  $this->mainLoginForm( [ /*?*/ ], $session->getProvider()->whyNoSession() );
117  // TODO something more specific? This used to use nocookiesnew
118  // FIXME should redirect to login page instead?
119  return;
120  }
121  } else {
122  $byEmail = false; // FIXME no way to set this
123 
124  $this->getHookRunner()->onAddNewAccount( $user, $byEmail );
125 
126  $out = $this->getOutput();
127  // @phan-suppress-next-line PhanImpossibleCondition
128  $out->setPageTitle( $this->msg( $byEmail ? 'accmailtitle' : 'accountcreated' ) );
129  // @phan-suppress-next-line PhanImpossibleCondition
130  if ( $byEmail ) {
131  $out->addWikiMsg( 'accmailtext', $user->getName(), $user->getEmail() );
132  } else {
133  $out->addWikiMsg( 'accountcreatedtext', $user->getName() );
134  }
135 
136  $rt = Title::newFromText( $this->mReturnTo );
137  $out->addReturnTo(
138  ( $rt && !$rt->isExternal() ) ? $rt : $this->getPageTitle(),
139  wfCgiToArray( $this->mReturnToQuery )
140  );
141  return;
142  }
143  }
144 
145  $this->clearToken();
146 
147  # Run any hooks; display injected HTML
148  $injected_html = '';
149  $welcome_creation_msg = 'welcomecreation-msg';
150  $this->getHookRunner()->onUserLoginComplete( $user, $injected_html, $direct );
151 
157  $this->getHookRunner()->onBeforeWelcomeCreation( $welcome_creation_msg, $injected_html );
158 
159  $this->showSuccessPage( 'signup', $this->msg( 'welcomeuser', $this->getUser()->getName() ),
160  $welcome_creation_msg, $injected_html, $extraMessages );
161  }
162 
163  protected function getToken() {
164  return $this->getRequest()->getSession()->getToken( '', 'createaccount' );
165  }
166 
167  protected function clearToken() {
168  return $this->getRequest()->getSession()->resetToken( 'createaccount' );
169  }
170 
171  protected function getTokenName() {
172  return 'wpCreateaccountToken';
173  }
174 
175  protected function getGroupName() {
176  return 'login';
177  }
178 
179  protected function logAuthResult( $success, $status = null ) {
180  LoggerFactory::getInstance( 'authevents' )->info( 'Account creation attempt', [
181  'event' => 'accountcreation',
182  'successful' => $success,
183  'status' => $status,
184  ] );
185  }
186 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:828
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:328
SpecialCreateAccount\getDefaultAction
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
Definition: SpecialCreateAccount.php:85
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:744
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:157
SpecialCreateAccount\__construct
__construct(PermissionManager $permManager)
Definition: SpecialCreateAccount.php:52
LoginSignupSpecialPage\showSuccessPage
showSuccessPage( $type, $title, $msgname, $injected_html, $extraMessages)
Show the success page.
Definition: LoginSignupSpecialPage.php:440
SpecialCreateAccount\$messages
static $messages
Definition: SpecialCreateAccount.php:40
SpecialCreateAccount\isSignup
isSignup()
Definition: SpecialCreateAccount.php:93
SpecialCreateAccount\getTokenName
getTokenName()
Returns the name of the CSRF token (under which it should be found in the POST or GET data).
Definition: SpecialCreateAccount.php:171
SpecialCreateAccount\doesWrites
doesWrites()
Indicates whether this special page may perform database writes.
Definition: SpecialCreateAccount.php:58
$success
$success
Definition: NoLocalSettings.php:42
SpecialPage\getName
getName()
Get the name of this Special Page.
Definition: SpecialPage.php:164
SpecialCreateAccount\successfulAction
successfulAction( $direct=false, $extraMessages=null)
Run any hooks registered for logins, then display a message welcoming the user.
Definition: SpecialCreateAccount.php:104
SpecialCreateAccount\clearToken
clearToken()
Definition: SpecialCreateAccount.php:167
SpecialCreateAccount
Implements Special:CreateAccount.
Definition: SpecialCreateAccount.php:34
SpecialCreateAccount\getDescription
getDescription()
Returns the name that goes in the <h1> in the special page itself, and also the name that will be l...
Definition: SpecialCreateAccount.php:89
AuthManagerSpecialPage\$subPage
string $subPage
Subpage of the special page.
Definition: AuthManagerSpecialPage.php:38
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1011
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
SpecialCreateAccount\$permManager
PermissionManager $permManager
Definition: SpecialCreateAccount.php:47
LoginSignupSpecialPage
Holds shared logic for login and account creation pages.
Definition: LoginSignupSpecialPage.php:37
SpecialCreateAccount\getLoginSecurityLevel
getLoginSecurityLevel()
Stable to override.
Definition: SpecialCreateAccount.php:81
wfCgiToArray
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
Definition: GlobalFunctions.php:391
LoginSignupSpecialPage\mainLoginForm
mainLoginForm(array $requests, $msg='', $msgtype='error')
Definition: LoginSignupSpecialPage.php:519
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:754
LoginSignupSpecialPage\hasSessionCookie
hasSessionCookie()
Check if a session cookie is present.
Definition: LoginSignupSpecialPage.php:1075
SpecialCreateAccount\logAuthResult
logAuthResult( $success, $status=null)
Logs to the authmanager-stats channel.
Definition: SpecialCreateAccount.php:179
SpecialCreateAccount\$allowedActions
static $allowedActions
Definition: SpecialCreateAccount.php:35
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:49
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:88
SpecialCreateAccount\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialCreateAccount.php:175
SpecialCreateAccount\getToken
getToken()
Returns the CSRF token.
Definition: SpecialCreateAccount.php:163
SpecialCreateAccount\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialCreateAccount.php:70
SpecialCreateAccount\isRestricted
isRestricted()
Can be overridden by subclasses with more complicated permissions schemes.
Definition: SpecialCreateAccount.php:62
AuthManagerSpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: AuthManagerSpecialPage.php:73
SpecialCreateAccount\userCanExecute
userCanExecute(User $user)
Checks if the given user (identified by an object) can execute this special page (as defined by $mRes...
Definition: SpecialCreateAccount.php:66
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:30
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:55