Index: src/java/org/apache/wiki/plugin/AbstractFilteredPlugin.java
===================================================================
--- src/java/org/apache/wiki/plugin/AbstractFilteredPlugin.java	(revision 770483)
+++ src/java/org/apache/wiki/plugin/AbstractFilteredPlugin.java	(working copy)
@@ -252,12 +252,35 @@
      *  Filters a collection according to the include and exclude -parameters.
      *  
      *  @param c The collection to filter.
-     *  @return A filtered collection.
+     *  @return A filtered collection in arbitrary order.
+     *  @throws IllegalArgumentException if called with a collection containing anything other than String, WikiPath or WikiPage 
      */
-    protected <T extends Object>Collection<T> filterCollection( Collection<T> c )
+    protected <T extends Object>List<T> filterCollection( Collection<T> c )
     {
-        ArrayList<T> result = new ArrayList<T>();
-
+        return (List<T>)filterCollection( new ArrayList<T>(), c );
+    }
+    
+    /**
+     *  Filters a collection according to the include and exclude -parameters.
+     *  
+     *  @param c The collection to filter.
+     *  @return A filtered collection sorted in name order.
+     *  @throws IllegalArgumentException if called with a collection containing anything other than String, WikiPath or WikiPage 
+     */
+    protected <T extends Object>SortedSet<T> filterCollectionSorted( Collection<T> c )
+    {
+        return (SortedSet<T>)filterCollection( new TreeSet<T>(), c );
+    }
+    
+    /**
+     *  Filters a collection according to the include and exclude -parameters.
+     *  
+     *  @param c The collection to filter.
+     *  @return A filtered collection in the order determined by the passed in result collection.
+     *  @throws IllegalArgumentException if called with a collection containing anything other than String, WikiPath or WikiPage 
+     */
+    protected <T extends Object>Collection<T> filterCollection( Collection<T> result, Collection<T> c )
+    {
         for( T objectje : c )
         {
             String pageName = null;
@@ -273,6 +296,8 @@
             {
                 pageName = (String) objectje;
             }
+            else
+                throw new IllegalArgumentException("filterCollection called with an instance of " + objectje.getClass().getCanonicalName());
 
             //
             //  If include parameter exists, then by default we include only those
@@ -353,29 +378,43 @@
     }
 
     /**
-     *  Makes WikiText from a Collection.
+     *  Makes WikiText from a Collection of Strings.
      *
      *  @param links Collection to make into WikiText.
      *  @param separator Separator string to use.
      *  @param numItems How many items to show.
      *  @return The WikiText
+     *
+     *  @deprecated Use wikitizeCollection( Collection, int ) instead.
      */
     protected String wikitizeCollection( Collection<String> links, String separator, int numItems )
     {
+        return wikitizeCollection( links, numItems );
+    }
+    
+    /**
+     *  Makes WikiText from a Collection of Strings, WikiPages or WikiPaths.
+     *
+     *  @param links Collection to make into WikiText.
+     *  @param numItems How many items to show.
+     *  @return The WikiText
+     *  @throws IllegalArgumentException if called with a collection containing anything other than String, WikiPath or WikiPage 
+     */
+    protected <T extends Object> String wikitizeCollection( Collection<T> links, int numItems )
+    {
         if( links == null || links.isEmpty() )
             return "";
 
         StringBuilder output = new StringBuilder();
-
-        Iterator<String> it     = links.iterator();
         int      count  = 0;
 
         //
         //  The output will be B Item[1] A S B Item[2] A S B Item[3] A
         //
-        while( it.hasNext() && ( (count < numItems) || ( numItems == ALL_ITEMS ) ) )
+        for( Object o : links )
         {
-            String value = (String)it.next();
+            if( numItems != ALL_ITEMS && count >= numItems )
+                break;
 
             if( count > 0 )
             {
@@ -385,6 +424,16 @@
 
             output.append( m_before );
 
+            String value;
+            if( o instanceof String )
+                value = (String)o;
+            else if( o instanceof WikiPath )
+                value = ((WikiPath)o).toString();
+            else if( o instanceof WikiPage )
+                value = ((WikiPage)o).getName();
+            else
+                throw new IllegalArgumentException("wikitizeCollection called with an instance of " + o.getClass().getCanonicalName());
+            
             // Make a Wiki markup link. See TranslatorReader.
             output.append( "[" + m_engine.beautifyTitle(value) + "|" + value + "]" );
             count++;
Index: src/java/org/apache/wiki/plugin/IndexPlugin.java
===================================================================
--- src/java/org/apache/wiki/plugin/IndexPlugin.java	(revision 770483)
+++ src/java/org/apache/wiki/plugin/IndexPlugin.java	(working copy)
@@ -51,7 +51,7 @@
     {
         super.initialize( context, params );
         
-        List<String> pages;
+        SortedSet<WikiPage> pages;
         div masterDiv = new div();
         masterDiv.setClass( "index" );
         
@@ -62,14 +62,14 @@
         try
         {
             pages = listPages( context );
-            Collections.sort( pages );
             
             char initialChar = ' ';
             
             div currentDiv = new div();
             
-            for( String name : pages )
+            for( WikiPage page : pages )
             {
+                String name = page.getName();
                 if( name.charAt( 0 ) != initialChar )
                 {
                     if( initialChar != ' ' ) indexDiv.addElement( " - " );
@@ -126,17 +126,10 @@
      * @return A list containing {@link org.apache.wiki.api.WikiPage} Objects
      * @throws ProviderException
      */
-    private List<String> listPages( WikiContext context ) throws ProviderException
+    private SortedSet<WikiPage> listPages( WikiContext context ) throws ProviderException
     {
-        ArrayList<String> result = new ArrayList<String>();
         Collection<WikiPage> pages = context.getEngine().getContentManager().getAllPages( ContentManager.DEFAULT_SPACE );
-        pages = super.filterCollection( pages );
-
-        for( WikiPage page : pages )
-        {
-            result.add( page.getName() );
-        }
-        return result;
+        return super.filterCollectionSorted( pages );
     }
 
 }
Index: src/java/org/apache/wiki/plugin/ReferredPagesPlugin.java
===================================================================
--- src/java/org/apache/wiki/plugin/ReferredPagesPlugin.java	(revision 770483)
+++ src/java/org/apache/wiki/plugin/ReferredPagesPlugin.java	(working copy)
@@ -145,7 +145,7 @@
 
 
     /**
      * Retrieves a list of all referred pages. Is called recursively
      * depending on the depth parameter
      * @throws PageNotFoundException 
      * @throws ProviderException 
@@ -161,9 +161,10 @@
 
         Collection<String> pages = mgr.findRefersTo( pagename );
         if( pages != null )
-        {
-            pages = super.filterCollection( pages );
-        }
+            if( m_formatSort )
+                pages = super.filterCollectionSorted( pages ); // get a filtered, ordered list (by name)
+            else
+                pages = super.filterCollection( pages ); // get a filtered, unordered list
 
         handleLinks( context, pages, ++depth, pagename );
     }
@@ -175,14 +176,7 @@
         // links to the same page
         localLinkSet.add(pagename);
 
-        ArrayList<String> allLinks = new ArrayList<String>();
-
-        if( links != null )
-            allLinks.addAll( links );
-
-        if( m_formatSort ) Collections.sort(allLinks);
-
-        for( String link : allLinks )
+        for( String link : links )
         {
             if( localLinkSet.contains( link ) ) continue; // skip multiple
                                                           // links to the same
Index: src/java/org/apache/wiki/plugin/ReferringPagesPlugin.java
===================================================================
--- src/java/org/apache/wiki/plugin/ReferringPagesPlugin.java	(revision 770483)
+++ src/java/org/apache/wiki/plugin/ReferringPagesPlugin.java	(working copy)
@@ -21,10 +21,7 @@
 package org.apache.wiki.plugin;
 
 import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import java.util.ResourceBundle;
+import java.util.*;
 
 import org.apache.wiki.ReferenceManager;
 import org.apache.wiki.WikiContext;
@@ -95,7 +92,7 @@
             WikiPage page = context.getEngine().getPage( pageName );
         
             Collection<WikiPath> links = refmgr.findReferrers( page.getPath() );
-            String wikitext = "";
+            String wikitext;
 
             super.initialize( context, params );
 
@@ -112,13 +109,8 @@
         
             if( links != null && links.size() > 0 )
             {
-                // FIXME: Having to copy all of these is kinda stupid.
-                Collection<String> tmpList = new ArrayList<String>();
-                
-                for( WikiPath wn : links ) tmpList.add( wn.toString() );
-                
-                tmpList= filterCollection( tmpList );
-                wikitext = wikitizeCollection( tmpList, m_separator, items );
+                SortedSet<WikiPath> tmpList = filterCollectionSorted( links );
+                wikitext = wikitizeCollection( tmpList, items );
 
                 result.append( makeHTML( context, wikitext ) );
                 
Index: src/java/org/apache/wiki/plugin/UndefinedPagesPlugin.java
===================================================================
--- src/java/org/apache/wiki/plugin/UndefinedPagesPlugin.java	(revision 770483)
+++ src/java/org/apache/wiki/plugin/UndefinedPagesPlugin.java	(working copy)
@@ -22,6 +22,7 @@
 
 import java.util.Collection;
 import java.util.Map;
+import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.apache.wiki.ReferenceManager;
@@ -52,13 +53,9 @@
 
         super.initialize( context, params );
 
-        TreeSet<String> sortedSet = new TreeSet<String>();
-
-        links = filterCollection( links );
-
-        sortedSet.addAll( links );
+        SortedSet<String> sortedSet = filterCollectionSorted( links );
         
-        String wikitext = null;
+        String wikitext;
         
         if (m_lastModified)
         {
@@ -73,7 +70,7 @@
         }
         else
         {
-            wikitext = wikitizeCollection(sortedSet, m_separator, ALL_ITEMS);
+            wikitext = wikitizeCollection(sortedSet, ALL_ITEMS);
         }
         
         return makeHTML( context, wikitext );
