Quick amd dirty spam filtering. We'll build something better in due time.

This commit is contained in:
Alexey Verkhovsky 2006-03-20 01:36:45 +00:00
parent faf0c51218
commit d051b174f8

View file

@ -229,6 +229,7 @@ class WikiController < ApplicationController
cookies['author'] = { :value => author_name, :expires => Time.utc(2030) } cookies['author'] = { :value => author_name, :expires => Time.utc(2030) }
begin begin
filter_spam(@params['content'])
if @page if @page
wiki.revise_page(@web_name, @page_name, @params['content'], Time.now, wiki.revise_page(@web_name, @page_name, @params['content'], Time.now,
Author.new(author_name, remote_ip), PageRenderer.new) Author.new(author_name, remote_ip), PageRenderer.new)
@ -404,4 +405,20 @@ class WikiController < ApplicationController
if text.length > length then text[0..(length - 3)] + truncate_string else text end if text.length > length then text[0..(length - 3)] + truncate_string else text end
end end
def filter_spam(content)
@@spam_patterns ||= load_spam_patterns
@@spam_patterns.each do |pattern|
raise "Your edit was blocked by spam filtering" if content =~ pattern
end
end
def load_spam_patterns
spam_patterns_file = "#{RAILS_ROOT}/config/spam_patterns.txt"
if File.exists?(spam_patterns_file)
File.readlines(spam_patterns_file).inject([]) { |patterns, line| patterns << Regexp.new(line.chomp, Regexp::IGNORECASE) }
else
[]
end
end
end end