/**
  * (a) Try to confirm an email address via a token
  * (b) Notify $wgConfirmAccountContact on success
  * @param $code string The token
  * @return void
  */
 protected function confirmEmailToken($code)
 {
     global $wgConfirmAccountContact, $wgPasswordSender, $wgPasswordSenderName;
     $reqUser = $this->getUser();
     $out = $this->getOutput();
     # Confirm if this token is in the pending requests
     $name = ConfirmAccount::requestNameFromEmailToken($code);
     if ($name !== false) {
         # Send confirmation email to prospective user
         ConfirmAccount::confirmEmail($name);
         # Send mail to admin after e-mail has been confirmed
         if ($wgConfirmAccountContact != '') {
             $target = new MailAddress($wgConfirmAccountContact);
             $source = new MailAddress($wgPasswordSender, $wgPasswordSenderName);
             $title = SpecialPage::getTitleFor('ConfirmAccounts');
             $subject = wfMsgForContent('requestaccount-email-subj-admin');
             $body = wfMsgForContent('requestaccount-email-body-admin', $name, $title->getFullUrl());
             # Actually send the email...
             $result = UserMailer::send($target, $source, $subject, $body);
             if (!$result->isOK()) {
                 wfDebug("Could not sent email to admin at {$target}\n");
             }
         }
         $out->addWikiMsg('request-account-econf');
         $out->returnToMain();
     } else {
         # Maybe the user confirmed after account was created...
         $user = User::newFromConfirmationCode($code);
         if (is_object($user)) {
             if ($user->confirmEmail()) {
                 $message = $reqUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
                 $out->addWikiMsg($message);
                 if (!$reqUser->isLoggedIn()) {
                     $title = SpecialPage::getTitleFor('Userlogin');
                     $out->returnToMain(true, $title->getPrefixedUrl());
                 }
             } else {
                 $out->addWikiMsg('confirmemail_error');
             }
         } else {
             $out->addWikiMsg('confirmemail_invalid');
         }
     }
 }
 /**
  * (a) Try to confirm an email address via a token
  * (b) Notify $wgConfirmAccountContact on success
  * @param $code string The token
  * @return void
  */
 protected function confirmEmailToken($code)
 {
     global $wgConfirmAccountContact, $wgPasswordSender;
     $reqUser = $this->getUser();
     $out = $this->getOutput();
     # Confirm if this token is in the pending requests
     $name = ConfirmAccount::requestNameFromEmailToken($code);
     if ($name !== false) {
         # Send confirmation email to prospective user
         ConfirmAccount::confirmEmail($name);
         $adminsNotify = ConfirmAccount::getAdminsToNotify();
         # Send an email to admin after email has been confirmed
         if ($adminsNotify->count() || $wgConfirmAccountContact != '') {
             $title = SpecialPage::getTitleFor('ConfirmAccounts');
             $subject = $this->msg('requestaccount-email-subj-admin')->inContentLanguage()->escaped();
             $body = $this->msg('requestaccount-email-body-admin', $name)->rawParams($title->getFullUrl())->inContentLanguage()->escaped();
             # Actually send the email...
             if ($wgConfirmAccountContact != '') {
                 $source = new MailAddress($wgPasswordSender, wfMessage('emailsender')->text());
                 $target = new MailAddress($wgConfirmAccountContact);
                 $result = UserMailer::send($target, $source, $subject, $body);
                 if (!$result->isOK()) {
                     wfDebug("Could not sent email to admin at {$target}\n");
                 }
             }
             # Send an email to all users with "confirmaccount-notify" rights
             foreach ($adminsNotify as $adminNotify) {
                 if ($adminNotify->canReceiveEmail()) {
                     $adminNotify->sendMail($subject, $body);
                 }
             }
         }
         $out->addWikiMsg('request-account-econf');
         $out->returnToMain();
     } else {
         # Maybe the user confirmed after account was created...
         $user = User::newFromConfirmationCode($code);
         if (is_object($user)) {
             $user->confirmEmail();
             $user->saveSettings();
             $message = $reqUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
             $out->addWikiMsg($message);
             if (!$reqUser->isLoggedIn()) {
                 $title = SpecialPage::getTitleFor('Userlogin');
                 $out->returnToMain(true, $title);
             }
         } else {
             $out->addWikiMsg('confirmemail_invalid');
         }
     }
 }