Quick amd dirty spam filtering. We'll build something better in due time.
This commit is contained in:
parent
faf0c51218
commit
d051b174f8
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue