function wfRegexBlockExpireCheck($user, $array_match = null, $ips = 0, $iregex = 0) { global $wgMemc; wfProfileIn(__METHOD__); /* I will use memcache, with the key being particular block */ if (empty($array_match)) { wfProfileOut(__METHOD__); return false; } $ret = array(); /* for EACH match check whether timestamp expired until found VALID timestamp but: only for a BLOCKED user, and it will be memcached moreover, expired blocks will be consequently deleted */ $blocked = ""; foreach ($array_match as $single) { $key = RegexBlockData::getMemcKey("block_user", $single); $blocked = null; $cached = $wgMemc->get($key); if (empty($cached) || !is_object($cached)) { /* get from database */ $blocked = RegexBlockData::getRegexBlockByName($single, $iregex); } else { /* get from cache */ $blocked = $cached; } /* check conditions */ if (is_object($blocked)) { $ret = wfRegexBlockExpireNameCheck($blocked); if ($ret !== false) { $ret['match'] = $single; $ret['ip'] = $ips; $wgMemc->set($key, $blocked); wfProfileOut(__METHOD__); return $ret; } else { /* clean up an obsolete block */ wfRegexBlockClearExpired($single, $blocked->blckby_blocker); } } } wfProfileOut(__METHOD__); return false; }
function wfRegexBlockExpireCheck($user, $names = null, $ips = null) { global $wgMemc, $wgSharedDB; /* I will use memcache, with the key being particular block */ if (is_array($ips)) { $array_match = $ips; $username = wfGetIP(); } else { $array_match = $names; $username = $user->getName(); } $ret = array(); $dbr =& wfGetDB(DB_SLAVE); /* for EACH match check whether timestamp expired until found VALID timestamp but: only for a BLOCKED user, and it will be memcached moreover, expired blocks will be consequently deleted */ foreach ($array_match as $single) { $key = str_replace(" ", "_", "{$wgSharedDB}:regexBlockCore:blocked:{$single}"); $cached = $wgMemc->get($key); if (!is_object($cached)) { /* get from database */ $query = "SELECT blckby_timestamp, blckby_expire, blckby_blocker, blckby_create, blckby_exact, blckby_reason \n\t\t\t\t FROM " . wfRegexBlockGetTable() . " \n\t\t\t\t WHERE blckby_name like {$dbr->addQuotes('%' . $single . '%')}"; $res = $dbr->query($query); if ($row = $dbr->fetchObject($res)) { /* if still valid or infinite, ok to block user */ if (wfTimestampNow() <= $row->blckby_expire || 'infinite' == $row->blckby_expire) { $ret['create'] = $row->blckby_create; $ret['exact'] = $row->blckby_exact; $ret['reason'] = $row->blckby_reason; $wgMemc->set($key, $row); $dbr->freeResult($res); return $ret; } else { /* clean up an obsolete block */ wfRegexBlockClearExpired($single, $row->blckby_blocker); } } $dbr->freeResult($res); } else { /* get from cache */ if (wfTimestampNow() <= $cached->blckby_expire || 'infinite' == $cached->blckby_expire) { $ret['create'] = $cached->blckby_create; $ret['exact'] = $cached->blckby_exact; $ret['reason'] = $cached->blckby_reason; return $ret; } else { /* clean up an obsolete block */ wfRegexBlockClearExpired($single, $cached->blckby_blocker); } } } return false; }
private function deleteFromRegexBlockList() { global $wgOut, $wgRequest, $wgMemc, $wgUser; global $wgExternalSharedDB; wfProfileIn(__METHOD__); $result = false; $ip = $wgRequest->getVal('ip'); $blckid = intval($wgRequest->getVal('blckid')); $blocker = $wgRequest->getVal('blocker'); $titleObj = Title::makeTitle(NS_SPECIAL, 'Regexblock'); if (empty($ip) && !empty($blckid)) { $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB); $oRes = $dbr->select(REGEXBLOCK_TABLE, array("blckby_name", "blckby_blocker"), array("blckby_id = '" . $blckid . "'"), __METHOD__); if ($oRow = $dbr->fetchObject($oRes)) { /* if still valid or infinite, ok to block user */ $ip = $oRow->blckby_name; $blocker = $oRow->blckby_blocker; } $dbr->freeResult($oRes); } if (function_exists('wfRegexBlockClearExpired')) { $result = wfRegexBlockClearExpired($ip, $blocker); } else { /* delete */ $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); wfRegexBlockUnsetKeys($ip); $dbw->delete(REGEXBLOCK_TABLE, array("blckby_name = {$dbw->addQuotes($ip)}"), __METHOD__); if ($dbw->affectedRows()) { $result = true; } } wfProfileOut(__METHOD__); if ($result === true) { $wgOut->redirect($titleObj->getFullURL('action=success_unblock&ip=' . urlencode($ip) . '&' . $this->makeListUrlParams())); } else { $wgOut->redirect($titleObj->getFullURL('action=failure_unblock&ip=' . urlencode($ip) . '&' . $this->makeListUrlParams())); } return; }