/** * Determines whether the specified IP address corresponds to a known active comment spammer. * @param $title Title object * @return boolean True for spammer, false for non-spammer or if get unexpected results. */ public static function isCommentSpammer($title) { // logged in users are assumed to not be comment spammers. global $wgUser; if (!$wgUser->isAnon()) { //wfDebug( __METHOD__ . ": Assuming not spammer as logged in.\n" ); #return false; } // check whether this is a known comment spammer. $ip_addr = wfGetIp(); $results = self::getDnsResults($ip_addr); $params = array($ip_addr); $is_spammer = self::resultsSaySpammer($results, $params); wfDebug(__METHOD__ . ": DNS says {$ip_addr} is " . ($is_spammer ? '' : 'NOT ') . "a spammer.\n"); // We record a diagnostic log in here, that will appear in Special:Log // For high-volume or mid-volume sites, this should be commented out. self::addLogEntry($title, $is_spammer, $params); return $is_spammer; }
/** * Check if the IP is allowed to skip captchas */ function isIPWhitelisted() { if ($this->IPWhitelist) { $ip = wfGetIp(); foreach ($this->IPWhitelist as $range) { if (IP::isInRange($ip, $range)) { return true; } } } return false; }
public static function isExitNode($ip = null) { if ($ip == null) { $ip = wfGetIp(); } $nodes = self::getExitNodes(); return in_array( $ip, $nodes ); }
/** * @param EditPage $editPage * @param string $newtext * @param string $section * @return bool true if the captcha should run */ function shouldCheck(&$editPage, $newtext, $section, $merged = false) { $this->trigger = ''; $title = $editPage->mArticle->getTitle(); global $wgUser; if ($wgUser->isAllowed('skipcaptcha')) { wfDebug("ConfirmEdit: user group allows skipping captcha\n"); return false; } global $wgCaptchaWhitelistIP; if (!empty($wgCaptchaWhitelistIP)) { $ip = wfGetIp(); foreach ($wgCaptchaWhitelistIP as $range) { if (IP::isInRange($ip, $range)) { return false; } } } global $wgEmailAuthentication, $ceAllowConfirmedEmail; if ($wgEmailAuthentication && $ceAllowConfirmedEmail && $wgUser->isEmailConfirmed()) { wfDebug("ConfirmEdit: user has confirmed mail, skipping captcha\n"); return false; } if ($this->captchaTriggers($editPage, 'edit')) { // Check on all edits global $wgUser; $this->trigger = sprintf("edit trigger by '%s' at [[%s]]", $wgUser->getName(), $title->getPrefixedText()); $this->action = 'edit'; wfDebug("ConfirmEdit: checking all edits...\n"); return true; } if ($this->captchaTriggers($editPage, 'create') && !$editPage->mTitle->exists()) { //Check if creating a page global $wgUser; $this->trigger = sprintf("Create trigger by '%s' at [[%s]]", $wgUser->getName(), $title->getPrefixedText()); $this->action = 'create'; wfDebug("ConfirmEdit: checking on page creation...\n"); return true; } if ($this->captchaTriggers($editPage, 'addurl')) { // Only check edits that add URLs if ($merged) { // Get links from the database $oldLinks = $this->getLinksFromTracker($title); // Share a parse operation with Article::doEdit() $editInfo = $editPage->mArticle->prepareTextForEdit($newtext); $newLinks = array_keys($editInfo->output->getExternalLinks()); } else { // Get link changes in the slowest way known to man $oldtext = $this->loadText($editPage, $section); $oldLinks = $this->findLinks($oldtext); $newLinks = $this->findLinks($newtext); } $unknownLinks = array_filter($newLinks, array(&$this, 'filterLink')); $addedLinks = array_diff($unknownLinks, $oldLinks); $numLinks = count($addedLinks); if ($numLinks > 0) { global $wgUser; $this->trigger = sprintf("%dx url trigger by '%s' at [[%s]]: %s", $numLinks, $wgUser->getName(), $title->getPrefixedText(), implode(", ", $addedLinks)); $this->action = 'addurl'; return true; } } global $wgCaptchaRegexes; if (!empty($wgCaptchaRegexes)) { // Custom regex checks $oldtext = $this->loadText($editPage, $section); foreach ($wgCaptchaRegexes as $regex) { $newMatches = array(); if (preg_match_all($regex, $newtext, $newMatches)) { $oldMatches = array(); preg_match_all($regex, $oldtext, $oldMatches); $addedMatches = array_diff($newMatches[0], $oldMatches[0]); $numHits = count($addedMatches); if ($numHits > 0) { global $wgUser; $this->trigger = sprintf("%dx %s at [[%s]]: %s", $numHits, $regex, $wgUser->getName(), $title->getPrefixedText(), implode(", ", $addedMatches)); $this->action = 'edit'; return true; } } } } return false; }
/** * If the (non-anonymous) user is blocked, this function will block any IP address * that they successfully log on from. */ function spreadBlock() { wfDebug(__METHOD__ . "()\n"); $this->load(); if ($this->mId == 0) { return; } $userblock = Block::newFromDB('', $this->mId); if (!$userblock) { return; } $userblock->doAutoblock(wfGetIp()); }
public function runWelcome() { global $wgUser; wfProfileIn(__METHOD__); //set the variables (used to be in __construct() ) $mUserId = $wgUser->getID(); $mUserIP = wfGetIp(); $mUserName = $wgUser->getName(); $mAnon = $wgUser->isAnon(); $mSysop = false; if ($mAnon) { return false; } $mUser = User::newFromId($mUserId); /** * fallback */ if (!$mUser) { $mUser = User::newFromName($mUserName); } $oldValue = $wgErrorLog; $wgErrorLog = true; /** * overwrite $wgUser for ~~~~ expanding */ $sysop = trim(wfMsgForContent("welcome-user")); if (!in_array($sysop, array("@disabled", "-"))) { $tmpUser = $wgUser; $wgUser = User::newFromName(self::WELCOMEUSER); $flags = 0; $bot_message = trim(wfMsgForContent("welcome-bot")); if ($bot_message == '@bot' || $wgUser && $wgUser->isAllowed('bot')) { $flags = EDIT_FORCE_BOT | EDIT_SUPPRESS_RC; } else { $flags = EDIT_SUPPRESS_RC; } if ($mUser && $mUser->getName() !== self::WELCOMEUSER) { /** * check again if talk page exists */ $talkPage = $mUser->getUserPage()->getTalkPage(); if ($talkPage) { $mSysop = self::getLastSysop(); $gEG = $mSysop->getEffectiveGroups(); $isSysop = in_array('sysop', $gEG); $isStaff = in_array('staff', $gEG); unset($gEG); $sysopPage = $mSysop->getUserPage()->getTalkPage(); $signature = self::expandSig(); $welcomeMsg = false; $talkArticle = new Article($talkPage, 0); if (!$talkArticle->exists()) { /** * now create user page (if not exists of course) */ if (self::isEnabled("page-user")) { $userPage = $mUser->getUserPage(); if ($userPage) { $userArticle = new Article($userPage, 0); if (!$userArticle->exists()) { $pageMsg = wfMsgForContent("welcome-user-page"); $userArticle->doEdit($pageMsg, false, $flags); } } } if (self::isEnabled("message-user")) { $key = "welcome-message-user"; $welcomeMsg = wfMsgExt($key, array("parsemag", "content"), array('', $sysopPage->getPrefixedText(), $signature, wfEscapeWikiText($mUser->getName()))); } if ($welcomeMsg) { global $wgLang; $dateStr = $wgLang->timeanddate(wfTimestampNow()); $real_name = User::whoIsReal($mSysop->getID()); if ($real_name == "") { $real_name = $mSysop->getName(); } $comment = $welcomeMsg; //add a hidden variable to id welcome user notifications for echo $comment .= '<!--welcomeuser-->'; $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $mSysop->getName(), $real_name, $comment); $talkArticle->doEdit($formattedComment, wfMsgForContent("welcome-message-log"), $flags); //notify via the echo notification system if (class_exists('EchoEvent')) { EchoEvent::create(array('type' => 'edit-user-talk', 'title' => $talkPage, 'agent' => $mSysop)); } } } } } $wgUser = $tmpUser; $wgErrorLog = $oldValue; } wfProfileOut(__METHOD__); return true; }
/** * Check if the IP is allowed to skip captchas */ function isIPWhitelisted() { global $wgCaptchaWhitelistIP; if ($wgCaptchaWhitelistIP) { $ip = wfGetIp(); foreach ($wgCaptchaWhitelistIP as $range) { if (IP::isInRange($ip, $range)) { return true; } } } return false; }
/** * If the (non-anonymous) user is blocked, this function will block any IP address * that they successfully log on from. */ function spreadBlock() { wfDebug(__METHOD__ . "()\n"); $this->load(); if ($this->mId == 0) { return; } $userblock = Block::newFromDB('', $this->mId); if (!$userblock) { return; } $currentIP = wfGetIp(); error_log(__METHOD__ . ": calling Autoblock for user " . $this->mName . " id=" . $this->mId . " ip=" . $currentIP . "\n", 3, '/tmp/block.log'); // Reuben commented this spreading because it was causing problems in the // wikiHaus. There is a banned user that keeps doing activity with our IP // address somehow but it's been a few hours debugging without result, // so this is the best compromise. Oct 24, 2013 //$userblock->doAutoblock( $currentIP ); }
private function shouldCheck( $title, $newText, $oldText = null ) { global $wgUser, $wgCaptchaWhitelistIP, $wgCaptchaRegexes; global $wgEmailAuthentication, $ceAllowConfirmedEmail; if ( $wgUser->isAllowed( 'skipcaptcha' ) ) { wfDebug( "WlCaptchaAdapter: user group allows skipping captcha\n" ); return false; } if ( !empty( $wgCaptchaWhitelistIP ) ) { $ip = wfGetIp(); foreach ( $wgCaptchaWhitelistIP as $range ) { if ( IP::isInRange( $ip, $range ) ) { return false; } } } if ( $wgEmailAuthentication && $ceAllowConfirmedEmail && $wgUser->isEmailConfirmed() ) { wfDebug( "WlCaptchaAdapter: user has confirmed mail, skipping captcha\n" ); return false; } if ( $this->captchaTriggers( $title, 'edit' ) ) { $this->mCaptcha->trigger = sprintf( "Edit trigger by '%s' at [[%s]]", $wgUser->getName(), $title->getPrefixedText() ); $this->mCaptcha->action = 'edit'; wfDebug( "WlCaptchaAdapter: checking all edits...\n" ); return true; } if ( $this->captchaTriggers( $title, 'create' ) && is_null( $oldText ) ) { $this->mCaptcha->trigger = sprintf( "Create trigger by '%s' at [[%s]]", $wgUser->getName(), $title->getPrefixedText() ); $this->mCaptcha->action = 'create'; wfDebug( "WlCaptchaAdapter: checking on page creation...\n" ); return true; } if ( $this->captchaTriggers( $title, 'addurl' ) ) { $oldLinks = $this->findLinks( $title, $oldText ); $newLinks = $this->findLinks( $title, $newText ); $unknownLinks = array_filter( $newLinks, array( &$this->mCaptcha, 'filterLink' ) ); $addedLinks = array_diff( $unknownLinks, $oldLinks ); $numLinks = count( $addedLinks ); if ( $numLinks > 0 ) { $this->mCaptcha->trigger = sprintf( "%dx url trigger by '%s' at [[%s]]: %s", $numLinks, $wgUser->getName(), $title->getPrefixedText(), implode( ", ", $addedLinks ) ); $this->mCaptcha->action = 'addurl'; return true; } } if ( !empty( $wgCaptchaRegexes ) ) { foreach ( $wgCaptchaRegexes as $regex ) { $newMatches = array(); if ( preg_match_all( $regex, $newtext, $newMatches ) ) { $oldMatches = array(); preg_match_all( $regex, $oldtext, $oldMatches ); $addedMatches = array_diff( $newMatches[0], $oldMatches[0] ); $numHits = count( $addedMatches ); if ( $numHits > 0 ) { $this->mCaptcha->trigger = sprintf( "%dx %s trigger by '%s' at [[%s]]: %s", $numHits, $regex, $wgUser->getName(), $title->getPrefixedText(), implode( ", ", $addedMatches ) ); $this->mCaptcha->action = 'edit'; return true; } } } } return false; }
static function onSpecialPasswordResetOnSubmit(&$users, $data, &$error) { global $wgUser; if (GlobalBlocking::getUserBlockErrors($wgUser, wfGetIp())) { $error = wfMsg('globalblocking-blocked-nopassreset'); return false; } return true; }
/** * Create a new SignDocumentSignature using data obtained from a POST. */ public static function newFromPost() { global $wgRequest; if ( !$wgRequest->wasPosted() ) throw new MWException( 'Page was not posted.' ); self::$canRunCtor = true; $f = new SignDocumentSignature(); self::$canRunCtor = false; $f->mTimestamp = wfTimestampNow(); $f->mRealName = $wgRequest->getVal( 'realname', '' ); $f->mAddress = $wgRequest->getVal( 'address', '' ); $f->mCity = $wgRequest->getVal( 'city', '' ); $f->mState = $wgRequest->getVal( 'state', '' ); $f->mCountry = $wgRequest->getVal( 'country', '' ); $f->mZip = $wgRequest->getVal( 'zip', '' ); $f->mPhone = $wgRequest->getVal( 'phone', '' ); $f->mBday = $wgRequest->getVal( 'bday', 0 ); $f->mEmail = $wgRequest->getVal( 'email', '' ); $f->mIp = wfGetIp(); $f->mAgent = $wgRequest->getHeader( 'User-Agent' ); if ( $wgRequest->getVal( 'anonymous' ) ) $f->mHiddenFields[] = 'realname'; if ( $wgRequest->getVal( 'hideaddress' ) ) $f->mHiddenFields[] = 'address'; if ( $wgRequest->getVal( 'hideextaddress' ) ) $f->mHiddenFields[] = 'extaddress'; if ( $wgRequest->getVal( 'hidephone' ) ) $f->mHiddenFields[] = 'phone'; if ( $wgRequest->getVal( 'hideemail' ) ) $f->mHiddenFields[] = 'email'; if ( $wgRequest->getVal( 'hidebday' ) ) $f->mHiddenFields[] = 'bday'; $f->mForm = SignDocumentForm::newFromDB( $wgRequest->getVal( 'doc' ) ); return $f; }