public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
Normalized the parameters to the different spam detection engines.

They always expect the permalink_url, followed by the comment object 
itself.
francois (author)
Mon Mar 03 04:05:35 -0800 2008
commit  73408ff31f8185ce80b5dfb4a48933501ec60e43
tree    9b11676014ce1973878678c8b5e7314cda93c335
parent  e570abd0a08dd9be0423496deeb135c36cfd6537
...
60
61
62
63
 
64
65
66
67
 
68
69
70
71
 
72
73
74
...
60
61
62
 
63
64
65
66
 
67
68
69
70
 
71
72
73
74
0
@@ -60,15 +60,15 @@ class Comment < Content
0
   end
0
 
0
   def check_approval(site, request)
0
- self.approved = site.approve_comments? || spam_engine(site).ham?(self, request)
0
+ self.approved = site.approve_comments? || spam_engine(site).ham?(article.permalink_url(site, request), self)
0
   end
0
 
0
   def mark_as_spam(site, request)
0
- spam_engine(site).mark_as_spam(self, request)
0
+ spam_engine(site).mark_as_spam(article.permalink_url(site, request), self)
0
   end
0
   
0
   def mark_as_ham(site, request)
0
- spam_engine(site).mark_as_ham(self, request)
0
+ spam_engine(site).mark_as_ham(article.permalink_url(site, request), self)
0
   end
0
 
0
   protected
...
9
10
11
12
 
13
14
15
16
17
 
18
19
20
21
22
 
23
24
25
...
9
10
11
 
12
13
14
15
16
 
17
18
19
20
21
 
22
23
24
25
0
@@ -9,17 +9,17 @@ module Mephisto
0
       end
0
 
0
       # Determines if a single comment is either ham or spam.
0
- def ham?(request, comment)
0
+ def ham?(permalink_url, comment)
0
         raise SubclassResponsibilityError
0
       end
0
 
0
       # Marks false positives as ham.
0
- def mark_as_ham(comment)
0
+ def mark_as_ham(permalink_url, comment)
0
         raise SubclassResponsibilityError
0
       end
0
 
0
       # Marks false negatives as spam.
0
- def mark_as_spam(comment)
0
+ def mark_as_spam(permalink_url, comment)
0
         raise SubclassResponsibilityError
0
       end
0
 
...
1
2
3
4
 
5
6
 
7
8
9
10
 
 
 
11
12
13
14
 
 
 
15
16
17
...
27
28
29
30
31
32
33
34
35
 
36
37
38
39
 
40
41
42
...
1
2
3
 
4
5
 
6
7
8
 
 
9
10
11
12
13
 
 
14
15
16
17
18
19
...
29
30
31
 
 
 
 
 
 
32
33
34
35
 
36
37
38
39
0
@@ -1,17 +1,19 @@
0
 module Mephisto
0
   module SpamDetectionEngines
0
     class AkismetEngine < Mephisto::SpamDetectionEngine::Base
0
- def ham?(request, comment)
0
+ def ham?(permalink_url, comment)
0
         check_valid!
0
- !akismet.comment_check(comment_spam_options(request, comment))
0
+ !akismet.comment_check(comment_spam_options(permalink_url, comment))
0
       end
0
 
0
- def mark_as_ham(comment, request)
0
- mark_comment(:ham, comment, request)
0
+ def mark_as_ham(permalink_url, comment)
0
+ check_valid!
0
+ akismet.submit_ham(comment_spam_options(permalink_url, comment))
0
       end
0
 
0
- def mark_as_spam(comment, request)
0
- mark_comment(:spam, comment, request)
0
+ def mark_as_spam(permalink_url, comment)
0
+ check_valid!
0
+ akismet.submit_spam(comment_spam_options(permalink_url, comment))
0
       end
0
 
0
       def valid?
0
@@ -27,16 +29,11 @@ module Mephisto
0
         @akismet ||= ::Akismet.new(options[:akismet_key], options[:akismet_url])
0
       end
0
 
0
- def mark_comment(comment_type, site, request)
0
- check_valid!
0
- response = akismet.send("submit_#{comment_type}", comment_spam_options(site, request))
0
- end
0
-
0
- def comment_spam_options(request, comment)
0
+ def comment_spam_options(permalink_url, comment)
0
         { :user_ip => comment.author_ip,
0
           :user_agent => comment.user_agent,
0
           :referrer => comment.referrer,
0
- :permalink => "http://#{request.host_with_port}#{site.permalink_for(comment)}",
0
+ :permalink => permalink_url,
0
           :comment_author => comment.author,
0
           :comment_author_email => comment.author_email,
0
           :comment_author_url => comment.author_url,
...
9
10
11
12
 
13
14
15
...
21
22
23
24
 
25
26
27
...
31
32
33
34
35
 
 
36
37
38
39
 
 
40
41
42
...
46
47
48
49
 
50
51
52
...
9
10
11
 
12
13
14
15
...
21
22
23
 
24
25
26
27
...
31
32
33
 
 
34
35
36
37
 
 
38
39
40
41
42
...
46
47
48
 
49
50
51
52
0
@@ -9,7 +9,7 @@ module Mephisto
0
         defensio.validate_key.success?
0
       end
0
 
0
- def ham?(request, comment)
0
+ def ham?(permalink_url, comment)
0
         response = defensio.audit_comment(
0
           # Required parameters
0
           :user_ip => comment.author_ip,
0
@@ -21,7 +21,7 @@ module Mephisto
0
           :comment_content => comment.body,
0
           :comment_author_email => comment.author_email,
0
           :comment_author_url => comment.author_url,
0
- :permalink => "http://#{request.host_with_port}#{site.permalink_for(comment)}",
0
+ :permalink => permalink_url,
0
           :referrer => comment.referrer,
0
           :user_logged_in => false,
0
           :trusted_user => false
0
@@ -31,12 +31,12 @@ module Mephisto
0
         !response.spam
0
       end
0
 
0
- def mark_as_ham(request, comment)
0
- defensio.report_false_positives(:signatures => comment.spam_engine_data[:signature])
0
+ def mark_as_ham(permalink_url, comment)
0
+ defensio.report_false_positives(:signatures => [comment.spam_engine_data[:signature]])
0
       end
0
 
0
- def mark_as_spam(request, comment)
0
- defensio.report_false_negatives(:signatures => comment.spam_engine_data[:signature])
0
+ def mark_as_spam(permalink_url, comment)
0
+ defensio.report_false_negatives(:signatures => [comment.spam_engine_data[:signature]])
0
       end
0
 
0
       # The Defensio service supports statistics.
0
@@ -46,7 +46,7 @@ module Mephisto
0
       protected
0
       def defensio
0
         begin
0
- @defensio ||= Defensio::Client.new(:owner_url => options[:defensio_url], :api_key => options[:defensio_key])
0
+ @defensio ||= Defensio::Client.new(:owner_url => options[:defensio_url], :api_key => options[:defensio_key])
0
         rescue Defensio::InvalidAPIKey
0
           logger.warn { $! }
0
           logger.warn { $!.backtrace.join("\n") }
...
10
11
12
13
14
15
16
...
19
20
21
22
 
23
24
25
...
10
11
12
 
13
14
15
...
18
19
20
 
21
22
23
24
0
@@ -10,7 +10,6 @@ context "A properly configured Mephisto::SpamDetectionEngines::AkismetEngine" do
0
     @request = stub("request", :host_with_port => "")
0
     @comment = Comment.new
0
     @akismet = stub("akismet", :comment_check => false)
0
- @site.stub!(:permalink_for).and_return("")
0
   end
0
 
0
   specify "should be #valid?" do
0
@@ -19,7 +18,7 @@ context "A properly configured Mephisto::SpamDetectionEngines::AkismetEngine" do
0
 
0
   specify "should instantiate an Akismet when calling #ham?" do
0
     Akismet.should_receive(:new).and_return(@akismet)
0
- @engine.ham?(@request, @comment)
0
+ @engine.ham?("http://permalink.url/", @comment)
0
   end
0
 end
0
   
...
71
72
73
 
 
 
 
 
 
74
75
76
77
78
79
 
 
 
 
 
 
80
81
82
...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
0
@@ -71,12 +71,24 @@ context "A Mephisto::SpamDetectionEngines::DefensioEngine" do
0
     @site.save(false)
0
     assert !@site.spam_engine.valid?
0
   end
0
+
0
+ specify "should not be #valid? when the defensio key is blank" do
0
+ @site.spam_engine_options[:defensio_key] = ""
0
+ @site.save(false)
0
+ assert !@site.spam_engine.valid?
0
+ end
0
   
0
   specify "should not be #valid? when the defensio url is missing from the options" do
0
     @site.spam_engine_options.delete(:defensio_url)
0
     @site.save(false)
0
     assert !@site.spam_engine.valid?
0
   end
0
+
0
+ specify "should not be #valid? when the defensio url is blank" do
0
+ @site.spam_engine_options[:defensio_url] = ""
0
+ @site.save(false)
0
+ assert !@site.spam_engine.valid?
0
+ end
0
 end
0
 
0
 context "A Mephisto::SpamDetectionEngines::DefensioEngine instantiated from a Site with a missing :defensio_key" do

Comments

    No one has commented yet.