You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2023/04/28 20:40:14 UTC

[jspwiki] branch master updated: Remove unnecessary variables. There re not used in the scope.

This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git


The following commit(s) were added to refs/heads/master by this push:
     new 116c0c236 Remove unnecessary variables. There re not used in the scope.
116c0c236 is described below

commit 116c0c23629ab9f8b80befcf7f8f05bd15b0beeb
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Sun Feb 5 18:16:06 2023 +0100

    Remove unnecessary variables. There re not used in the scope.
---
 .../apache/wiki/content/DefaultPageRenamer.java    | 14 +++----
 .../java/org/apache/wiki/filters/SpamFilter.java   | 46 +++++++++++-----------
 .../apache/wiki/parser/JSPWikiMarkupParser.java    | 11 +++---
 .../wiki/references/DefaultReferenceManager.java   |  5 +--
 4 files changed, 36 insertions(+), 40 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/content/DefaultPageRenamer.java b/jspwiki-main/src/main/java/org/apache/wiki/content/DefaultPageRenamer.java
index 8cb403f5d..16371e4f9 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/content/DefaultPageRenamer.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/content/DefaultPageRenamer.java
@@ -179,11 +179,11 @@ public class DefaultPageRenamer implements PageRenamer {
             final Page p = engine.getManager( PageManager.class ).getPage( pageName );
 
             final String sourceText = engine.getManager( PageManager.class ).getPureText( p );
-            String newText = replaceReferrerString( context, sourceText, fromPage.getName(), toPage.getName() );
+            String newText = replaceReferrerString(sourceText, fromPage.getName(), toPage.getName() );
 
             m_camelCase = TextUtil.getBooleanProperty( engine.getWikiProperties(), MarkupParser.PROP_CAMELCASELINKS, m_camelCase );
             if( m_camelCase ) {
-                newText = replaceCCReferrerString( context, newText, fromPage.getName(), toPage.getName() );
+                newText = replaceCCReferrerString(newText, fromPage.getName(), toPage.getName() );
             }
             
             if( !sourceText.equals( newText ) ) {
@@ -226,7 +226,7 @@ public class DefaultPageRenamer implements PageRenamer {
     /**
      *  Replaces camelcase links.
      */
-    private String replaceCCReferrerString( final Context context, final String sourceText, final String from, final String to ) {
+    private String replaceCCReferrerString( final String sourceText, final String from, final String to ) {
         final StringBuilder sb = new StringBuilder( sourceText.length()+32 );
         final Pattern linkPattern = Pattern.compile( "\\p{Lu}+\\p{Ll}+\\p{Lu}+[\\p{L}\\p{Digit}]*" );
         final Matcher matcher = linkPattern.matcher( sourceText );
@@ -252,7 +252,7 @@ public class DefaultPageRenamer implements PageRenamer {
         return sb.toString();
     }
 
-    private String replaceReferrerString( final Context context, final String sourceText, final String from, final String to ) {
+    private String replaceReferrerString(final String sourceText, final String from, final String to ) {
         final StringBuilder sb = new StringBuilder( sourceText.length()+32 );
         
         // This monstrosity just looks for a JSPWiki link pattern.  But it is pretty cool for a regexp, isn't it?  If you can
@@ -280,9 +280,9 @@ public class DefaultPageRenamer implements PageRenamer {
             final String attr = matcher.group(6);
              
             if( link.isEmpty() ) {
-                text = replaceSingleLink( context, text, from, to );
+                text = replaceSingleLink(text, from, to );
             } else {
-                link = replaceSingleLink( context, link, from, to );
+                link = replaceSingleLink(link, from, to );
                 
                 //  A very simple substitution, but should work for quite a few cases.
                 text = TextUtil.replaceString( text, from, to );
@@ -312,7 +312,7 @@ public class DefaultPageRenamer implements PageRenamer {
     /**
      *  This method does a correct replacement of a single link, taking into account anchors and attachments.
      */
-    private String replaceSingleLink( final Context context, final String original, final String from, final String newlink ) {
+    private String replaceSingleLink(final String original, final String from, final String newlink ) {
         final int hash = original.indexOf( '#' );
         final int slash = original.indexOf( '/' );
         String realLink = original;
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/filters/SpamFilter.java b/jspwiki-main/src/main/java/org/apache/wiki/filters/SpamFilter.java
index c12940119..1160d8b74 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/filters/SpamFilter.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/filters/SpamFilter.java
@@ -314,10 +314,10 @@ public class SpamFilter extends BasePageFilter {
 
         if( !ignoreThisUser( context ) ) {
             checkBanList( context, change );
-            checkSinglePageChange( context, content, change );
+            checkSinglePageChange( context, change );
             checkIPList( context );
-            checkPatternList( context, content, change );
-            checkPageName( context, content, change);
+            checkPatternList( context, change );
+            checkPageName( context);
         }
 
         if( !m_stopAtFirstMatch ) {
@@ -332,7 +332,7 @@ public class SpamFilter extends BasePageFilter {
         return content;
     }
 
-    private void checkPageName( final Context context, final String content, final Change change ) throws RedirectException {
+    private void checkPageName(final Context context ) throws RedirectException {
         final Page page = context.getPage();
         final String pageName = page.getName();
         final int maxlength = Integer.parseInt(m_pageNameMaxLength);
@@ -344,12 +344,12 @@ public class SpamFilter extends BasePageFilter {
             final String uid = log( context, REJECT, REASON_PAGENAME_TOO_LONG + "(" + m_pageNameMaxLength + ")" , pageName);
 
             LOG.info("SPAM:PageNameTooLong (" + uid + "). The length of the page name is too large (" + pageName.length() + " , limit is " + m_pageNameMaxLength + ")");
-            checkStrategy( context, REASON_PAGENAME_TOO_LONG, "Herb says '" + pageName + "' is a bad pageName and I trust Herb! (Incident code " + uid + ")" );
+            checkStrategy( context, "Herb says '" + pageName + "' is a bad pageName and I trust Herb! (Incident code " + uid + ")" );
 
         }
     }
 
-    private void checkStrategy( final Context context, final String error, final String message ) throws RedirectException {
+    private void checkStrategy(final Context context, final String message ) throws RedirectException {
         if( m_stopAtFirstMatch ) {
             throw new RedirectException( message, getRedirectPage( context ) );
         }
@@ -432,11 +432,10 @@ public class SpamFilter extends BasePageFilter {
      * Takes a single page change and performs a load of tests on the content change. An admin can modify anything.
      *
      * @param context page Context
-     * @param content page content
      * @param change page change
      * @throws RedirectException spam filter rejects the page change.
      */
-    private synchronized void checkSinglePageChange( final Context context, final String content, final Change change )
+    private synchronized void checkSinglePageChange(final Context context, final Change change )
     		throws RedirectException {
         final HttpServletRequest req = context.getHttpRequest();
 
@@ -477,7 +476,7 @@ public class SpamFilter extends BasePageFilter {
 
                 final 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 + ")" );
+                checkStrategy( context, "Herb says you look like a spammer, and I trust Herb! (Incident code " + uid + ")" );
             }
 
             if( changeCounter >= m_limitSimilarChanges ) {
@@ -486,7 +485,7 @@ public class SpamFilter extends BasePageFilter {
 
                 final 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+")");
+                checkStrategy( context, "Herb says you look like a spammer, and I trust Herb! (Incident code "+uid+")");
             }
 
             //  Calculate the number of links in the addition.
@@ -504,7 +503,7 @@ public class SpamFilter extends BasePageFilter {
 
                 final 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 + ")" );
+                checkStrategy( context, "Herb says you look like a spammer, and I trust Herb! (Incident code " + uid + ")" );
             }
 
             //  Check bot trap
@@ -582,7 +581,7 @@ public class SpamFilter extends BasePageFilter {
 
                     final 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." );
-                    checkStrategy( context, REASON_AKISMET, "Akismet tells Herb you're a spammer, Herb trusts Akismet, and I trust Herb! (Incident code " + uid + ")" );
+                    checkStrategy( context, "Akismet tells Herb you're a spammer, Herb trusts Akismet, and I trust Herb! (Incident code " + uid + ")" );
                 }
             }
         }
@@ -612,7 +611,7 @@ public class SpamFilter extends BasePageFilter {
                 final String uid = log( context, REJECT, REASON_BOT_TRAP, change.toString() );
 
                 LOG.info( "SPAM:BotTrap (" + uid + ").  Wildly behaving bot detected." );
-                checkStrategy( context, REASON_BOT_TRAP, "Spamming attempt detected. (Incident code " + uid + ")" );
+                checkStrategy( context, "Spamming attempt detected. (Incident code " + uid + ")" );
             }
         }
     }
@@ -625,7 +624,7 @@ public class SpamFilter extends BasePageFilter {
                 final String uid = log( context, REJECT, REASON_UTF8_TRAP, change.toString() );
 
                 LOG.info( "SPAM:UTF8Trap (" + uid + ").  Wildly posting dumb bot detected." );
-                checkStrategy( context, REASON_UTF8_TRAP, "Spamming attempt detected. (Incident code " + uid + ")" );
+                checkStrategy( context, "Spamming attempt detected. (Incident code " + uid + ")" );
             }
         }
     }
@@ -661,7 +660,7 @@ public class SpamFilter extends BasePageFilter {
                     final long timeleft = ( host.getReleaseTime() - now ) / 1000L;
 
                     log( context, REJECT, REASON_IP_BANNED_TEMPORARILY, change.m_change );
-                    checkStrategy( context, REASON_IP_BANNED_TEMPORARILY,
+                    checkStrategy( context,
                             "You have been temporarily banned from modifying this wiki. (" + timeleft + " seconds of ban left)" );
                 }
             }
@@ -729,11 +728,10 @@ public class SpamFilter extends BasePageFilter {
      * Does a check against a known pattern list.
      *
      * @param context page Context
-     * @param content page content
      * @param change page change
      * @throws RedirectException spam filter rejects the page change.
      */
-    private void checkPatternList( final Context context, final String content, final Change change ) throws RedirectException {
+    private void checkPatternList( final Context context, final Change change ) throws RedirectException {
         // If we have no spam patterns defined, or we're trying to save the page containing the patterns, just return.
         if( m_spamPatterns == null || context.getPage().getName().equals( m_forbiddenWordsPage ) ) {
             return;
@@ -752,7 +750,7 @@ public class SpamFilter extends BasePageFilter {
                 final String uid = log( context, REJECT, REASON_REGEXP + "(" + p.getPattern() + ")", ch );
 
                 LOG.info( "SPAM:Regexp (" + uid + "). Content matches the spam filter '" + p.getPattern() + "'" );
-                checkStrategy( context, REASON_REGEXP, "Herb says '" + p.getPattern() + "' is a bad spam word and I trust Herb! (Incident code " + uid + ")" );
+                checkStrategy( context, "Herb says '" + p.getPattern() + "' is a bad spam word and I trust Herb! (Incident code " + uid + ")" );
             }
         }
     }
@@ -783,15 +781,15 @@ public class SpamFilter extends BasePageFilter {
                 final String uid = log( context, REJECT, REASON_IP_BANNED_PERMANENTLY + "(" + p.getPattern() + ")", remoteIP );
 
                 LOG.info( "SPAM:IPBanList (" + uid + "). remoteIP matches the IP filter '" + p.getPattern() + "'" );
-                checkStrategy( context, REASON_IP_BANNED_PERMANENTLY, "Herb says '" + p.getPattern() + "' is a banned IP and I trust Herb! (Incident code " + uid + ")" );
+                checkStrategy( context, "Herb says '" + p.getPattern() + "' is a banned IP and I trust Herb! (Incident code " + uid + ")" );
             }
         }
     }
 
-    private void checkPatternList( final Context context, final String content, final String change ) throws RedirectException {
+    private void checkPatternList( final Context context, final String change ) throws RedirectException {
         final Change c = new Change();
         c.m_change = change;
-        checkPatternList( context, content, c );
+        checkPatternList( context, c );
     }
  
     /**
@@ -916,9 +914,9 @@ public class SpamFilter extends BasePageFilter {
      */
     public boolean isValidUserProfile( final Context context, final UserProfile profile ) {
         try {
-            checkPatternList( context, profile.getEmail(), profile.getEmail() );
-            checkPatternList( context, profile.getFullname(), profile.getFullname() );
-            checkPatternList( context, profile.getLoginName(), profile.getLoginName() );
+            checkPatternList( context, profile.getEmail() );
+            checkPatternList( context, profile.getFullname() );
+            checkPatternList( context, profile.getLoginName() );
         } catch( final RedirectException e ) {
             LOG.info("Detected attempt to create a spammer user account (see above for rejection reason)");
             return false;
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java b/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
index fb25f67d5..2e6500c0b 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
@@ -1482,11 +1482,10 @@ public class JSPWikiMarkupParser extends MarkupParser {
 
     /**
      * Handles constructs of type %%(style) and %%class
-     * @param newLine
      * @return An Element containing the div or span, depending on the situation.
      * @throws IOException
      */
-    private Element handleDiv( final boolean newLine ) throws IOException {
+    private Element handleDiv( ) throws IOException {
         int ch = nextToken();
         Element el = null;
 
@@ -1577,11 +1576,11 @@ public class JSPWikiMarkupParser extends MarkupParser {
         return el;
     }
 
-    private Element handleSlash( final boolean newLine ) throws IOException {
+    private Element handleSlash( ) throws IOException {
         final int ch = nextToken();
         pushBack( ch );
         if( ch == '%' && !m_styleStack.isEmpty() ) {
-            return handleDiv( newLine );
+            return handleDiv();
         }
 
         return null;
@@ -1900,11 +1899,11 @@ public class JSPWikiMarkupParser extends MarkupParser {
             break;
 
           case '%':
-            el = handleDiv( m_newLine );
+            el = handleDiv();
             break;
 
           case '/':
-            el = handleSlash( m_newLine );
+            el = handleSlash();
             break;
 
           default:
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/references/DefaultReferenceManager.java b/jspwiki-main/src/main/java/org/apache/wiki/references/DefaultReferenceManager.java
index 4626c8286..ce95d4ca6 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/references/DefaultReferenceManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/references/DefaultReferenceManager.java
@@ -546,7 +546,7 @@ public class DefaultReferenceManager extends BasePageFilter implements Reference
 
         //  Get all pages that used to be referred to by 'page' and remove that reference. (We don't want to try to figure out
         //  which particular references were removed...)
-        cleanReferredBy( page, oldRefTo, cleanedRefs );
+        cleanReferredBy( page, oldRefTo);
 
         //  Notify all referred pages of their referinesshoodicity.
         for( final String referredPageName : cleanedRefs ) {
@@ -584,8 +584,7 @@ public class DefaultReferenceManager extends BasePageFilter implements Reference
      * We'll just try the first for now. Need to come back and optimize this a bit.
      */
     private void cleanReferredBy( final String referrer,
-                                  final Collection< String > oldReferred,
-                                  final Collection< String > newReferred ) {
+                                  final Collection< String > oldReferred ) {
         if( oldReferred == null ) {
             return;
         }