Merge "Delete UIDGenerator cache files after unit tests"
[lhc/web/wiklou.git] / includes / api / ApiCreateAccount.php
index f25f5ae..be8286c 100644 (file)
@@ -39,7 +39,10 @@ class ApiCreateAccount extends ApiBase {
                // Use userCan in order to hit GlobalBlock checks (according to Special:userlogin)
                $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
                if ( !$loginTitle->userCan( 'createaccount', $this->getUser() ) ) {
-                       $this->dieUsage( 'You do not have the right to create a new account', 'permdenied-createaccount' );
+                       $this->dieUsage(
+                               'You do not have the right to create a new account',
+                               'permdenied-createaccount'
+                       );
                }
                if ( $this->getUser()->isBlockedFromCreateAccount() ) {
                        $this->dieUsage( 'You cannot create a new account because you are blocked', 'blocked' );
@@ -80,6 +83,7 @@ class ApiCreateAccount extends ApiBase {
 
                $loginForm = new LoginForm();
                $loginForm->setContext( $context );
+               wfRunHooks( 'AddNewAccountApiForm', array( $this, $loginForm ) );
                $loginForm->load();
 
                $status = $loginForm->addNewaccountInternal();
@@ -96,7 +100,12 @@ class ApiCreateAccount extends ApiBase {
                        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' ) );
+                               $status->merge( $loginForm->mailPasswordInternal(
+                                       $user,
+                                       false,
+                                       'createaccount-title',
+                                       'createaccount-text'
+                               ) );
                        } elseif ( $wgEmailAuthentication && Sanitizer::validateEmail( $user->getEmail() ) ) {
                                // Send out an email authentication message if needed
                                $status->merge( $user->sendConfirmationMail() );
@@ -129,13 +138,13 @@ class ApiCreateAccount extends ApiBase {
                        // since not having the correct token is part of the normal
                        // flow of events.
                        $result['token'] = LoginForm::getCreateaccountToken();
-                       $result['result'] = 'needtoken';
+                       $result['result'] = 'NeedToken';
                } elseif ( !$status->isOK() ) {
                        // There was an error. Die now.
                        $this->dieStatus( $status );
                } elseif ( !$status->isGood() ) {
                        // Status is not good, but OK. This means warnings.
-                       $result['result'] = 'warning';
+                       $result['result'] = 'Warning';
 
                        // Add any warnings to the result
                        $warnings = $status->getErrorsByType( 'warning' );
@@ -148,9 +157,12 @@ class ApiCreateAccount extends ApiBase {
                        }
                } else {
                        // Everything was fine.
-                       $result['result'] = 'success';
+                       $result['result'] = 'Success';
                }
 
+               // Give extensions a chance to modify the API result data
+               wfRunHooks( 'AddNewAccountApiResult', array( $this, $loginForm, &$result ) );
+
                $apiResult->addValue( null, 'createaccount', $result );
        }
 
@@ -207,7 +219,8 @@ class ApiCreateAccount extends ApiBase {
                        'realname' => 'Real name of user (optional)',
                        'mailpassword' => 'If set to any value, a random password will be emailed to the user',
                        'reason' => 'Optional reason for creating the account to be put in the logs',
-                       'language' => 'Language code to set as default for the user (optional, defaults to content language)'
+                       'language'
+                               => 'Language code to set as default for the user (optional, defaults to content language)'
                );
        }
 
@@ -216,9 +229,9 @@ class ApiCreateAccount extends ApiBase {
                        'createaccount' => array(
                                'result' => array(
                                        ApiBase::PROP_TYPE => array(
-                                               'success',
-                                               'warning',
-                                               'needtoken'
+                                               'Success',
+                                               'Warning',
+                                               'NeedToken'
                                        )
                                ),
                                'username' => array(
@@ -256,7 +269,10 @@ 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 )->inLanguage( 'en' )->useDatabase( false )->parse() );
+                       $errors[] = array(
+                               'code' => $error,
+                               'info' => wfMessage( $error )->inLanguage( 'en' )->useDatabase( false )->parse()
+                       );
                }
 
                $errors[] = array(
@@ -280,7 +296,8 @@ class ApiCreateAccount extends ApiBase {
                global $wgMinimalPasswordLength;
                $errors[] = array(
                        'code' => 'passwordtooshort',
-                       'info' => wfMessage( 'passwordtooshort', $wgMinimalPasswordLength )->inLanguage( 'en' )->useDatabase( false )->parse()
+                       'info' => wfMessage( 'passwordtooshort', $wgMinimalPasswordLength )
+                               ->inLanguage( 'en' )->useDatabase( false )->parse()
                );
 
                return $errors;