/** * @static * @param User $user * @return array|bool|null */ public static function blockCheck(User $user) { global $wgUser, $wgMemc; wfProfileIn(__METHOD__); // dependancy -- if this doesn't exist, quit early if (!class_exists('AccountCreationTracker')) { wfProfileOut(__METHOD__); return true; } // we don't block anons with this filter if ($user->isAnon()) { wfProfileOut(__METHOD__); return true; } $ret = true; // RT#42011: RegexBlock records strange results // don't write stats for other user than visiting user $isCurrentUser = $user->getName() == $wgUser->getName(); // check cache first before proceeding $cachedState = self::getBlockFromCache($user, $isCurrentUser); if (!is_null($cachedState)) { wfProfileOut(__METHOD__); return $cachedState; } $tracker = new AccountCreationTracker(); $hashes = $tracker->getHashesByUser($user); $blocksData = Phalanx::getFromFilter(self::TYPE); if (!empty($blocksData) && !empty($hashes)) { foreach ($hashes as $hash) { $ret = self::blockCheckInternal($user, $blocksData, $hash, $isCurrentUser); if (!$ret) { // only check until we get first blocking match break; } } } // populate cache if not done before if ($ret) { $cacheKey = self::getCacheKey($user); $cachedState = array('timestamp' => wfTimestampNow(), 'block' => false, 'return' => $ret); $wgMemc->set($cacheKey, $cachedState); } wfProfileOut(__METHOD__); return $ret; }
public function nukeContribs() { wfProfileIn(__METHOD__); global $wgSharedDB; $user_id = intval($_GET['user_id']); $wiki_id = intval($_GET['wiki_id']); $page_id = intval($_GET['page_id']); if (empty($wgSharedDB)) { wfProfileOut(__METHOD__); return $this->returnError('Non-shared Users DB, cannot continue'); } if (!$user_id || !$wiki_id || !$page_id) { wfProfileOut(__METHOD__); return $this->returnError('Wrong parameters'); } if ($wiki_id != $this->wg->CityId) { // can only process local requests wfProfileOut(__METHOD__); return $this->returnError('Wrong wiki id'); } if (!$this->wg->User->isAllowed('rollbacknuke')) { // doesn't have permissions wfProfileOut(__METHOD__); return $this->returnError('No permissions to execute action'); } $user = User::newFromId($user_id); if (!$user instanceof User) { wfProfileOut(__METHOD__); return $this->returnError('Unable to create User obj with ID specified'); } $article = Article::newFromID($page_id); if (!$article instanceof Article) { wfProfileOut(__METHOD__); return $this->returnError('Article does not exist'); } $msg = ''; $act = new AccountCreationTracker(); $ret = $act->rollbackPage($article, $user->getName(), 'mass rollback', $msg); $status = $ret ? 'OK' : 'ERROR'; $output = array('status' => $status, 'msg' => $msg); echo json_encode($output); $this->skipRendering(); wfProfileOut(__METHOD__); return false; }