/**
  * Show the special page
  *
  * @param $par Mixed: parameter passed to the page or null
  */
 public function execute($par)
 {
     global $wgExternalAuthType;
     // Set page title and other stuff
     $this->setHeaders();
     $user = $this->getUser();
     $output = $this->getOutput();
     # If the user isn't permitted to access this special page, display an error
     if (!$user->isAllowed('editaccount')) {
         throw new PermissionsError('editaccount');
     }
     # Show a message if the database is in read-only mode
     if (wfReadOnly()) {
         $output->readOnlyPage();
         return;
     }
     # If user is blocked, s/he doesn't need to access this page
     if ($user->isBlocked()) {
         throw new UserBlockedError($this->getUser()->mBlock);
     }
     $output->addModuleStyles('ext.editAccount');
     $request = $this->getRequest();
     $action = $request->getVal('wpAction');
     #get name to work on. subpage is supported, but form submit name trumps
     $userName = $request->getVal('wpUserName', $par);
     if ($userName !== null) {
         #got a name, clean it up
         $userName = str_replace("_", " ", trim($userName));
         $userName = ucfirst($userName);
         # user names begin with a capital letter
         // check if user name is an existing user
         if (User::isValidUserName($userName)) {
             // BugId:CE-11
             // If the user account has just been enabled with Special:EditAccount
             // and the 'wikicities_c1' database (local for Community Central)
             // has lagged compared to the 'wikicities' database (the shared one)
             // the next action done with Special:EditAccount will fail and the
             // correct user data will be replaced by the temp user cache.
             // In other words: LOST.
             //
             // In order to prevent that we have to do the following two steps:
             //
             // 1) REMOVED: invalidate temp user cache
             //
             // 2) and copy the data from the shared to the local database
             $oUser = User::newFromName($userName);
             wfRunHooks('UserNameLoadFromId', array($userName, &$oUser, true));
             $id = 0;
             $this->mUser = $oUser;
             if (!empty($this->mUser)) {
                 $id = $this->mUser->getId();
             }
             if (empty($action)) {
                 $action = 'displayuser';
             }
             if (empty($id)) {
                 $this->mUser = null;
                 $this->mStatus = false;
                 $this->mStatusMsg = wfMsg('editaccount-nouser', $userName);
             }
         }
     }
     // FB:23860
     if (!$this->mUser instanceof User) {
         $action = '';
     }
     // CSRF protection for EditAccount (CE-774)
     if ($action !== '' && $action !== 'displayuser' && $action !== 'closeaccount' && (!$request->wasPosted() || !$user->matchEditToken($request->getVal('wpToken')))) {
         $output->addHTML(Xml::element('p', ['class' => 'error'], $this->msg('sessionfailure')->text()));
         return;
     }
     $changeReason = $request->getVal('wpReason');
     switch ($action) {
         case 'setemail':
             $newEmail = $request->getVal('wpNewEmail');
             $this->mStatus = $this->setEmail($newEmail, $changeReason);
             $template = 'displayuser';
             break;
         case 'setpass':
             $newPass = $request->getVal('wpNewPass');
             $this->mStatus = $this->setPassword($newPass, $changeReason);
             $template = 'displayuser';
             break;
         case 'setrealname':
             $newRealName = $request->getVal('wpNewRealName');
             $this->mStatus = $this->setRealName($newRealName, $changeReason);
             $template = 'displayuser';
             break;
         case 'closeaccount':
             $template = 'closeaccount';
             $this->mStatus = (bool) $this->mUser->getGlobalFlag('requested-closure', 0);
             $this->mStatusMsg = $this->mStatus ? wfMsg('editaccount-requested') : wfMsg('editaccount-not-requested');
             break;
         case 'closeaccountconfirm':
             $keepEmail = !$request->getBool('clearemail', false);
             $this->mStatus = self::closeAccount($this->mUser, $changeReason, $this->mStatusMsg, $this->mStatusMsg2, $keepEmail);
             $template = $this->mStatus ? 'selectuser' : 'displayuser';
             break;
         case 'clearunsub':
             $this->mStatus = $this->clearUnsubscribe();
             $template = 'displayuser';
             break;
         case 'cleardisable':
             $this->mStatus = $this->clearDisable();
             $template = 'displayuser';
             break;
         case 'clearclosurerequest':
             $this->mStatus = $this->clearClosureRequest();
             $template = 'displayuser';
             break;
         case 'toggleadopter':
             $this->mStatus = $this->toggleAdopterStatus();
             $template = 'displayuser';
             break;
         case 'displayuser':
             $template = 'displayuser';
             break;
         default:
             $template = 'selectuser';
     }
     $output->setPageTitle($this->msg('editaccount-title')->plain());
     $oTmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
     $oTmpl->set_Vars(array('status' => $this->mStatus, 'statusMsg' => $this->mStatusMsg, 'statusMsg2' => $this->mStatusMsg2, 'user' => $userName, 'userEmail' => null, 'userRealName' => null, 'userEncoded' => urlencode($userName), 'user_hsc' => htmlspecialchars($userName), 'userId' => null, 'userReg' => null, 'isUnsub' => null, 'isDisabled' => null, 'isAdopter' => null, 'returnURL' => $this->getTitle()->getFullURL(), 'logLink' => Linker::linkKnown(SpecialPage::getTitleFor('Log', 'editaccnt'), $this->msg('editaccount-log')->escaped()), 'userStatus' => null, 'emailStatus' => null, 'disabled' => null, 'changeEmailRequested' => null, 'editToken' => $user->getEditToken()));
     if (is_object($this->mUser)) {
         $userStatus = wfMsg('editaccount-status-realuser');
         $this->mUser->load();
         // get new email (unconfirmed)
         $optionNewEmail = $this->mUser->getGlobalAttribute('new_email');
         $changeEmailRequested = empty($optionNewEmail) ? '' : wfMsg('editaccount-email-change-requested', $optionNewEmail);
         // emailStatus is the status of the email in the "Set new email address" field
         $emailStatus = $this->mUser->isEmailConfirmed() ? wfMsg('editaccount-status-confirmed') : wfMsg('editaccount-status-unconfirmed');
         $oTmpl->set_Vars(array('userEmail' => $this->mUser->getEmail(), 'userRealName' => $this->mUser->getRealName(), 'userId' => $this->mUser->getID(), 'userReg' => date('r', strtotime($this->mUser->getRegistration())), 'isUnsub' => $this->mUser->getGlobalPreference('unsubscribed'), 'isDisabled' => $this->mUser->getGlobalFlag('disabled'), 'isClosureRequested' => $this->isClosureRequested(), 'isAdopter' => $this->mUser->getGlobalFlag('AllowAdoption', 1), 'userStatus' => $userStatus, 'emailStatus' => $emailStatus, 'changeEmailRequested' => $changeEmailRequested));
     }
     // HTML output
     $output->addHTML($oTmpl->render($template));
 }
 /**
  * Show the special page
  *
  * @param $par Mixed: parameter passed to the page or null
  */
 public function execute($par)
 {
     global $wgOut, $wgUser, $wgRequest, $wgEnableUserLoginExt;
     // Set page title and other stuff
     $this->setHeaders();
     # If the user isn't permitted to access this special page, display an error
     if (!$wgUser->isAllowed('editaccount')) {
         throw new PermissionsError('editaccount');
     }
     # Show a message if the database is in read-only mode
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     # If user is blocked, s/he doesn't need to access this page
     if ($wgUser->isBlocked()) {
         throw new UserBlockedError($this->getUser()->mBlock);
     }
     $action = $wgRequest->getVal('wpAction');
     #get name to work on. subpage is supported, but form submit name trumps
     $userName = $wgRequest->getVal('wpUserName', $par);
     if ($userName !== null) {
         #got a name, clean it up
         $userName = str_replace("_", " ", trim($userName));
         $userName = ucfirst($userName);
         # user names begin with a capital letter
         // check if user name is an existing user
         if (User::isValidUserName($userName)) {
             $this->mUser = User::newFromName($userName);
             $id = $this->mUser->idFromName($userName);
             if (empty($action)) {
                 $action = 'displayuser';
             }
             if (empty($id)) {
                 if (!empty($wgEnableUserLoginExt)) {
                     $this->mTempUser = TempUser::getTempUserFromName($userName);
                 }
                 if ($this->mTempUser) {
                     $id = $this->mTempUser->getId();
                     $this->mUser = User::newFromId($id);
                 } else {
                     $this->mStatus = false;
                     $this->mStatusMsg = wfMsg('editaccount-nouser', $userName);
                     $action = '';
                 }
             }
         }
     }
     // FB:23860
     if (!$this->mUser instanceof User) {
         $action = '';
     }
     switch ($action) {
         case 'setemail':
             $newEmail = $wgRequest->getVal('wpNewEmail');
             $this->mStatus = $this->setEmail($newEmail);
             $template = 'displayuser';
             break;
         case 'setpass':
             $newPass = $wgRequest->getVal('wpNewPass');
             $this->mStatus = $this->setPassword($newPass);
             $template = 'displayuser';
             break;
         case 'setrealname':
             $newRealName = $wgRequest->getVal('wpNewRealName');
             $this->mStatus = $this->setRealName($newRealName);
             $template = 'displayuser';
             break;
         case 'closeaccount':
             $template = 'closeaccount';
             $this->mStatus = (bool) $this->mUser->getOption('requested-closure', 0);
             $this->mStatusMsg = $this->mStatus ? wfMsg('editaccount-requested') : wfMsg('editaccount-not-requested');
             break;
         case 'closeaccountconfirm':
             $this->mStatus = $this->closeAccount();
             $template = $this->mStatus ? 'selectuser' : 'displayuser';
             break;
         case 'clearunsub':
             $this->mStatus = $this->clearUnsubscribe();
             $template = 'displayuser';
             break;
         case 'cleardisable':
             $this->mStatus = $this->clearDisable();
             $template = 'displayuser';
             break;
         case 'toggleadopter':
             $this->mStatus = $this->toggleAdopterStatus();
             $template = 'displayuser';
             break;
         case 'displayuser':
             $template = 'displayuser';
             break;
         default:
             $template = 'selectuser';
     }
     $wgOut->setPageTitle(wfMsg('editaccount-title'));
     $oTmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
     $oTmpl->set_Vars(array('status' => $this->mStatus, 'statusMsg' => $this->mStatusMsg, 'statusMsg2' => $this->mStatusMsg2, 'user' => $userName, 'userEmail' => null, 'userRealName' => null, 'userEncoded' => urlencode($userName), 'user_hsc' => htmlspecialchars($userName), 'userId' => null, 'userReg' => null, 'isUnsub' => null, 'isDisabled' => null, 'isAdopter' => null, 'returnURL' => $this->getTitle()->getFullURL(), 'userStatus' => null, 'emailStatus' => null, 'disabled' => null, 'changeEmailRequested' => null));
     if (is_object($this->mUser)) {
         if ($this->mTempUser) {
             $this->mUser = $this->mTempUser->mapTempUserToUser(false);
             $userStatus = wfMsg('editaccount-status-tempuser');
             $oTmpl->set_Vars(array('disabled' => 'disabled="disabled"'));
         } else {
             $userStatus = wfMsg('editaccount-status-realuser');
         }
         $this->mUser->load();
         // get new email (unconfirmed)
         $optionNewEmail = $this->mUser->getOption('new_email');
         $changeEmailRequested = empty($optionNewEmail) ? '' : wfMsg('editaccount-email-change-requested', $optionNewEmail);
         // emailStatus is the status of the email in the "Set new email address" field
         $emailStatus = $this->mUser->isEmailConfirmed() ? wfMsg('editaccount-status-confirmed') : wfMsg('editaccount-status-unconfirmed');
         $oTmpl->set_Vars(array('userEmail' => $this->mUser->getEmail(), 'userRealName' => $this->mUser->getRealName(), 'userId' => $this->mUser->getID(), 'userReg' => date('r', strtotime($this->mUser->getRegistration())), 'isUnsub' => $this->mUser->getOption('unsubscribed'), 'isDisabled' => $this->mUser->getOption('disabled'), 'isAdopter' => $this->mUser->getOption('AllowAdoption', 1), 'userStatus' => $userStatus, 'emailStatus' => $emailStatus, 'changeEmailRequested' => $changeEmailRequested));
     }
     // HTML output
     $wgOut->addHTML($oTmpl->render($template));
 }