/**
  * Attempt to automatically create a user on login. Only succeeds if there
  * is an external authentication method which allows it.
  *
  * @param $user User
  *
  * @return integer Status code
  */
 function attemptAutoCreate($user)
 {
     global $wgAuth, $wgAutocreatePolicy;
     if ($this->getUser()->isBlockedFromCreateAccount()) {
         wfDebug(__METHOD__ . ": user is blocked from account creation\n");
         return self::CREATE_BLOCKED;
     }
     /**
      * If the external authentication plugin allows it, automatically cre-
      * ate a new account for users that are externally defined but have not
      * yet logged in.
      */
     if ($this->mExtUser) {
         # mExtUser is neither null nor false, so use the new ExternalAuth
         # system.
         if ($wgAutocreatePolicy == 'never') {
             return self::NOT_EXISTS;
         }
         if (!$this->mExtUser->authenticate($this->mPassword)) {
             return self::WRONG_PLUGIN_PASS;
         }
     } else {
         # Old AuthPlugin.
         if (!$wgAuth->autoCreate()) {
             return self::NOT_EXISTS;
         }
         if (!$wgAuth->userExists($user->getName())) {
             wfDebug(__METHOD__ . ": user does not exist\n");
             return self::NOT_EXISTS;
         }
         if (!$wgAuth->authenticate($user->getName(), $this->mPassword)) {
             wfDebug(__METHOD__ . ": \$wgAuth->authenticate() returned false, aborting\n");
             return self::WRONG_PLUGIN_PASS;
         }
     }
     $abortError = '';
     if (!wfRunHooks('AbortAutoAccount', array($user, &$abortError))) {
         // Hook point to add extra creation throttles and blocks
         wfDebug("LoginForm::attemptAutoCreate: a hook blocked creation: {$abortError}\n");
         $this->mAbortLoginErrorMsg = $abortError;
         return self::ABORTED;
     }
     wfDebug(__METHOD__ . ": creating account\n");
     $status = $this->initUser($user, true);
     if (!$status->isOK()) {
         $errors = $status->getErrorsByType('error');
         $this->mAbortLoginErrorMsg = $errors[0]['message'];
         return self::ABORTED;
     }
     return self::SUCCESS;
 }