public function execute() { if (!$this->getOption('nowarn')) { $this->output("The script is about to reset the user_token for ALL USERS in the database.\n"); $this->output("This may log some of them out and is not necessary unless you believe your\n"); $this->output("user table has been compromised.\n"); $this->output("\n"); $this->output("Abort with control-c in the next five seconds (skip this countdown with --nowarn) ... "); wfCountDown(5); } // We list user by user_id from one of the slave database $dbr = CentralAuthUser::getCentralDB(DB_SLAVE); $maxid = $this->getOption('maxid', -1); if ($maxid == -1) { $maxid = $dbr->selectField('globaluser', 'MAX(gu_id)', array(), __METHOD__); } $min = $this->getOption('minid', 0); $max = $min + $this->mBatchSize; do { $result = $dbr->select('globaluser', array('gu_id', 'gu_name'), array('gu_id > ' . $dbr->addQuotes($min), 'gu_id <= ' . $dbr->addQuotes($max)), __METHOD__); foreach ($result as $user) { $this->updateUser($user->gu_name); } $min = $max; $max = $min + $this->mBatchSize; if ($max > $maxid) { $max = $maxid; } CentralAuthUser::waitForSlaves(); } while ($min < $maxid); }
/** * Get a DatabaseBase object for the CentralAuth db * * @param int $type DB_SLAVE or DB_MASTER * * @return DatabaseBase */ protected function getDB($type = DB_SLAVE) { if ($type === DB_MASTER) { return CentralAuthUser::getCentralDB(); } else { return CentralAuthUser::getCentralSlaveDB(); } }
public function execute() { $centralMaster = CentralAuthUser::getCentralDB(); $centralSlave = CentralAuthUser::getCentralSlaveDB(); if ($this->getOption('delete', false) === true) { $this->dryrun = false; } $wiki = $this->getOption('wiki', false); if ($wiki !== false) { $this->wiki = $wiki; } if ($this->getOption('verbose', false) !== false) { $this->verbose = true; } // since the keys on localnames are not conducive to batch operations and // because of the database shards, grab a list of the wikis and we will // iterate from there $wikis = array(); if (!is_null($this->wiki)) { $wikis[] = $this->wiki; } else { $result = $centralSlave->select('localnames', array('ln_wiki'), "", __METHOD__, array("DISTINCT", "ORDER BY" => "ln_wiki ASC")); foreach ($result as $row) { $wikis[] = $row->ln_wiki; } } // iterate through the wikis foreach ($wikis as $wiki) { $localdb = wfGetDB(DB_SLAVE, array(), $wiki); $lastUsername = ""; $this->output("Checking localnames for {$wiki} ...\n"); // batch query localnames from the wiki do { $this->output("\t ... querying from '{$lastUsername}'\n"); $result = $centralSlave->select('localnames', array('ln_name'), array("ln_wiki" => $wiki, "ln_name > " . $centralSlave->addQuotes($lastUsername)), __METHOD__, array("LIMIT" => $this->batchSize, "ORDER BY" => "ln_name ASC")); // iterate through each of the localnames to confirm that a local user foreach ($result as $u) { $localUser = $localdb->select('user', array('user_name'), array("user_name" => $u->ln_name), __METHOD__); // check to see if the user did not exist in the local user table if ($localUser->numRows() == 0) { if ($this->verbose) { $this->output("Local user not found for localname entry {$u->ln_name}@{$wiki}\n"); } $this->total++; if (!$this->dryrun) { // go ahead and delete the extraneous entry $deleted = $centralMaster->delete('localnames', array("ln_wiki" => $wiki, "ln_name" => $u->ln_name), __METHOD__); // TODO: is there anyway to check the success of the delete? $this->deleted++; } } $lastUsername = $u->ln_name; } } while ($result->numRows() > 0); } $this->report(); $this->output("done.\n"); }
public function execute() { $dbw = CentralAuthUser::getCentralDB(); $databaseUpdates = new UsersToRenameDatabaseUpdates($dbw); // CentralAuthUser::chooseHomeWiki is expensive and called // multiple times, so lets cache it. $cache = new MapCacheLRU($this->mBatchSize); do { $rows = $this->doQuery(); $insertRows = array(); foreach ($rows as $row) { $this->lName = $row->name; $this->lWiki = $row->wiki; if ($cache->has($row->name)) { $attachableWikis = $cache->get($row->name); } else { $ca = new CentralAuthUser($row->name); $attachableWikis = array(); $unattached = $ca->queryUnattached(); if ($ca->exists()) { $home = $ca->getHomeWiki(); $attachableWikis[] = $home; foreach ($unattached as $wiki => $info) { if ($ca->getEmailAuthenticationTimestamp() && $info['email'] === $ca->getEmail() && !is_null($info['emailAuthenticated'])) { $attachableWikis[] = $wiki; } } } else { $home = $ca->chooseHomeWiki($unattached); $attachableWikis[] = $home; if ($unattached[$home]['email'] && isset($unattached[$home]['emailAuthenticated'])) { foreach ($unattached as $wiki => $info) { if ($wiki !== $home && $unattached[$home]['email'] === $info['email'] && isset($info['emailAuthenticated'])) { $attachableWikis[] = $wiki; } } } } $cache->set($row->name, $attachableWikis); } if (!in_array($row->wiki, $attachableWikis)) { // Unattached account which is not attachable, // so they're getting renamed :( $this->output("{$row->name}@{$row->wiki} is going to be renamed.\n"); $insertRows[] = (array) $row; } } $databaseUpdates->batchInsert($insertRows); $count = $dbw->affectedRows(); $this->output("Inserted {$count} users who we will rename\n"); $this->output("Waiting for slaves...\n"); CentralAuthUser::waitForSlaves(); } while ($count !== 0); }
function execute() { $wikis = file('/srv/mediawiki/dblist/deleted.dblist'); if ($wikis === false) { $this->error('Unable to open deleted.dblist', 1); } $dbw = $this->getDB(DB_MASTER); $cadbw = CentralAuthUser::getCentralDB(); foreach ($wikis as $wiki) { $wiki = rtrim($wiki); $this->output("{$wiki}:\n"); $this->doDeletes($cadbw, 'localnames', 'ln_wiki', $wiki); $this->doDeletes($cadbw, 'localuser', 'lu_wiki', $wiki); // @todo: Delete from wikisets } $this->output("Done.\n"); }
public function execute() { $dbw = CentralAuthUser::getCentralDB(); $dbr = CentralAuthUser::getCentralSlaveDB(); $total = 0; do { $rows = $dbr->select(array('users_to_rename', 'localuser'), array('utr_id', 'utr_name', 'utr_wiki'), array(), __METHOD__, array('LIMIT' => $this->mBatchSize), array('localuser' => array('INNER JOIN', 'utr_wiki=lu_wiki AND utr_name=lu_name'))); $ids = array(); foreach ($rows as $row) { $ids[] = $row->utr_id; $this->output("{$row->utr_name}@{$row->utr_wiki} is now attached!\n"); } if ($ids) { $count = count($ids); $this->output("Deleting {$count} users...\n"); $dbw->delete('users_to_rename', array('utr_id' => $ids), __METHOD__); $total += $count; } CentralAuthUser::waitForSlaves(); } while ($rows->numRows() >= $this->mBatchSize); $this->output("Removed {$total} users in total.\n"); }
public function execute() { if (!class_exists('CentralAuthUser')) { $this->error('CentralAuth is not installed on this wiki.', 1); } $dbw = CentralAuthUser::getCentralDB(); while (true) { $rowsToRename = $this->findUsers(wfWikiID(), $dbw); if (!$rowsToRename) { break; } foreach ($rowsToRename as $row) { $this->rename($row, $dbw); } CentralAuthUser::waitForSlaves(); $count = $this->getCurrentRenameCount($dbw); while ($count > 50) { $this->output("There are currently {$count} renames queued, pausing...\n"); sleep(5); $count = $this->getCurrentRenameCount($dbw); } } }
<?php $IP = getenv('MW_INSTALL_PATH'); if ($IP === false) { $IP = dirname(__FILE__) . '/../../..'; } require_once "{$IP}/maintenance/commandLine.inc"; echo "Populating global groups table with stewards...\n"; // Fetch local stewards $dbl = wfGetDB(DB_SLAVE); // Get local database $result = $dbl->select(array('user', 'user_groups'), array('user_name'), array('ug_group' => 'steward', 'user_id = ug_user'), 'migrateStewards.php'); $localStewards = array(); foreach ($result as $row) { $localStewards[] = $row->user_name; } echo "Fetched " . count($localStewards) . " from local database... Checking for attached ones\n"; $dbg = CentralAuthUser::getCentralDB(); $globalStewards = array(); $result = $dbg->select(array('globaluser', 'localuser'), array('gu_name', 'gu_id'), array('gu_name = lu_name', 'lu_wiki' => wfWikiId(), 'gu_name IN (' . $dbg->makeList($localStewards) . ')'), 'migrateStewards.php'); foreach ($result as $row) { $globalStewards[$row->gu_name] = $row->gu_id; } echo "Fetched " . count($localStewards) . " SULed stewards... Adding them in group\n"; foreach ($globalStewards as $user => $id) { $dbg->insert('global_user_groups', array('gug_user' => $id, 'gug_group' => 'steward'), 'migrateStewards.php'); echo "Added {$user}\n"; $u = new CentralAuthUser($user); $u->quickInvalidateCache(); // Don't bother regenerating the steward's cache. }
/** * @param $group string */ function invalidateRightsCache($group) { // Figure out all the users in this group. // Use the master over here as this could go horribly wrong with newly created or just renamed groups $dbr = CentralAuthUser::getCentralDB(); $res = $dbr->select(array('global_user_groups', 'globaluser'), 'gu_name', array('gug_group' => $group, 'gu_id=gug_user'), __METHOD__); // Invalidate their rights cache. foreach ($res as $row) { $cu = new CentralAuthUser($row->gu_name); $cu->quickInvalidateCache(); } }
/** * @return DatabaseBase */ protected function getDBMaster() { return CentralAuthUser::getCentralDB(); }
/** * @return DatabaseBase */ protected function getDB() { CentralAuthUser::getCentralDB(); }
/** * @param $group */ function invalidateRightsCache($group) { // Figure out all the users in this group. $dbr = CentralAuthUser::getCentralDB(); $res = $dbr->select(array('global_user_groups', 'globaluser'), 'gu_name', array('gug_group' => $group, 'gu_id=gug_user'), __METHOD__); // Invalidate their rights cache. foreach ($res as $row) { $cu = new CentralAuthUser($row->gu_name); $cu->quickInvalidateCache(); } }
/** * @return bool */ public function delete() { $dbw = CentralAuthUser::getCentralDB(); $dbw->delete('wikiset', array('ws_id' => $this->mId), __METHOD__); $dbw->commit(); $this->purge(); return (bool) $dbw->affectedRows(); }
public function execute() { if (!class_exists('MassMessageServerSideJob')) { $this->error('This script requires the MassMessage extension', 1); } $message = $this->getLocalizedText($this->getOption('message')); $message = str_replace('{{WIKI}}', wfWikiID(), $message); $message .= " ~~~~~\n<!-- SUL finalisation notification -->"; $dbw = CentralAuthUser::getCentralDB(); $updates = new UsersToRenameDatabaseUpdates($dbw); $commonParams = array('subject' => $this->getLocalizedText($this->getOption('subject'))); while (true) { $jobs = array(); $markNotified = array(); $rows = $updates->findUsers(wfWikiID(), 0, $this->mBatchSize); if ($rows->numRows() === 0) { break; } $lb = new LinkBatch(); foreach ($rows as $row) { $title = Title::makeTitleSafe(NS_USER_TALK, $row->utr_name); if (!$title) { $this->output("ERROR: Invalid username for {$row->utr_name}\n"); continue; } $lb->addObj($title); } $lb->execute(); foreach ($rows as $row) { $title = 'User talk:' . $row->utr_name; $titleObj = Title::newFromText($title); if ($titleObj->isRedirect()) { // @fixme find a way to notify users with a redirected user-talk $this->output("Skipping {$title} because it is a redirect\n"); $updates->markRedirectSkipped($row->utr_name, $row->utr_wiki); continue; } $jobs[] = new MassMessageServerSideJob(Title::newFromText($title), array('title' => $title, 'message' => str_replace('{{subst:PAGENAME}}', $row->utr_name, $message)) + $commonParams); $this->output("Will notify {$row->utr_name}\n"); $markNotified[] = $row; } $count = count($jobs); $this->output("Queued job for {$count} users.\n"); JobQueueGroup::singleton()->push($jobs); foreach ($markNotified as $row) { $updates->markNotified($row->utr_name, $row->utr_wiki); } $this->output("Waiting for slaves..."); CentralAuthUser::waitForSlaves(); // users_to_rename wfWaitForSlaves(); // And on the local wiki! $this->output(" done.\n"); $queued = $this->getQueuedCount(); while ($queued > 100000) { $this->output("Currently {$queued} jobs, sleeping for 5 seconds...\n"); sleep(5); $queued = $this->getQueuedCount(); } } }