/**
  * Static factory method for creation from username.
  *
  * This is slightly less efficient than newFromId(), so use newFromId() if
  * you have both an ID and a name handy.
  *
  * @param string $name Username, validated by Title::newFromText()
  * @param string|Bool $validate Validate username. Takes the same parameters as
  *    User::getCanonicalName(), except that true is accepted as an alias
  *    for 'valid', for BC.
  *
  * @return EmailableUser|bool EmailableUser object, or false if the
  *    username is invalid (e.g. if it contains illegal characters or is an IP address).
  *    If the username is not present in the database, the result will be a user object
  *    with a name, zero user ID and default settings.
  */
 public static function newFromName($name, $validate = 'valid')
 {
     if ($validate === true) {
         $validate = 'valid';
     }
     $name = self::getCanonicalName($name, $validate);
     if ($name === false) {
         return false;
     } else {
         # Create unloaded user object
         $u = new EmailableUser();
         $u->mName = $name;
         $u->mFrom = 'name';
         $u->setItemLoaded('name');
         return $u;
     }
 }
 function resendConfirmationEmail($username)
 {
     $wikiID = wfWikiID();
     $this->total++;
     $this->output("Sending confirmation email for: '{$username}@{$wikiID}'\n");
     // we want to start with the local user
     $user = EmailableUser::newFromName($username);
     if ($user === false) {
         $this->output("ERROR: {$username} is an invalid username\n");
         return;
     }
     $user->load();
     if (!$this->sendToConfirmed && $user->isEmailConfirmed()) {
         $this->output("ERROR: The user '{$username}@{$wikiID}' already has a confirmed email address\n");
         return;
     }
     $central = CentralAuthUser::getInstance($user);
     if (!$central->exists()) {
         $this->output("ERROR: No global account for '{$username}'\n");
         return;
     }
     if (!$central->isAttached()) {
         $this->output("ERROR: '{$username}@{$wikiID}' is not attached to the global user\n");
         return;
     }
     $unattached = $central->queryUnattached();
     if (count($unattached) == 0) {
         $this->output("ERROR: No unattached accounts for '{$username}'\n");
         return;
     }
     if ($this->dryrun) {
         $this->output("Would have sent email\n");
         return;
     }
     if ($user->sendConfirmAndMigrateMail()) {
         $this->output("Sent email to {$username}\n");
         $this->sent++;
         sleep($this->sleep);
     } else {
         $this->output("ERROR: Sending confirm and migrate email failed for '{$username}@{$wikiID}'\n");
     }
 }