/** * Switches a user's preferences off * @param $user User object to set preferences for * @param $global bool Whether to apply this change on all wikis in $wgPrefSwitchWikis */ public static function switchOff($user, $global = false) { self::switchOffUser($user); if ($global) { $globalUser = new CentralAuthUser($user->getName()); if (!$globalUser->exists()) { return; } $accounts = $globalUser->queryAttached(); foreach ($accounts as $account) { $remoteUser = UserRightsProxy::newFromName($account['wiki'], $globalUser->getName(), true); if ($remoteUser) { self::switchOffUser($remoteUser); } } } }
/** * Normalize the input username, which may be local or remote, and * return a user (or proxy) object for manipulating it. * * Side effects: error output for invalid access * @return mixed User, UserRightsProxy, or null */ function fetchUser($username) { global $wgOut, $wgUser; $parts = explode('@', $username); if (count($parts) < 2) { $name = trim($username); $database = ''; } else { list($name, $database) = array_map('trim', $parts); if (!$wgUser->isAllowed('userrights-interwiki')) { $wgOut->addWikiMsg('userrights-no-interwiki'); return null; } if (!UserRightsProxy::validDatabase($database)) { $wgOut->addWikiMsg('userrights-nodatabase', $database); return null; } } if ($name == '') { $wgOut->addWikiMsg('nouserspecified'); return false; } if ($name[0] == '#') { // Numeric ID can be specified... // We'll do a lookup for the name internally. $id = intval(substr($name, 1)); if ($database == '') { $name = User::whoIs($id); } else { $name = UserRightsProxy::whoIs($database, $id); } if (!$name) { $wgOut->addWikiMsg('noname'); return null; } } if ($database == '') { $user = User::newFromName($name); } else { $user = UserRightsProxy::newFromName($database, $name); } if (!$user || $user->isAnon()) { $wgOut->addWikiMsg('nosuchusershort', $username); return null; } return $user; }
/** * @param array $formData * @param HtmlForm $form * * @return bool|string * @throws DBUnexpectedError * @throws Exception * @throws MWException */ public static function processInput(array $formData, HtmlForm $form) { error_reporting(0); global $wgCreateWikiSQLfiles, $IP; $DBname = $formData['dbname']; $founderName = $formData['founder']; $dbw = wfGetDB(DB_MASTER); $dbTest = $dbw->query('SHOW DATABASES LIKE ' . $dbw->addQuotes($DBname) . ';'); $rows = $dbTest->numRows(); $dbTest->free(); if ($rows !== 0) { return wfMessage('createwiki-error-dbexists')->plain(); } $farmerLogEntry = new ManualLogEntry('farmer', 'createandpromote'); $farmerLogEntry->setPerformer($form->getUser()); $farmerLogEntry->setTarget($form->getTitle()); $farmerLogEntry->setComment($formData['comment']); $farmerLogEntry->setParameters(array('4::wiki' => $DBname, '5::founder' => $founderName)); $farmerLogID = $farmerLogEntry->insert(); $farmerLogEntry->publish($farmerLogID); $dbw->query('SET storage_engine=InnoDB;'); $dbw->query('CREATE DATABASE ' . $dbw->addIdentifierQuotes($DBname) . ';'); $dbw->selectDB($DBname); foreach ($wgCreateWikiSQLfiles as $file) { $dbw->sourceFile($file); } $dbw->insert('site_stats', array('ss_row_id' => 1)); $dbw->close(); // Add DNS record to cloudflare global $wgCreateWikiUseCloudFlare, $wgCloudFlareUser, $wgCloudFlareKey; if ($wgCreateWikiUseCloudFlare) { $domainPrefix = substr($DBname, 0, -4); $cloudFlare = new cloudflare_api($wgCloudFlareUser, $wgCloudFlareKey); $cloudFlareResult = $cloudFlare->rec_new('orain.org', 'CNAME', $domainPrefix, 'lb.orain.org'); if (!is_object($cloudFlareResult) || $cloudFlareResult->result !== 'success') { wfDebugLog('CreateWiki', 'CloudFlare FAILED to add CNAME for ' . $domainPrefix . '.orain.org'); } else { wfDebugLog('CreateWiki', 'CloudFlare CNAME added for ' . $domainPrefix . '.orain.org'); } } // Create local account for founder (hack) $out = exec("php5 {$IP}/extensions/CentralAuth/maintenance/createLocalAccount.php " . escapeshellarg($founderName) . ' --wiki ' . escapeshellarg($DBname)); if (!strpos($out, 'created')) { return wfMessage('createwiki-error-usernotcreated')->plain(); } require_once "{$IP}/includes/UserRightsProxy.php"; // Grant founder sysop and bureaucrat rights $founderUser = UserRightsProxy::newFromName($DBname, $founderName); $newGroups = array('sysop', 'bureaucrat'); array_map(array($founderUser, 'addGroup'), $newGroups); $founderUser->invalidateCache(); $form->getOutput()->addWikiMsg('createwiki-success', $DBname); return true; }
/** * Normalize the input username, which may be local or remote, and * return a user (or proxy) object for manipulating it. * * Side effects: error output for invalid access * @param string $username * @return Status */ public function fetchUser($username) { $parts = explode($this->getConfig()->get('UserrightsInterwikiDelimiter'), $username); if (count($parts) < 2) { $name = trim($username); $database = ''; } else { list($name, $database) = array_map('trim', $parts); if ($database == wfWikiID()) { $database = ''; } else { if (!$this->getUser()->isAllowed('userrights-interwiki')) { return Status::newFatal('userrights-no-interwiki'); } if (!UserRightsProxy::validDatabase($database)) { return Status::newFatal('userrights-nodatabase', $database); } } } if ($name === '') { return Status::newFatal('nouserspecified'); } if ($name[0] == '#') { // Numeric ID can be specified... // We'll do a lookup for the name internally. $id = intval(substr($name, 1)); if ($database == '') { $name = User::whoIs($id); } else { $name = UserRightsProxy::whoIs($database, $id); } if (!$name) { return Status::newFatal('noname'); } } else { $name = User::getCanonicalName($name); if ($name === false) { // invalid name return Status::newFatal('nosuchusershort', $username); } } if ($database == '') { $user = User::newFromName($name); } else { $user = UserRightsProxy::newFromName($database, $name); } if (!$user || $user->isAnon()) { return Status::newFatal('nosuchusershort', $username); } return Status::newGood($user); }
public function checkUser($username, $output = false) { global $wgOut; $bits = explode('@', $username, 2); if (count($bits) == 1) { if ($output) { $this->showForm(wfMsgWikiHtml('crosswikiblock-local')); } return array('local'); } list($name, $db) = $bits; if (!UserRightsProxy::validDatabase($db)) { if ($output) { $this->showForm(wfMsgWikiHtml('crosswikiblock-dbnotfound', htmlspecialchars($db))); } return array('dbnotfound', $db); } if (!User::isIP($name) && !User::isCreatableName($name)) { if ($output) { $this->showForm(wfMsgWikiHtml('crosswikiblock-noname', htmlspecialchars($name))); } return array('invalidname', $name); } if (!User::isIP($name)) { $userProxy = UserRightsProxy::newFromName($db, $name); $this->mUserProxy = $userProxy; if (!$userProxy) { if ($output) { $this->showForm(wfMsgWikiHtml('crosswikiblock-nouser', htmlspecialchars($name), htmlspecialchars($db), htmlspecialchars($username))); } return array('usernotfound', $name, $db, $username); } } $this->mUsername = $name; $this->mDatabase = $db; return false; }
static function getBlockRow($target) { $dbw = UserRightsProxy::getDB($target['wiki']); $conds = array(); if (isset($target['blockid'])) { $conds['ipb_id'] = $target['blockid']; } if (isset($target['ip'])) { $conds['ipb_address'] = $target['ip']; } if (isset($target['username'])) { $conds['ipb_address'] = $target['username']; } return $dbw->selectRow('ipblocks', '*', $conds, __METHOD__); }