/** * There's a race condition of some kind in cache purging (T94491), * so see if the cache still thinks they're being renamed and purge * it if it's wrong * * @param string $name */ function checkCachePurge($name) { $ca = new CentralAuthUser($name); if ($ca->renameInProgress()) { $ca->quickInvalidateCache(); } }
/** * @param $name * @return string|bool */ public function validateUsername($name) { if ($name === null || $name === '') { // blank cloner field, bypass. return true; } $name = User::getCanonicalName($name, 'usable'); if (!$name) { return $this->msg('centralauth-usermerge-invalid', $name)->escaped(); } if ($name === $this->getUser()->getName()) { return $this->msg('centralauth-usermerge-noself')->escaped(); } $caUser = new CentralAuthUser($name); if (!$caUser->exists()) { return $this->msg('centralauth-usermerge-invalid', $name)->escaped(); } if ($caUser->renameInProgress()) { return $this->msg('centralauth-usermerge-already', $name)->escaped(); } return true; }
public function execute($subpage) { global $wgContLang; $this->setHeaders(); $this->mCanUnmerge = $this->getUser()->isAllowed('centralauth-unmerge'); $this->mCanLock = $this->getUser()->isAllowed('centralauth-lock'); $this->mCanOversight = $this->getUser()->isAllowed('centralauth-oversight'); $this->mCanEdit = $this->mCanUnmerge || $this->mCanLock || $this->mCanOversight; $this->getOutput()->setPageTitle($this->msg($this->mCanEdit ? 'centralauth' : 'centralauth-ro')); $this->getOutput()->addModules('ext.centralauth'); $this->getOutput()->addModules('ext.centralauth.globaluserautocomplete'); $this->getOutput()->addModuleStyles('ext.centralauth.noflash'); $this->getOutput()->addJsConfigVars('wgMergeMethodDescriptions', $this->getMergeMethodDescriptions()); $this->mUserName = trim(str_replace('_', ' ', $this->getRequest()->getText('target', $subpage))); $this->mUserName = $wgContLang->ucfirst($this->mUserName); $this->mPosted = $this->getRequest()->wasPosted(); $this->mMethod = $this->getRequest()->getVal('wpMethod'); $this->mWikis = (array) $this->getRequest()->getArray('wpWikis'); // Possible demo states // success, all accounts merged // successful login, some accounts merged, others left // successful login, others left // not account owner, others left // is owner / is not owner // did / did not merge some accounts // do / don't have more accounts to merge if ($this->mUserName === '') { # First time through $this->getOutput()->addWikiMsg('centralauth-admin-intro'); $this->showUsernameForm(); return; } // per bug 47991 $this->getOutput()->setHTMLTitle($this->msg('pagetitle', $this->msg($this->mCanEdit ? 'centralauth-admin-title' : 'centralauth-admin-title-ro', $this->mUserName)->plain())); $this->mGlobalUser = $globalUser = new CentralAuthUser($this->mUserName); if (($globalUser->isOversighted() || $globalUser->isHidden()) && !$this->mCanOversight) { // Claim that there's nothing if the global account is hidden and the user is not // allowed to see it. $this->showNonexistentError(); return; } $continue = true; if ($this->mCanEdit && $this->mPosted) { $continue = $this->doSubmit(); } // Show just a user friendly message when a rename is in progress try { $this->mAttachedLocalAccounts = $globalUser->queryAttached(); } catch (Exception $e) { if ($globalUser->renameInProgress()) { $this->showRenameInProgressError(); return; } // Rethrow throw $e; } $this->mUnattachedLocalAccounts = $globalUser->queryUnattached(); if (!$globalUser->exists() && !count($this->mUnattachedLocalAccounts)) { // Nothing to see here $this->showNonexistentError(); return; } $this->showUsernameForm(); if ($continue && $globalUser->exists()) { $this->showInfo(); if ($this->mCanLock) { $this->showStatusForm(); } if ($this->mCanUnmerge) { $this->showActionForm('delete'); } $this->showLogExtract(); $this->showWikiLists(); } elseif ($continue && !$globalUser->exists()) { // No global account, but we can still list the local ones $this->showError('centralauth-admin-nonexistent', $this->mUserName); $this->showWikiLists(); } }
/** * Warn bureaucrat about possible conflicts with unified accounts * @param $oldName * @param $newName * @param $warnings * @return bool */ static function onRenameUserWarning($oldName, $newName, &$warnings) { $oldCentral = new CentralAuthUser($oldName); if ($oldCentral->exists() && $oldCentral->isAttached()) { $warnings[] = array('centralauth-renameuser-merged', $oldName, $newName); } if ($oldCentral->renameInProgress()) { $warnings[] = array('centralauth-renameuser-global-inprogress', $oldName); } $newCentral = new CentralAuthUser($newName); if ($newCentral->exists() && !$newCentral->isAttached()) { $warnings[] = array('centralauth-renameuser-reserved', $oldName, $newName); } if ($newCentral->renameInProgress()) { $warnings[] = array('centralauth-renameuser-global-inprogress', $newName); // Can potentially be renaming two accounts into the same name, so throw an error throw new ErrorPageError('error', 'centralauth-renameuser-global-inprogress', array($newName)); } return true; }
/** * Check to see if a given username is available for use via CentralAuth. * * Note that this is not a definiative check. It does not include checking * for AntiSpoof, TitleBlacklist or other AbortNewAccount hook blocks. * Unfortunately the only cannonical way to validate that an account is * available is to make the account and check that it wasn't blocked by * something. * * @param string $name * @return Status Canonicalized name */ public static function isNameAvailable($name) { $safe = User::getCanonicalName($name, 'creatable'); $status = Status::newGood($safe); if ($safe === false || $safe === '') { $status->fatal('globalrenamerequest-newname-err-invalid'); return $status; } if (self::nameHasPendingRequest($safe)) { $status->fatal('globalrenamerequest-newname-err-taken'); return $status; } // New user creation checks against local wiki only using an API // request, but we need to check against te central user table instead $centralUser = new CentralAuthUser($safe); if ($centralUser->exists() || $centralUser->listUnattached()) { $status->fatal('globalrenamerequest-newname-err-taken'); return $status; } // Check to see if there is an active rename to the desired name. $progress = $centralUser->renameInProgress(); if ($progress && $safe == $progress[1]) { $status->fatal('globalrenamerequest-newname-err-taken'); return $status; } return $status; }