jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jalka...@apache.org
Subject svn commit: r743866 - in /incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH: ChangeLog src/com/ecyrd/jspwiki/Release.java src/com/ecyrd/jspwiki/filters/SpamFilter.java
Date Thu, 12 Feb 2009 20:23:12 GMT
Author: jalkanen
Date: Thu Feb 12 20:23:11 2009
New Revision: 743866

URL: http://svn.apache.org/viewvc?rev=743866&view=rev
Log:
JSPWIKI-500: No longer submits removal-only changes to Akismet.

Modified:
    incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog
    incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java
    incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/filters/SpamFilter.java

Modified: incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog?rev=743866&r1=743865&r2=743866&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog Thu Feb 12 20:23:11 2009
@@ -1,3 +1,10 @@
+2008-02-12  Janne Jalkanen <jalkanen@apache.org>
+
+        * 2.8.2-svn-11
+        
+        * JSPWIKI-500: Spam containing only deletions is no longer sent
+        to Akismet.
+
 2009-02-09  Harry Metske <metskem@apache.org>
 
         * 2.8.2-svn-10

Modified: incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java?rev=743866&r1=743865&r2=743866&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java Thu Feb
12 20:23:11 2009
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "10";
+    public static final String     BUILD         = "11";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/filters/SpamFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/filters/SpamFilter.java?rev=743866&r1=743865&r2=743866&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/filters/SpamFilter.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/filters/SpamFilter.java
Thu Feb 12 20:23:11 2009
@@ -298,7 +298,7 @@
         cleanBanList();
         refreshBlacklists(context);
 
-        String change = getChange( context, content );
+        Change change = getChange( context, content );
 
         if(!ignoreThisUser(context))
         {
@@ -318,7 +318,7 @@
             }
         }
 
-        log( context, ACCEPT, "-", change );
+        log( context, ACCEPT, "-", change.toString() );
         return content;
     }
 
@@ -433,7 +433,7 @@
      *  @param content
      *  @throws RedirectException
      */
-    private synchronized void checkSinglePageChange( WikiContext context, String content,
String change )
+    private synchronized void checkSinglePageChange( WikiContext context, String content,
Change change )
         throws RedirectException
     {
         HttpServletRequest req = context.getHttpRequest();
@@ -444,7 +444,7 @@
             int hostCounter = 0;
             int changeCounter = 0;
 
-            log.debug("Change is "+change);
+            log.debug("Change is "+change.m_change);
 
             long time = System.currentTimeMillis()-60*1000L; // 1 minute
 
@@ -490,7 +490,7 @@
 
                 m_temporaryBanList.add( host );
 
-                String uid = log( context, REJECT, REASON_TOO_MANY_MODIFICATIONS, change
);
+                String uid = log( context, REJECT, REASON_TOO_MANY_MODIFICATIONS, change.m_change
);
                 log.info( "SPAM:TooManyModifications ("+uid+"). Added host "+addr+" to temporary
ban list for doing too many modifications/minute" );
                 checkStrategy( context, REASON_TOO_MANY_MODIFICATIONS, "Herb says you look
like a spammer, and I trust Herb! (Incident code "+uid+")" );
             }
@@ -501,7 +501,7 @@
 
                 m_temporaryBanList.add( host );
 
-                String uid = log( context, REJECT, REASON_SIMILAR_MODIFICATIONS, change );
+                String uid = log( context, REJECT, REASON_SIMILAR_MODIFICATIONS, change.m_change
);
 
                 log.info("SPAM:SimilarModifications ("+uid+"). Added host "+addr+" to temporary
ban list for doing too many similar modifications" );
                 checkStrategy( context, REASON_SIMILAR_MODIFICATIONS, "Herb says you look
like a spammer, and I trust Herb! (Incident code "+uid+")");
@@ -511,7 +511,7 @@
             //  Calculate the number of links in the addition.
             //
 
-            String tstChange = change;
+            String tstChange = change.toString();
             int    urlCounter = 0;
 
             while( m_matcher.contains(tstChange,m_urlPattern) )
@@ -529,7 +529,7 @@
 
                 m_temporaryBanList.add( host );
 
-                String uid = log( context, REJECT, REASON_TOO_MANY_URLS, change );
+                String uid = log( context, REJECT, REASON_TOO_MANY_URLS, change.toString()
);
 
                 log.info("SPAM:TooManyUrls ("+uid+"). Added host "+addr+" to temporary ban
list for adding too many URLs" );
                 checkStrategy( context, REASON_TOO_MANY_URLS, "Herb says you look like a
spammer, and I trust Herb! (Incident code "+uid+")" );
@@ -566,7 +566,7 @@
      * @param change
      * @throws RedirectException
      */
-    private void checkAkismet( WikiContext context, String change )
+    private void checkAkismet( WikiContext context, Change change )
         throws RedirectException
     {
         if( m_akismetAPIKey != null )
@@ -587,6 +587,15 @@
 
             HttpServletRequest req = context.getHttpRequest();
 
+            //
+            //  Akismet will mark all empty statements as spam, so we'll just
+            //  ignore them.
+            //
+            if( change.m_adds == 0 && change.m_removals > 0 )
+            {
+                return;
+            }
+            
             if( req != null && m_akismet != null )
             {
                 log.debug("Calling Akismet to check for spam...");
@@ -611,7 +620,7 @@
                                                          commentAuthor,
                                                          commentAuthorEmail,
                                                          commentAuthorURL,
-                                                         change,
+                                                         change.toString(),
                                                          null );
 
                 sw.stop();
@@ -624,7 +633,7 @@
 
                     // m_temporaryBanList.add( host );
 
-                    String uid = log( context, REJECT, REASON_AKISMET, change );
+                    String uid = log( context, REJECT, REASON_AKISMET, change.toString()
);
 
                     log.info("SPAM:Akismet ("+uid+"). Akismet thinks this change is spam;
added host to temporary ban list.");
 
@@ -653,7 +662,7 @@
      *  @param change
      * @throws RedirectException
      */
-    private void checkBotTrap( WikiContext context, String change ) throws RedirectException
+    private void checkBotTrap( WikiContext context, Change change ) throws RedirectException
     {
         HttpServletRequest request = context.getHttpRequest();
 
@@ -662,7 +671,7 @@
             String unspam = request.getParameter( getBotFieldName() );
             if( unspam != null && unspam.length() > 0 )
             {
-                String uid = log( context, REJECT, REASON_BOT_TRAP, change );
+                String uid = log( context, REJECT, REASON_BOT_TRAP, change.toString() );
 
                 log.info("SPAM:BotTrap ("+uid+").  Wildly behaving bot detected.");
 
@@ -672,7 +681,7 @@
         }
     }
 
-    private void checkUTF8( WikiContext context, String change ) throws RedirectException
+    private void checkUTF8( WikiContext context, Change change ) throws RedirectException
     {
         HttpServletRequest request = context.getHttpRequest();
 
@@ -682,7 +691,7 @@
 
             if( utf8field != null && !utf8field.equals("\u3041") )
             {
-                String uid = log( context, REJECT, REASON_UTF8_TRAP, change );
+                String uid = log( context, REJECT, REASON_UTF8_TRAP, change.toString() );
 
                 log.info("SPAM:UTF8Trap ("+uid+").  Wildly posting dumb bot detected.");
 
@@ -717,7 +726,7 @@
      *  @throws RedirectException
      */
 
-    private void checkBanList( WikiContext context, String change )
+    private void checkBanList( WikiContext context, Change change )
         throws RedirectException
     {
         HttpServletRequest req = context.getHttpRequest();
@@ -736,7 +745,7 @@
                 {
                     long timeleft = (host.getReleaseTime() - now) / 1000L;
 
-                    log( context, REJECT, REASON_IP_BANNED_TEMPORARILY, change );
+                    log( context, REJECT, REASON_IP_BANNED_TEMPORARILY, change.m_change );
 
                     checkStrategy( context, REASON_IP_BANNED_TEMPORARILY, "You have been
temporarily banned from modifying this wiki. ("+timeleft+" seconds of ban left)");
                 }
@@ -829,7 +838,7 @@
      *  @param change
      *  @throws RedirectException
      */
-    private void checkPatternList(WikiContext context, String content, String change) throws
RedirectException
+    private void checkPatternList(WikiContext context, String content, Change change) throws
RedirectException
     {
         //
         //  If we have no spam patterns defined, or we're trying to save
@@ -840,19 +849,21 @@
             return;
         }
 
+        String ch = change.toString();
+        
         if( context.getHttpRequest() != null )
-            change += context.getHttpRequest().getRemoteAddr();
+            ch += context.getHttpRequest().getRemoteAddr();
 
         for( Pattern p : m_spamPatterns )
         {
             // log.debug("Attempting to match page contents with "+p.getPattern());
 
-            if( m_matcher.contains( change, p ) )
+            if( m_matcher.contains( ch, p ) )
             {
                 //
                 //  Spam filter has a match.
                 //
-                String uid = log( context, REJECT, REASON_REGEXP+"("+p.getPattern()+")",
change);
+                String uid = log( context, REJECT, REASON_REGEXP+"("+p.getPattern()+")",
ch);
 
                 log.info("SPAM:Regexp ("+uid+"). Content matches the spam filter '"+p.getPattern()+"'");
 
@@ -861,6 +872,13 @@
         }
     }
 
+    private void checkPatternList(WikiContext context, String content, String change ) throws
RedirectException
+    {
+        Change c = new Change();
+        c.m_change = change;
+        checkPatternList(context,content,c);
+    }
+ 
     /**
      *  Creates a simple text string describing the added content.
      *
@@ -868,13 +886,15 @@
      *  @param newText
      *  @return Empty string, if there is no change.
      */
-    private static String getChange( WikiContext context, String newText )
+    private static Change getChange( WikiContext context, String newText )
     {
         WikiPage page = context.getPage();
         StringBuffer change = new StringBuffer();
         WikiEngine engine = context.getEngine();
         // Get current page version
 
+        Change ch = new Change();
+        
         try
         {
             String oldText = engine.getPureText(page.getName(), WikiProvider.LATEST_VERSION);
@@ -885,10 +905,9 @@
 
             if( rev == null || rev.size() == 0 )
             {
-                return "";
+                return ch;
             }
-
-
+            
             for( int i = 0; i < rev.size(); i++ )
             {
                 Delta d = rev.getDelta(i);
@@ -896,10 +915,16 @@
                 if( d instanceof AddDelta )
                 {
                     d.getRevised().toString( change, "", "\r\n" );
+                    ch.m_adds++;
                 }
                 else if( d instanceof ChangeDelta )
                 {
                     d.getRevised().toString( change, "", "\r\n" );
+                    ch.m_adds++;
+                }
+                else if( d instanceof DeleteDelta )
+                {
+                    ch.m_removals++;
                 }
             }
         }
@@ -928,7 +953,8 @@
             change.append("\r\n"+page.getAuthor());
         }
 
-        return change.toString();
+        ch.m_change = change.toString();
+        return ch;
     }
 
     /**
@@ -1100,9 +1126,9 @@
         {
             if( pageContext.getAttribute( hashName ) == null )
             {
-                String change = getChange( context, EditorManager.getEditedText( pageContext
) );
+                Change change = getChange( context, EditorManager.getEditedText( pageContext
) );
 
-                log( context, REJECT, "MissingHash", change );
+                log( context, REJECT, "MissingHash", change.m_change );
 
                 String redirect = context.getURL(WikiContext.VIEW,"SessionExpired");
                 ((HttpServletResponse)pageContext.getResponse()).sendRedirect( redirect );
@@ -1145,7 +1171,7 @@
         private  long m_addedTime = System.currentTimeMillis();
         private  long m_releaseTime;
         private  String m_address;
-        private  String m_change;
+        private  Change m_change;
 
         public String getAddress()
         {
@@ -1162,12 +1188,12 @@
             return m_addedTime;
         }
 
-        public String getChange()
+        public Change getChange()
         {
             return m_change;
         }
 
-        public Host( String ipaddress, String change )
+        public Host( String ipaddress, Change change )
         {
             m_address = ipaddress;
             m_change  = change;
@@ -1175,4 +1201,29 @@
             m_releaseTime = System.currentTimeMillis() + m_banTime * 60 * 1000L;
         }
     }
+    
+    private static class Change
+    {
+        public String m_change;
+        public int    m_adds;
+        public int    m_removals;
+        
+        public String toString()
+        {
+            return m_change;
+        }
+        
+        public boolean equals(Object o)
+        {
+            if( o instanceof Change )
+                return m_change.equals( ((Change)o).m_change);
+            
+            return false;
+        }
+        
+        public int hashCode()
+        {
+            return m_change.hashCode()+17;
+        }
+    }
 }



Mime
View raw message