function wfFetchSpamRegexData($mode) { global $wgMemc, $wgUser, $wgSpamRegex, $wgSharedDB; $phrases = ""; $first = true; /* first, check if regex string is already stored in memcache */ $mode == SPAMREGEX_SUMMARY ? $key_clause = ":Summary" : ($key_clause = ":Textbox"); $key = "{$wgSharedDB}:spamRegexCore:spamRegex" . $key_clause; $cached = $wgMemc->get($key); if (!$cached) { /* fetch data from db, concatenate into one string, then fill cache */ $mode == SPAMREGEX_SUMMARY ? $clause = " WHERE spam_summary = 1" : ($clause = " WHERE spam_textbox = 1"); $dbr =& wfGetDB(DB_SLAVE); $query = "SELECT spam_text FROM " . wfSpamRegexGetTable() . $clause; $res = $dbr->query($query); while ($row = $dbr->fetchObject($res)) { $concat = $row->spam_text; if (!$first) { $phrases .= "|" . $concat; } else { $phrases .= $concat; $first = false; } } $wgMemc->set($key, $phrases, 0); $dbr->freeResult($res); } else { /* take from cache */ $phrases = $cached; } return $phrases; }
function doSubmit() { global $wgOut, $wgUser, $wgMemc; /* empty name */ if (strlen($this->mBlockedPhrase) == 0) { $this->showForm(wfMsgHtml('spamregex-warning-1')); return; } /* validate expression */ if (!($simple_regex = wfValidRegex($this->mBlockedPhrase))) { $this->showForm(wfMsgHtml('spamregex-error-1')); return; } /* make insert */ $dbw =& wfGetDB(DB_MASTER); $name = $wgUser->getName(); $timestamp = wfTimestampNow(); /* we need at least one block mode specified... we can have them both, of course */ if ($this->mBlockedTextbox == 0 && $this->mBlockedSummary == 0) { $this->showForm(wfMsgHtml('spamregex-warning-2')); return; } $query = "INSERT IGNORE INTO " . wfSpamRegexGetTable() . " (spam_id, spam_text, spam_timestamp, spam_user, spam_textbox, spam_summary)\n\t\t\t VALUES (null,\n\t\t\t \t {$dbw->addQuotes($this->mBlockedPhrase)},\n\t\t\t\t {$timestamp},\n\t\t\t\t {$dbw->addQuotes($name)},\n\t\t\t\t {$this->mBlockedTextbox},\n\t\t\t\t {$this->mBlockedSummary}\n\t\t\t\t )"; $dbw->query($query); /* duplicate entry */ if (!$dbw->affectedRows()) { $this->showForm(wfMsgHtml('spamregex-already-blocked', $this->mBlockedPhrase)); return; } wfSpamRegexUnsetKeys($name); /* redirect */ $titleObj = Title::makeTitle(NS_SPECIAL, 'Spamregex'); $wgOut->redirect($titleObj->getFullURL('action=success_block&text=' . urlencode($this->mBlockedPhrase) . "&" . wfSpamRegexGetListBits())); }