MediaWiki  1.27.1
SpecialCreateAccount.php
Go to the documentation of this file.
1 <?php
27 
34  protected static $allowedActions = [
35  AuthManager::ACTION_CREATE,
36  AuthManager::ACTION_CREATE_CONTINUE
37  ];
38 
39  protected static $messages = [
40  'authform-newtoken' => 'nocookiesfornew',
41  'authform-notoken' => 'sessionfailure',
42  'authform-wrongtoken' => 'sessionfailure',
43  ];
44 
45  public function __construct() {
46  parent::__construct( 'CreateAccount' );
47  }
48 
49  public function doesWrites() {
50  return true;
51  }
52 
53  public function isRestricted() {
54  return !User::groupHasPermission( '*', 'createaccount' );
55  }
56 
57  public function userCanExecute( User $user ) {
58  return $user->isAllowed( 'createaccount' );
59  }
60 
61  public function checkPermissions() {
62  parent::checkPermissions();
63 
64  $user = $this->getUser();
65  $status = AuthManager::singleton()->checkAccountCreatePermissions( $user );
66  if ( !$status->isGood() ) {
67  throw new ErrorPageError( 'createacct-error', $status->getMessage() );
68  }
69  }
70 
71  protected function getLoginSecurityLevel() {
72  return false;
73  }
74 
75  protected function getDefaultAction( $subPage ) {
76  return AuthManager::ACTION_CREATE;
77  }
78 
79  public function getDescription() {
80  return $this->msg( 'createaccount' )->text();
81  }
82 
83  protected function isSignup() {
84  return true;
85  }
86 
94  protected function successfulAction( $direct = false, $extraMessages = null ) {
95  $session = $this->getRequest()->getSession();
96  $user = $this->targetUser ?: $this->getUser();
97 
98  if ( $direct ) {
99  # Only save preferences if the user is not creating an account for someone else.
100  if ( !$this->proxyAccountCreation ) {
101  Hooks::run( 'AddNewAccount', [ $user, false ] );
102 
103  // If the user does not have a session cookie at this point, they probably need to
104  // do something to their browser.
105  if ( !$this->hasSessionCookie() ) {
106  $this->mainLoginForm( [ /*?*/ ], $session->getProvider()->whyNoSession() );
107  // TODO something more specific? This used to use nocookiesnew
108  // FIXME should redirect to login page instead?
109  return;
110  }
111  } else {
112  $byEmail = false; // FIXME no way to set this
113 
114  Hooks::run( 'AddNewAccount', [ $user, $byEmail ] );
115 
116  $out = $this->getOutput();
117  $out->setPageTitle( $this->msg( $byEmail ? 'accmailtitle' : 'accountcreated' ) );
118  if ( $byEmail ) {
119  $out->addWikiMsg( 'accmailtext', $user->getName(), $user->getEmail() );
120  } else {
121  $out->addWikiMsg( 'accountcreatedtext', $user->getName() );
122  }
123  $out->addReturnTo( $this->getPageTitle() );
124  return;
125  }
126  }
127 
128  $this->clearToken();
129 
130  # Run any hooks; display injected HTML
131  $injected_html = '';
132  $welcome_creation_msg = 'welcomecreation-msg';
133  Hooks::run( 'UserLoginComplete', [ &$user, &$injected_html ] );
134 
140  Hooks::run( 'BeforeWelcomeCreation', [ &$welcome_creation_msg, &$injected_html ] );
141 
142  $this->showSuccessPage( 'signup', $this->msg( 'welcomeuser', $this->getUser()->getName() ),
143  $welcome_creation_msg, $injected_html, $extraMessages );
144  }
145 
146  protected function getToken() {
147  return $this->getRequest()->getSession()->getToken( '', 'createaccount' );
148  }
149 
150  protected function clearToken() {
151  return $this->getRequest()->getSession()->resetToken( 'createaccount' );
152  }
153 
154  protected function getTokenName() {
155  return 'wpCreateaccountToken';
156  }
157 
158  protected function getGroupName() {
159  return 'login';
160  }
161 
162  protected function logAuthResult( $success, $status = null ) {
163  LoggerFactory::getInstance( 'authmanager-stats' )->info( 'Account creation attempt', [
164  'event' => 'accountcreation',
165  'successful' => $success,
166  'status' => $status,
167  ] );
168  }
169 }
successfulAction($direct=false, $extraMessages=null)
Run any hooks registered for logins, then display a message welcoming the user.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:762
$success
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
hasSessionCookie()
Check if a session cookie is present.
mainLoginForm(array $requests, $msg= '', $msgtype= 'error')
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
Holds shared logic for login and account creation pages.
logAuthResult($success, $status=null)
showSuccessPage($type, $title, $msgname, $injected_html, $extraMessages)
Show the success page.
static groupHasPermission($group, $role)
Check, if the given group has the given permission.
Definition: User.php:4554
An error page which can definitely be safely rendered using the OutputPage.
isAllowed($action= '')
Internal mechanics of testing a permission.
Definition: User.php:3410
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getName()
Get the name of this Special Page.
getUser()
Shortcut to get the User executing this instance.
Implements Special:CreateAccount.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1004
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method.MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances.The"Spi"in MediaWiki\Logger\Spi stands for"service provider interface".An SPI is an API intended to be implemented or extended by a third party.This software design pattern is intended to enable framework extension and replaceable components.It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki.The service provider interface allows the backend logging library to be implemented in multiple ways.The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime.This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance.Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
string $subPage
Subpage of the special page.
getPageTitle($subpage=false)
Get a self-referential title object.