Class: Wiki2Go::SpamFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/Wiki2Go/SpamFilter.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SpamFilter

Returns a new instance of SpamFilter.



9
10
11
# File 'lib/Wiki2Go/SpamFilter.rb', line 9

def initialize(config)
  @config = config
end

Instance Method Details

#added_urls(original_content, modified_content) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/Wiki2Go/SpamFilter.rb', line 31

def added_urls(original_content, modified_content)
  url_finder = Wiki2Go::UrlFinder.new

  old_urls = url_finder.urls_in(original_content)
  new_urls = url_finder.urls_in(modified_content)
  urls = new_urls - old_urls
  urls
end

#blacklist_url(url) ⇒ Object



46
47
48
49
# File 'lib/Wiki2Go/SpamFilter.rb', line 46

def blacklist_url(url)
  banned_urls.add(url)
  @config.storage.save_list(banned_urls)
end

#blacklist_urls(urls) ⇒ Object



51
52
53
54
55
56
# File 'lib/Wiki2Go/SpamFilter.rb', line 51

def blacklist_urls(urls)
  urls.each do |url|
    banned_urls.add(url)
  end
  @config.storage.save_list(banned_urls)
end

#blacklist_user(author) ⇒ Object



40
41
42
43
44
# File 'lib/Wiki2Go/SpamFilter.rb', line 40

def blacklist_user(author)
  bad_users = banned_users
  bad_users.add(author)
  @config.storage.save_list(bad_users)
end

#blacklist_user_and_urls_added(author, original, new_content) ⇒ Object



58
59
60
61
62
# File 'lib/Wiki2Go/SpamFilter.rb', line 58

def blacklist_user_and_urls_added(author,original,new_content)
  blacklist_user(author)
  new_urls = added_urls(original,new_content)
  blacklist_urls(new_urls)
end

#edit_by_banned_user?(author) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/Wiki2Go/SpamFilter.rb', line 13

def edit_by_banned_user?(author)
  @config.log("Checking if '#{author}' is banned") 
  banned = banned_users.contains(author)
  @config.log("Checking if '#{author}' is banned. Done.")
  banned 
end

#edit_contains_banned_url?(content) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/Wiki2Go/SpamFilter.rb', line 20

def edit_contains_banned_url?(content)
  @config.log("Checking if '#{content}' is banned") 
  banned = banned_urls.found_in(content) || chonqed_urls.found_in(content)
  @config.log("Checking if '#{content}' is banned. Done")
  banned 
end

#greylist_new_urls(author, original, new_content) ⇒ Object



64
65
66
67
# File 'lib/Wiki2Go/SpamFilter.rb', line 64

def greylist_new_urls(author,original,new_content)
  new_urls = added_urls(original,new_content)
  greylist_urls(author,new_urls)
end

#greylist_suspectsObject



83
84
85
# File 'lib/Wiki2Go/SpamFilter.rb', line 83

def greylist_suspects
  greylist.suspects
end

#greylist_urls(author, new_urls) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/Wiki2Go/SpamFilter.rb', line 69

def greylist_urls(author,new_urls)
  if new_urls.length > 0 then    
    list = greylist
    new_urls.each do |url|
      list.add(author,url)
    end
    @config.storage.save_list(list)
  end
end

#greylisted_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/Wiki2Go/SpamFilter.rb', line 79

def greylisted_url?(url)
  greylist.contains_url?(url)
end

#remove_from_greylist(author, url) ⇒ Object



87
88
89
90
# File 'lib/Wiki2Go/SpamFilter.rb', line 87

def remove_from_greylist(author,url)
  greylist.remove(author,url)
  @config.storage.save_list(greylist)
end

#too_many_new_urls?(original_content, modified_content, max_new_urls) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/Wiki2Go/SpamFilter.rb', line 27

def too_many_new_urls?(original_content, modified_content,max_new_urls)
  return added_urls(original_content,modified_content).size > max_new_urls
end

#update_chongqedObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/Wiki2Go/SpamFilter.rb', line 92

def update_chongqed
  output = 'Updating blacklist'
  response = Net::HTTP.get_response('blacklist.chongqed.org','/index.html')
  if response.code == '200' then
    output = response.body
    @config.storage.update_chongqed_spamlist(output)
  else
    output = "Error code #{response.code}: #{response.message}"
  end
  output
end