public function execute() { $userName = '******'; // <- targer username $user = new CentralAuthUser( $userName ); if ( !$user->exists() ) { echo "Cannot unsuppress non-existent user {$userName}!\n"; exit( 0 ); } $userName = $user->getName(); // sanity $wikis = $user->listAttached(); // wikis with attached accounts foreach ( $wikis as $wiki ) { $lb = wfGetLB( $wiki ); $dbw = $lb->getConnection( DB_MASTER, array(), $wiki ); # Get local ID like $user->localUserData( $wiki ) does $localUserId = $dbw->selectField( 'user', 'user_id', array( 'user_name' => $userName ), __METHOD__ ); $delUserBit = Revision::DELETED_USER; $hiddenCount = $dbw->selectField( 'revision', 'COUNT(*)', array( 'rev_user' => $localUserId, "rev_deleted & $delUserBit != 0" ), __METHOD__ ); echo "$hiddenCount edits have the username hidden on \"$wiki\"\n"; # Unsuppress username on edits if ( $hiddenCount > 0 ) { echo "Unsuppressed edits of attached account (local id $localUserId) on \"$wiki\"..."; IPBlockForm::unsuppressUserName( $userName, $localUserId, $dbw ); echo "done!\n\n"; } $lb->reuseConnection( $dbw ); // not really needed # Don't lag too bad wfWaitForSlaves( 5 ); } }
/** * Rename a global user (this assumes that the data has been verified before * and that $newUser is being a creatable user)! * * @param $options array * @return Status */ public function rename(array $options) { $wikis = $this->oldCAUser->listAttached(); $status = $this->setRenameStatuses($wikis); if (!$status->isOK()) { return $status; } $this->databaseUpdates->update($this->oldUser->getName(), $this->newUser->getName()); // Update CA's AntiSpoof if enabled if (class_exists('CentralAuthSpoofUser')) { $spoof = new CentralAuthSpoofUser($this->newUser->getName()); $spoof->update($this->oldUser->getName()); } // From this point on all code using CentralAuthUser // needs to use the new username, except for // the renameInProgress function. Probably. // Clear some caches... $this->oldCAUser->quickInvalidateCache(); $this->newCAUser->quickInvalidateCache(); $this->injectLocalRenameUserJobs($wikis, $options); $this->logger->log($this->oldUser->getName(), $this->newUser->getName(), $options['reason']); return Status::newGood(); }
/** * @param CentralAuthUser $globalUser * @return string */ private function getUserTableRow(CentralAuthUser $globalUser) { $rowHtml = ''; // @TODO: Don't use methods from the special page directly, // rather move them somewhere sane $sca = new SpecialCentralAuth(); $sca->setContext($this->getContext()); $guName = $globalUser->getName(); $guLink = Linker::link(SpecialPage::getTitleFor('CentralAuth', $guName), htmlspecialchars($guName)); $guHidden = $sca->formatHiddenLevel($globalUser->getHiddenLevel()); $accountAge = time() - wfTimestamp(TS_UNIX, $globalUser->getRegistration()); $guRegister = $sca->prettyTimespan($accountAge); $guLocked = $this->msg('centralauth-admin-status-locked-no')->escaped(); if ($globalUser->isLocked()) { $guLocked = $this->msg('centralauth-admin-status-locked-yes')->escaped(); } $guEditCount = htmlspecialchars($this->getLanguage()->formatNum($globalUser->getGlobalEditCount())); $guAttachedLocalAccounts = htmlspecialchars($this->getLanguage()->formatNum(count($globalUser->listAttached()))); $rowHtml .= Html::rawElement('td', array(), Html::input('wpActionTarget[' . $guName . ']', $guName, 'checkbox', array('checked' => 'checked'))); $rowHtml .= Html::rawElement('td', array(), $guLink); $rowHtml .= Html::element('td', array('data-sort-value' => $accountAge), $guRegister); $rowHtml .= Html::element('td', array(), $guLocked); $rowHtml .= Html::element('td', array(), $guHidden); $rowHtml .= Html::element('td', array(), $guEditCount); $rowHtml .= Html::element('td', array(), $guAttachedLocalAccounts); return $rowHtml; }
function onSuccess() { $lang = $this->getLanguage(); $caUser = new CentralAuthUser($this->newUsername); $wikiList = $lang->commaList($caUser->listAttached()); $msg = $this->msg('centralauth-rename-queued')->params($this->oldUsername, $this->newUsername, $wikiList)->parse(); $this->getOutput()->addHTML($msg); }
function showAttachForm() { $globalUser = new CentralAuthUser($this->getUser()->getName()); $merged = $globalUser->listAttached(); $this->getOutput()->addWikiMsg('centralauth-attach-list-attached', $this->mUserName); $this->getOutput()->addHTML($this->listAttached($merged)); $this->getOutput()->addHTML($this->attachActionForm()); }
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; }
/** * Creates a link to the global lock log * @param array $msg Message with a link to the global block log * @param string $user The username to be checked * @return boolean true */ static function getBlockLogLink(&$msg, $user) { if (IP::isIPAddress($user)) { return true; // Return if it is an IP as only usernames can be locked. } $caUser = new CentralAuthUser($user); if ($caUser->isLocked() && in_array(wfWikiID(), $caUser->listAttached())) { $msg[] = Html::rawElement('span', array('class' => 'mw-centralauth-lock-loglink plainlinks'), wfMessage('centralauth-block-already-locked', $user)->parse()); } return true; }
/** * @covers CentralAuthUser::attach */ public function testAttach() { $caUser = new CentralAuthUser('GlobalUser'); $caUser->attach('anotherwiki', 'admin', false); $this->assertSame(true, $caUser->exists()); $this->assertSame(true, in_array('anotherwiki', $caUser->listAttached())); }