public function execute() { $params = $this->extractRequestParams(); $prop = array_flip((array) $params['prop']); $APIResult = $this->getResult(); $data = array(); $dbr = CentralAuthUser::getCentralSlaveDB(); $fields = array('ggp_group'); if (isset($prop['rights'])) { $fields[] = 'ggp_permission'; } $result = $dbr->select('global_group_permissions', $fields, array(), __METHOD__, array('DISTINCT')); $globalGroups = array(); foreach ($result as $row) { if (!isset($globalGroups[$row->ggp_group])) { $globalGroups[$row->ggp_group] = array('rights' => array()); } if (isset($prop['rights'])) { $globalGroups[$row->ggp_group]['rights'][] = $row->ggp_permission; } } foreach ($globalGroups as $name => $value) { $entry = array('name' => $name); if (isset($prop['rights']) && count($value['rights'])) { $entry['rights'] = $value['rights']; $APIResult->setIndexedTagName($entry['rights'], 'right'); } $data[] = $entry; } $APIResult->setIndexedTagName($data, 'globalgroup'); $APIResult->addValue('query', $this->getModuleName(), $data); }
public function execute() { global $wgUser; $wgUser = User::newFromName('Maintenance script'); RequestContext::getMain()->setUser($wgUser); $dbr = CentralAuthUser::getCentralSlaveDB(); if ($this->getOption('fix', false) !== false) { $this->fix = true; } if ($this->getOption('safe-migrate', false) !== false) { $this->safe = true; $this->migrate = true; } if ($this->getOption('migrate', false) !== false) { $this->migrate = true; } if ($this->getOption('suppressrc', false) !== false) { $this->suppressRC = true; } $end = $dbr->selectField('globaluser', 'MAX(gu_id)'); for ($cur = 0; $cur <= $end; $cur += $this->mBatchSize) { $this->output("PROGRESS: {$cur} / {$end}\n"); $result = $dbr->select(array('globaluser', 'localuser'), array('gu_name'), array('lu_name' => null, "gu_id >= {$cur}", 'gu_id < ' . ($cur + $this->mBatchSize)), __METHOD__, array('ORDER BY' => 'gu_id'), array('localuser' => array('LEFT JOIN', 'gu_name=lu_name'))); foreach ($result as $row) { $this->process($row->gu_name); } if ($this->fix) { CentralAuthUser::waitForSlaves(); } } $this->output("done.\n"); }
/** * Get the Query database connection (read-only) * * @see ApiQueryBase::getDB * @return DatabaseBase */ protected function getDB() { static $db = null; if (is_null($db)) { $db = CentralAuthUser::getCentralSlaveDB(); } return $db; }
/** * 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() { $this->dbBackground = CentralAuthUser::getCentralSlaveDB(); if ($this->getOption('safe', false) !== false) { $this->safe = true; } if ($this->getOption('auto', false) !== false) { $this->autoMigrate = true; } if ($this->getOption('resettoken', false) !== false) { $this->resetToken = true; } if ($this->getOption('suppressrc', false) !== false) { $this->suppressRC = true; } // Check to see if we are processing a single username if ($this->getOption('username', false) !== false) { $username = $this->getOption('username'); $homewiki = $this->getOption('homewiki', null); $this->migrate($username, $homewiki); } elseif ($this->getOption('userlist', false) !== false) { $list = $this->getOption('userlist'); if (!is_file($list)) { $this->output("ERROR - File not found: {$list}"); exit(1); } $file = fopen($list, 'r'); if ($file === false) { $this->output("ERROR - Could not open file: {$list}"); exit(1); } while (strlen($line = trim(fgets($file)))) { $values = explode("\t", $line); switch (count($values)) { case 1: $this->migrate($values[0]); break; case 2: $this->migrate($values[0], $values[1]); break; default: $this->output("ERROR: Invalid account specification: '{$line}'\n"); continue; } if ($this->total % $this->batchSize == 0) { $this->output("Waiting for slaves to catch up ... "); CentralAuthUser::waitForSlaves(); $this->output("done\n"); } } fclose($file); } else { $this->output("ERROR - No username or list of usernames given\n"); exit(1); } $this->migratePassOneReport(); $this->output("done.\n"); }
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() { $this->output("CentralAuth migration pass 1:\n"); $this->output("Finding accounts which can be migrated without interaction...\n"); $dbBackground = CentralAuthUser::getCentralSlaveDB(); $result = $dbBackground->select('globalnames', array('gn_name'), array(), __METHOD__); foreach ($result as $row) { $this->fromPrefix = $row->gn_name; $central = new CentralAuthUser($row->gn_name); if ($central->storeAndMigrate()) { $this->migrated++; } if (++$this->total % 1000 == 0) { $this->migratePassOneReport(); } } $this->migratePassOneReport(); $this->output("done.\n"); }
function migratePassOne() { $migrated = 0; $total = 0; $chunkSize = 1000; $start = microtime(true); $dbBackground = CentralAuthUser::getCentralSlaveDB(); $result = $dbBackground->select('globalnames', array('gn_name'), '', __METHOD__); foreach ($result as $row) { $name = $row->gn_name; $central = new CentralAuthUser($name); if ($central->storeAndMigrate()) { $migrated++; } if (++$total % $chunkSize == 0) { migratePassOneReport($migrated, $total, $start); } } migratePassOneReport($migrated, $total, $start); echo "DONE\n"; }
/** * @param $res ResultWrapper */ function __construct($res) { parent::__construct($res); if ($res->numRows() == 0) { return; } /** * Load global user data */ $names = array(); foreach ($res as $row) { $names[] = $row->user_name; } $res->rewind(); $dbr = CentralAuthUser::getCentralSlaveDB(); $caRes = $dbr->select(array('localuser', 'globaluser'), '*', array('gu_name' => $names, 'lu_name=gu_name', 'lu_wiki' => wfWikiID()), __METHOD__); $this->globalData = array(); foreach ($caRes as $row) { $this->globalData[$row->gu_name] = $row; } wfDebug(__METHOD__ . ': got user data for ' . implode(', ', array_keys($this->globalData)) . "\n"); }
public function execute() { $db = CentralAuthUser::getCentralSlaveDB(); $conds = array(); $count = 0; do { $result = $db->select('globaluser', array('gu_name'), array_merge($conds, array('gu_home_db IS NULL OR gu_home_db = ""')), __METHOD__, array('LIMIT' => $this->mBatchSize, 'ORDER BY' => 'gu_name')); foreach ($result as $row) { $central = new CentralAuthUser($row->gu_name); $central->mStateDirty = true; $central->saveSettings(); $count++; } $this->output("{$count}\n"); CentralAuthUser::waitForSlaves(); if ($result->numRows() < $this->mBatchSize) { break; } $conds = array('gu_name > ' . $db->addQuotes($row->gu_name)); } while (true); $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"); }
function showCurrentRenames() { $dbr = CentralAuthUser::getCentralSlaveDB(); $tables = array('renameuser_status'); if (!$this->getUser()->isAllowed('centralauth-oversight')) { $join_conds = array('globaluser' => array('INNER JOIN', array('gu_name=ru_newname', 'gu_hidden=""'))); $tables[] = 'globaluser'; } else { $join_conds = array(); } $res = $dbr->select($tables, array('ru_oldname', 'ru_newname'), array(), __METHOD__, array('DISTINCT'), $join_conds); $html = "<ul>\n"; $hasResults = false; foreach ($res as $row) { $hasResults = true; $html .= '<li>' . $this->msg('centralauth-rename-progress-item')->params($row->ru_oldname, $row->ru_newname)->parse() . "</li>\n"; } if (!$hasResults) { return; } $html .= "</ul>\n"; $html = $this->msg('centralauth-rename-progress-list-header')->escaped() . $html; $this->getOutput()->addHTML($html); }
/** * Search the CentralAuth db for all usernames prefixed with mPrefixSearch */ private function searchForUsers() { $dbr = CentralAuthUser::getCentralSlaveDB(); $where = array('gu_name' . $dbr->buildLike($this->mPrefixSearch, $dbr->anyString())); if (!$this->mCanOversight) { $where['gu_hidden'] = CentralAuthUser::HIDDEN_NONE; } $result = $dbr->select(array('globaluser'), array('gu_name'), $where, __METHOD__, array('LIMIT' => 100)); foreach ($result as $row) { $this->mUserNames[] = $row->gu_name; } }
/** * @return DatabaseBase */ protected function getDBSlave() { return CentralAuthUser::getCentralSlaveDB(); }
function __construct(IContextSource $context = null, $par = null) { parent::__construct($context, $par); $this->mDb = CentralAuthUser::getCentralSlaveDB(); }
/** * @param $group * @return int */ public static function getWikiSetForGroup($group) { $dbr = CentralAuthUser::getCentralSlaveDB(); $res = $dbr->selectRow('global_group_restrictions', '*', array('ggr_group' => $group), __METHOD__); return $res ? $res->ggr_set : 0; }
/** * Check that the local user object is part of a global account, and the account is * attached on this wiki, and the central OAuth wiki, so we know that the same username * on both wikis references the same user. Set the user object to false if they are not. * @param int $userId the central OAuth wiki user_id for this username * @param string $wgMWOAuthCentralWiki * @param User &$user the loca user object * @param string $wgMWOAuthSharedUserSource the authoritative extension */ public static function onOAuthGetLocalUserFromCentralId($userId, $wgMWOAuthCentralWiki, &$user, $wgMWOAuthSharedUserSource) { if ($wgMWOAuthSharedUserSource !== 'CentralAuth') { // We aren't supposed to handle this return true; } $dbr = CentralAuthUser::getCentralSlaveDB(); $user_name = $dbr->selectField('globaluser', 'gu_name', array('gu_id' => $userId), __METHOD__); if ($user_name === false) { wfDebugLog('CentralAuth', __METHOD__ . ": invalid userId ({$userId}) passed to CentralAuth by OAuth"); $user = false; return false; } $centralUser = new CentralAuthUser($user_name); if ($centralUser->isLocked() || !$centralUser->isAttached() || !$centralUser->attachedOn($wgMWOAuthCentralWiki)) { wfDebugLog('CentralAuth', __METHOD__ . ": user '{$user_name}' cannot use OAuth on " . wfWikiID()); $user = false; return false; } $user = User::newFromName($user_name); // One last sanity check if ($user->getId() == 0) { throw new Exception("Attached user couldn't be loaded from name"); } return true; }
/** * Fetches unattached accounts and attempts to continue. * * @return ResultWrapper */ private function doQuery() { $dbr = CentralAuthUser::getCentralSlaveDB(); $rows = $dbr->select(array('localnames', 'localuser'), array('ln_name AS name', 'ln_wiki AS wiki'), array($dbr->makeList(array('ln_name > ' . $dbr->addQuotes($this->lName), 'ln_name = ' . $dbr->addQuotes($this->lName) . ' AND ln_wiki > ' . $dbr->addQuotes($this->lWiki)), LIST_OR), 'lu_attached_method IS NULL'), __METHOD__, array('LIMIT' => $this->mBatchSize, 'ORDER BY' => array('ln_name', 'ln_wiki')), array('localuser' => array('LEFT JOIN', 'ln_name=lu_name AND ln_wiki=lu_wiki'))); return $rows; }
/** * @param SpecialPage $owner Containing page * @param IContextSource $context */ public function __construct(SpecialPage $owner, IContextSource $context) { $this->owner = $owner; $this->mDb = CentralAuthUser::getCentralSlaveDB(); parent::__construct($context); }
/** * @param SpecialPage $owner Containing page * @param string $page Subpage * @param IContextSource $context */ public function __construct(SpecialPage $owner, $page, IContextSource $context = null) { $this->mOwner = $owner; $this->mPage = $page; $this->mDb = CentralAuthUser::getCentralSlaveDB(); $this->setLimit(25); if ($this->showOpenRequests()) { $this->mDefaultDirection = self::DIR_ASCENDING; } else { $this->mDefaultDirection = self::DIR_DESCENDING; } parent::__construct($context); }
function __construct(IContextSource $context = null, $par = null) { parent::__construct($context); $this->mDefaultDirection = $this->getRequest()->getBool('desc'); $this->mDb = CentralAuthUser::getCentralSlaveDB(); }