function wfRegexBlockClearExpired($username, $blocker) { $dbw =& wfGetDB(DB_MASTER); $query = "DELETE FROM " . wfRegexBlockGetTable() . " WHERE blckby_name = " . $dbw->addQuotes($username); $dbw->query($query); if ($dbw->affectedRows()) { /* success, remember to delete cache key */ wfRegexBlockUnsetKeys($blocker, $username); return true; } return false; }
function wfRegexBlockClearExpired($username, $blocker) { global $wgExternalSharedDB; wfProfileIn(__METHOD__); $result = false; /* delete cache key */ wfRegexBlockUnsetKeys($username); $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); $dbw->delete(REGEXBLOCK_TABLE, array("blckby_name = {$dbw->addQuotes($username)}"), __METHOD__); $result = true; wfProfileOut(__METHOD__); return $result; }
function doSubmit() { global $wgOut, $wgUser, $wgMemc; /* empty name */ if (strlen($this->mRegexBlockedAddress) == 0) { $this->showForm(wfMsg('regexblock-form-submit-empty')); return; } /* castrate regexes */ if (!($simple_regex = wfValidRegex($this->mRegexBlockedAddress))) { /* now, very generic comment - should the conditions change, this should too */ $this->showForm(wfMsg('regexblock-form-submit-regex')); return; } /* check expiry */ if (strlen($this->mRegexBlockedExpire) == 0) { $this->showForm(wfMsg('regexblock-form-submit-expiry')); return; } /* TODO - check infinite */ if ($this->mRegexBlockedExpire != 'infinite') { $expiry = strtotime($this->mRegexBlockedExpire); if ($expiry < 0 || $expiry === false) { $this->showForm(wfMsg('ipb_expiry_invalid')); return; } $expiry = wfTimestamp(TS_MW, $expiry); } else { $expiry = $this->mRegexBlockedExpire; } /* make insert */ $dbw =& wfGetDB(DB_MASTER); $name = $wgUser->getName(); $timestamp = wfTimestampNow(); $query = "INSERT IGNORE INTO " . wfRegexBlockGetTable() . "\n\t\t\t (blckby_id, blckby_name, blckby_blocker, blckby_timestamp, blckby_expire, blckby_exact, blckby_create, blckby_reason)\n\t\t\t VALUES (null,\n\t\t\t\t {$dbw->addQuotes($this->mRegexBlockedAddress)},\n\t\t\t\t {$dbw->addQuotes($name)},\n\t\t\t\t '{$timestamp}',\n\t\t\t\t '{$expiry}',\n\t\t\t\t {$this->mRegexBlockedExact},\n\t\t\t\t {$this->mRegexBlockedCreation},\n\t\t\t\t {$dbw->addQuotes($this->mRegexBlockedReason)}\n\t\t\t\t )"; $dbw->query($query); /* duplicate entry */ if (!$dbw->affectedRows()) { $this->showForm(wfMsg('regexblock-already-blocked', $this->mRegexBlockedAddress)); return; } wfRegexBlockUnsetKeys($name, $this->mRegexBlockedAddress); /* redirect */ $titleObj = Title::makeTitle(NS_SPECIAL, 'Regexblock'); $wgOut->redirect($titleObj->getFullURL('action=success_block&ip=' . urlencode($this->mRegexBlockedAddress) . "&" . wfGetListBits())); }
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; }