You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ja...@apache.org on 2009/02/14 18:36:48 UTC
svn commit: r744546 - in /incubator/jspwiki/trunk: ChangeLog
src/java/org/apache/wiki/Release.java
src/java/org/apache/wiki/filters/SpamFilter.java
Author: jalkanen
Date: Sat Feb 14 17:36:47 2009
New Revision: 744546
URL: http://svn.apache.org/viewvc?rev=744546&view=rev
Log:
JSPWIKI-500: SpamFilter no longer calls Akismet on deletions.
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=744546&r1=744545&r2=744546&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sat Feb 14 17:36:47 2009
@@ -1,3 +1,9 @@
+2009-02-14 Janne Jalkanen <ja...@apache.org>
+
+ * 3.0.0-svn-69
+
+ * JSPWIKI-500: SpamFilter no longer calls Akismet on deletions.
+
2009-02-14 Harry Metske <me...@apache.org>
* 3.0.0-svn-68
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=744546&r1=744545&r2=744546&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Sat Feb 14 17:36:47 2009
@@ -77,7 +77,7 @@
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "68";
+ public static final String BUILD = "69";
/**
* This is the generic version string you should use
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java?rev=744546&r1=744545&r2=744546&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java Sat Feb 14 17:36:47 2009
@@ -306,7 +306,7 @@
cleanBanList();
refreshBlacklists(context);
- String change = getChange( context, content );
+ Change change = getChange( context, content );
if(!ignoreThisUser(context))
{
@@ -326,7 +326,7 @@
}
}
- log( context, ACCEPT, "-", change );
+ log( context, ACCEPT, "-", change.toString() );
return content;
}
@@ -441,7 +441,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();
@@ -452,7 +452,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
@@ -498,7 +498,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+")" );
}
@@ -509,7 +509,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+")");
@@ -519,7 +519,7 @@
// Calculate the number of links in the addition.
//
- String tstChange = change;
+ String tstChange = change.toString();
int urlCounter = 0;
Matcher matcher = m_urlPattern.matcher( tstChange );
@@ -538,7 +538,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+")" );
@@ -575,7 +575,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 )
@@ -596,6 +596,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...");
@@ -620,7 +629,7 @@
commentAuthor,
commentAuthorEmail,
commentAuthorURL,
- change,
+ change.toString(),
null );
sw.stop();
@@ -633,7 +642,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.");
@@ -662,7 +671,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();
@@ -671,7 +680,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.");
@@ -681,7 +690,7 @@
}
}
- private void checkUTF8( WikiContext context, String change ) throws RedirectException
+ private void checkUTF8( WikiContext context, Change change ) throws RedirectException
{
HttpServletRequest request = context.getHttpRequest();
@@ -691,7 +700,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.");
@@ -726,7 +735,7 @@
* @throws RedirectException
*/
- private void checkBanList( WikiContext context, String change )
+ private void checkBanList( WikiContext context, Change change )
throws RedirectException
{
HttpServletRequest req = context.getHttpRequest();
@@ -745,7 +754,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)");
}
@@ -838,7 +847,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
@@ -849,20 +858,22 @@
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());
- Matcher matcher = p.matcher( change );
+ Matcher matcher = p.matcher( ch );
if( matcher.find( ) )
{
//
// Spam filter has a match.
//
- String uid = log( context, REJECT, REASON_REGEXP+"("+p.pattern()+")", change);
+ String uid = log( context, REJECT, REASON_REGEXP+"("+p.pattern()+")", change.toString());
log.info("SPAM:Regexp ("+uid+"). Content matches the spam filter '"+p.pattern()+"'");
@@ -871,6 +882,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.
*
@@ -878,13 +896,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);
@@ -895,10 +915,9 @@
if( rev == null || rev.size() == 0 )
{
- return "";
+ return ch;
}
-
-
+
for( int i = 0; i < rev.size(); i++ )
{
Delta d = rev.getDelta(i);
@@ -906,10 +925,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++;
}
}
}
@@ -938,7 +963,8 @@
change.append("\r\n"+page.getAuthor());
}
- return change.toString();
+ ch.m_change = change.toString();
+ return ch;
}
/**
@@ -1110,9 +1136,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 );
@@ -1155,7 +1181,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()
{
@@ -1172,12 +1198,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;
@@ -1185,4 +1211,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;
+ }
+ }
}