summaryrefslogtreecommitdiff
path: root/includes/api/ApiCreateAccount.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiCreateAccount.php')
-rw-r--r--includes/api/ApiCreateAccount.php52
1 files changed, 23 insertions, 29 deletions
diff --git a/includes/api/ApiCreateAccount.php b/includes/api/ApiCreateAccount.php
index 69748c93..0e752c56 100644
--- a/includes/api/ApiCreateAccount.php
+++ b/includes/api/ApiCreateAccount.php
@@ -47,17 +47,19 @@ class ApiCreateAccount extends ApiBase {
$params = $this->extractRequestParams();
- $result = array();
-
// Init session if necessary
if ( session_id() == '' ) {
wfSetupSession();
}
- if( $params['mailpassword'] && !$params['email'] ) {
+ if ( $params['mailpassword'] && !$params['email'] ) {
$this->dieUsageMsg( 'noemail' );
}
+ if ( $params['language'] && !Language::isSupportedLanguage( $params['language'] ) ) {
+ $this->dieUsage( 'Invalid language parameter', 'langinvalid' );
+ }
+
$context = new DerivativeContext( $this->getContext() );
$context->setRequest( new DerivativeRequest(
$this->getContext()->getRequest(),
@@ -82,22 +84,20 @@ class ApiCreateAccount extends ApiBase {
$status = $loginForm->addNewaccountInternal();
$result = array();
- if( $status->isGood() ) {
+ if ( $status->isGood() ) {
// Success!
+ global $wgEmailAuthentication;
$user = $status->getValue();
- // If we showed up language selection links, and one was in use, be
- // smart (and sensible) and save that language as the user's preference
- global $wgLoginLanguageSelector, $wgEmailAuthentication;
- if( $wgLoginLanguageSelector && $params['language'] ) {
+ if ( $params['language'] ) {
$user->setOption( 'language', $params['language'] );
}
- if( $params['mailpassword'] ) {
+ if ( $params['mailpassword'] ) {
// If mailpassword was set, disable the password and send an email.
$user->setPassword( null );
$status->merge( $loginForm->mailPasswordInternal( $user, false, 'createaccount-title', 'createaccount-text' ) );
- } elseif( $wgEmailAuthentication && Sanitizer::validateEmail( $user->getEmail() ) ) {
+ } elseif ( $wgEmailAuthentication && Sanitizer::validateEmail( $user->getEmail() ) ) {
// Send out an email authentication message if needed
$status->merge( $user->sendConfirmationMail() );
}
@@ -124,33 +124,23 @@ class ApiCreateAccount extends ApiBase {
$apiResult = $this->getResult();
- if( $status->hasMessage( 'sessionfailure' ) || $status->hasMessage( 'nocookiesfornew' ) ) {
+ if ( $status->hasMessage( 'sessionfailure' ) || $status->hasMessage( 'nocookiesfornew' ) ) {
// Token was incorrect, so add it to result, but don't throw an exception
// since not having the correct token is part of the normal
// flow of events.
$result['token'] = LoginForm::getCreateaccountToken();
$result['result'] = 'needtoken';
- } elseif( !$status->isOK() ) {
+ } elseif ( !$status->isOK() ) {
// There was an error. Die now.
- // Cannot use dieUsageMsg() directly because extensions
- // might return custom error messages.
- $errors = $status->getErrorsArray();
- if( $errors[0] instanceof Message ) {
- $code = 'aborted';
- $desc = $errors[0];
- } else {
- $code = array_shift( $errors[0] );
- $desc = wfMessage( $code, $errors[0] );
- }
- $this->dieUsage( $desc, $code );
- } elseif( !$status->isGood() ) {
+ $this->dieStatus( $status );
+ } elseif ( !$status->isGood() ) {
// Status is not good, but OK. This means warnings.
$result['result'] = 'warning';
// Add any warnings to the result
$warnings = $status->getErrorsByType( 'warning' );
- if( $warnings ) {
- foreach( $warnings as &$warning ) {
+ if ( $warnings ) {
+ foreach ( $warnings as &$warning ) {
$apiResult->setIndexedTagName( $warning['params'], 'param' );
}
$apiResult->setIndexedTagName( $warnings, 'warning' );
@@ -263,8 +253,8 @@ class ApiCreateAccount extends ApiBase {
$errors = parent::getPossibleErrors();
// All local errors are from LoginForm, which means they're actually message keys.
- foreach( $localErrors as $error ) {
- $errors[] = array( 'code' => $error, 'info' => wfMessage( $error )->parse() );
+ foreach ( $localErrors as $error ) {
+ $errors[] = array( 'code' => $error, 'info' => wfMessage( $error )->inLanguage( 'en' )->useDatabase( false )->parse() );
}
$errors[] = array(
@@ -279,12 +269,16 @@ class ApiCreateAccount extends ApiBase {
'code' => 'aborted',
'info' => 'Account creation aborted by hook (info may vary)'
);
+ $errors[] = array(
+ 'code' => 'langinvalid',
+ 'info' => 'Invalid language parameter'
+ );
// 'passwordtooshort' has parameters. :(
global $wgMinimalPasswordLength;
$errors[] = array(
'code' => 'passwordtooshort',
- 'info' => wfMessage( 'passwordtooshort', $wgMinimalPasswordLength )->parse()
+ 'info' => wfMessage( 'passwordtooshort', $wgMinimalPasswordLength )->inLanguage( 'en' )->useDatabase( false )->parse()
);
return $errors;
}