function onSubmit(array $data)
 {
     if (!isset($data['username'])) {
         $this->showCurrentRenames();
         return false;
     }
     $name = User::getCanonicalName($data['username'], 'usable');
     if (!$name) {
         $this->showCurrentRenames();
         return false;
     }
     $out = $this->getOutput();
     $this->renameuserStatus = new GlobalRenameUserStatus($name);
     $names = $this->renameuserStatus->getNames();
     if (!$names) {
         $this->checkCachePurge($name);
         $out->addWikiMsg('centralauth-rename-notinprogress', $name);
         $this->getForm()->displayForm(false);
         $this->showLogExtract($name);
         return true;
     }
     list($oldName, $newName) = $names;
     $statuses = $this->renameuserStatus->getStatuses();
     $this->getForm()->displayForm(false);
     // $newname will always be defined since we check
     // for 0 result rows above
     $caUser = new CentralAuthUser($newName);
     $attached = $caUser->listAttached();
     foreach ($attached as $wiki) {
         // If it's not in the db table, and there is
         // an attached acount, assume it's done.
         if (!isset($statuses[$wiki])) {
             $statuses[$wiki] = 'done';
         }
     }
     ksort($statuses);
     $table = Html::openElement('table', array('class' => 'wikitable sortable'));
     $table .= Html::openElement('tr');
     $table .= Html::element('th', array(), $this->msg('centralauth-rename-table-domain')->text());
     $table .= Html::element('th', array(), $this->msg('centralauth-rename-table-status')->text());
     $table .= Html::closeElement('tr');
     foreach ($statuses as $wiki => $status) {
         $table .= Html::openElement('tr');
         $table .= Html::element('td', array(), WikiMap::getWiki($wiki)->getDisplayName());
         // Messages used: centralauth-rename-table-status-inprogress
         // centralauth-rename-table-status-queued, centralauth-rename-table-status-done
         $table .= Html::rawElement('td', array(), $this->msg("centralauth-rename-table-status-{$status}")->parse());
         $table .= Html::closeElement('tr');
     }
     $table .= Html::closeElement('table');
     $fieldset = Xml::fieldset($this->msg('centralauth-rename-progress-fieldset')->text(), $table);
     $this->showLogExtract($newName);
     $out->addHTML($fieldset);
     return true;
 }
 /**
  * @param array $wikis
  *
  * @return Status
  */
 private function setRenameStatuses(array $wikis)
 {
     $rows = array();
     foreach ($wikis as $wiki) {
         // @TODO: This shouldn't know about these column names
         $rows[] = array('ru_wiki' => $wiki, 'ru_oldname' => $this->oldUser->getName(), 'ru_newname' => $this->newUser->getName(), 'ru_status' => 'queued');
     }
     $success = $this->renameuserStatus->setStatuses($rows);
     if (!$success) {
         // Race condition: Another admin already started the rename!
         return Status::newFatal('centralauth-rename-alreadyinprogress', $this->newUser->getName());
     }
     return Status::newGood();
 }
 protected function rename($row, DatabaseBase $dbw)
 {
     $wiki = $row->utr_wiki;
     $name = $row->utr_name;
     $newNamePrefix = User::getCanonicalName($name . '~' . str_replace('_', '-', $wiki), 'usable');
     if (!$newNamePrefix) {
         $this->log("ERROR: New name '{$name}~{$wiki}' is not valid");
         return;
     }
     $this->log("Beginning rename of {$newNamePrefix}");
     $newCAUser = new CentralAuthUser($newNamePrefix);
     $count = 0;
     // Edge case: Someone created User:Foo~wiki manually.
     // So just start appending numbers to the end of the name
     // until we get one that isn't used.
     while ($newCAUser->exists()) {
         $count++;
         $newCAUser = new CentralAuthUser($newNamePrefix . (string) $count);
     }
     if ($newNamePrefix !== $newCAUser->getName()) {
         $this->log("WARNING: New name is now {$newCAUser->getName()}");
     }
     $this->log("Renaming {$name} to {$newCAUser->getName()}.");
     $statuses = new GlobalRenameUserStatus($name);
     $success = $statuses->setStatuses(array(array('ru_wiki' => $wiki, 'ru_oldname' => $name, 'ru_newname' => $newCAUser->getName(), 'ru_status' => 'queued')));
     if (!$success) {
         $this->log("WARNING: Race condition, renameuser_status already set for {$newCAUser->getName()}. Skipping.");
         return;
     }
     $this->log("Set renameuser_status for {$newCAUser->getName()}.");
     $job = new LocalRenameUserJob(Title::newFromText('Global rename job'), array('from' => $name, 'to' => $newCAUser->getName(), 'renamer' => 'Maintenance script', 'movepages' => true, 'suppressredirects' => true, 'promotetoglobal' => true, 'reason' => $this->getOption('reason')));
     JobQueueGroup::singleton($row->utr_wiki)->push($job);
     $this->log("Submitted job for {$newCAUser->getName()}.");
     $updates = new UsersToRenameDatabaseUpdates($dbw);
     $updates->markRenamed($row->utr_name, $row->utr_wiki);
 }
 private function showRenameInProgressError()
 {
     $this->showError('centralauth-admin-rename-in-progress', $this->mUserName);
     $special = new SpecialGlobalRenameProgress();
     $special->setContext($this->getContext());
     $renameStatus = new GlobalRenameUserStatus($this->mUserName);
     $names = $renameStatus->getNames();
     $special->showLogExtract($names[1]);
 }
 /**
  * Same as $this->renameInProgress, but only checks one wiki
  * Not cached
  * @see CentralAuthUser::renameInProgress
  * @param string $wiki
  * @return array|bool
  */
 public function renameInProgressOn($wiki)
 {
     $renameState = new GlobalRenameUserStatus($this->mName);
     // Use master as this is being used for various critical things
     $names = $renameState->getNames($wiki, 'master');
     if ($names) {
         return $names;
     } else {
         return false;
     }
 }
 protected function updateStatus($status)
 {
     $this->renameuserStatus->setStatus(wfWikiID(), $status);
 }