Пример #1
0
 function filter(&$title, $text, $section)
 {
     global $wgArticle, $wgVersion, $wgOut, $wgParser, $wgUser;
     $fname = 'wfSpamBlacklistFilter';
     wfProfileIn($fname);
     # Call the rest of the hook chain first
     if ($this->previousFilter) {
         $f = $this->previousFilter;
         if ($f($title, $text, $section)) {
             wfProfileOut($fname);
             return true;
         }
     }
     $this->title = $title;
     $this->text = $text;
     $this->section = $section;
     $regexes = $this->getRegexes();
     $whitelists = $this->getWhitelists();
     if (is_array($regexes)) {
         # Run parser to strip SGML comments and such out of the markup
         # This was being used to circumvent the filter (see bug 5185)
         $options = new ParserOptions();
         $text = $wgParser->preSaveTransform($text, $title, $wgUser, $options);
         $out = $wgParser->parse($text, $title, $options);
         $links = implode("\n", array_keys($out->getExternalLinks()));
         # Strip whitelisted URLs from the match
         if (is_array($whitelists)) {
             wfDebug("Excluding whitelisted URLs from " . count($whitelists) . " regexes: " . implode(', ', $whitelists) . "\n");
             foreach ($whitelists as $regex) {
                 $links = preg_replace($regex, '', $links);
             }
         }
         # Do the match
         wfDebug("Checking text against " . count($regexes) . " regexes: " . implode(', ', $regexes) . "\n");
         $retVal = false;
         foreach ($regexes as $regex) {
             if (preg_match($regex, $links, $matches)) {
                 wfDebug("Match!\n");
                 EditPage::spamPage($matches[0]);
                 $retVal = true;
                 break;
             }
         }
     } else {
         $retVal = false;
     }
     wfProfileOut($fname);
     return $retVal;
 }
 function filter(&$title, $text, $section)
 {
     global $wgArticle, $wgVersion, $wgOut;
     $fname = 'wfSpamBlacklistFilter';
     wfProfileIn($fname);
     # Call the rest of the hook chain first
     if ($this->previousFilter) {
         $f = $this->previousFilter;
         if ($f($title, $text, $section)) {
             wfProfileOut($fname);
             return true;
         }
     }
     $this->title = $title;
     $this->text = $text;
     $this->section = $section;
     $regex =& $this->getRegex();
     if ($regex && $regex[0] == '/') {
         # Do the match
         wfDebug("Checking text against regex: {$regex}\n");
         if (preg_match($regex, $text, $matches)) {
             wfDebug("Match!\n");
             EditPage::spamPage($matches[0]);
             $retVal = true;
         } else {
             $retVal = false;
         }
     } else {
         $retVal = false;
     }
     wfProfileOut($fname);
     return $retVal;
 }