/** * Performs spam check for 3rd party extension. Third parameter will be provided with matching block data * * @param $text string content to check for spam * @param $typeId int block type (see Phalanx::TYPE_* constants) * @param $blockData array array to be provided with matching block details (pass as a reference) * @return boolean spam check result * * @author macbre */ public static function onSpamFilterCheck($text, $typeId, &$blockData) { wfProfileIn(__METHOD__); if ($text === '') { wfProfileOut(__METHOD__); return true; } if (!$typeId) { $typeId = PhalanxModel::determineTypeId($text); } $model = PhalanxModel::newFromType($typeId, $text); if (is_null($model)) { throw new WikiaException("Unsupported block type passed - #{$typeId}"); } // get type ID -> type mapping $types = Phalanx::getAllTypeNames(); $ret = $model->match($types[$typeId]); // pass matching block details if ($ret === false) { $blockData = (array) $model->getBlock(); wfDebug(__METHOD__ . ": spam check blocked '{$text}'\n"); } wfProfileOut(__METHOD__); return $ret; }
public function matchBlock() { if (!$this->userCanExecute($this->wg->User)) { $this->displayRestrictionError(); return; } $result = array(); $token = $this->request->getVal('token'); $block = $this->request->getVal('block'); if ($token == $this->getToken()) { foreach (Phalanx::getAllTypeNames() as $type => $typeName) { $blocks = $this->service->match($type, $block); if (!empty($blocks)) { $result[$type] = $blocks; } } } $this->setVal('blocks', $result); }
/** * testBlock * * performs a test of all available phalanx filters and returns warning message if there are any * @author Kamil Koterba <*****@*****.**> * * @param $text String to match * @return String with HTML to display via AJAX */ public static function testBlock($text) { wfProfileIn(__METHOD__); if (!class_exists('PhalanxService')) { wfProfileOut(__METHOD__); return ''; } $service = new PhalanxService(); $blockFound = false; foreach (Phalanx::getAllTypeNames() as $blockType) { $res = $service->match($blockType, $text); if (!empty($res)) { $blockFound = true; break; } } $warning = ''; if ($blockFound) { $phalanxTestTitle = SpecialPage::getTitleFor('Phalanx', 'test'); $linkToTest = Linker::link($phalanxTestTitle, wfMessage('userrenametool-see-list-of-blocks')->escaped(), [], ['wpBlockText' => $text]); $warning = wfMessage('userrenametool-warning-phalanx-block', $text)->rawParams($linkToTest)->escaped(); } wfProfileOut(__METHOD__); return $warning; }