2aaad2b66e35bc2bef4757e4f10829d4694be059
kate
  Tue Jul 9 11:40:23 2019 -0700
More conservative approach, from Angie code review. refs #23744

diff --git src/hg/lib/cartTrackDb.c src/hg/lib/cartTrackDb.c
index 6d4c762..531fe13 100644
--- src/hg/lib/cartTrackDb.c
+++ src/hg/lib/cartTrackDb.c
@@ -10,67 +10,67 @@
 #include "hgConfig.h"
 #include "hgMaf.h"
 #include "hubConnect.h"
 #include "joiner.h"
 #include "trackHub.h"
 #include "wikiTrack.h"
 
 /* Static globals */
 static boolean useAC = FALSE;
 static struct slRef *accessControlTrackRefList = NULL;
 
 static struct trackDb *getFullTrackList(struct cart *cart, char *db, struct grp **pHubGroups)
 {
 struct trackDb *list = hTrackDb(db);
 
-// get hub tracks
+/* add wikiTrack if enabled */
+if (wikiTrackEnabled(db, NULL))
+    slAddHead(&list, wikiTrackDb());
+slSort(&list, trackDbCmp);
+
+// Add hub tracks at head of list
 struct trackDb *hubTdbList = hubCollectTracks(db, pHubGroups);
 list = slCat(list, hubTdbList);
 
 /* exclude any track with a 'tableBrowser off' setting */
 struct trackDb *tdb, *nextTdb, *newList = NULL;
 for (tdb = list;  tdb != NULL;  tdb = nextTdb)
     {
     nextTdb = tdb->next;
     if (tdbIsDownloadsOnly(tdb) || tdb->table == NULL)
         {
         //freeMem(tdb);  // should not free tdb's.
         // While hdb.c should and says it does cache the tdbList, it doesn't.
         // The most notable reason that the tdbs are not cached is this hgTables CGI !!!
         // It needs to be rewritten to make tdbRef structures for the lists it creates here!
         continue;
         }
 
     char *tbOff = trackDbSetting(tdb, "tableBrowser");
     if (useAC && tbOff != NULL &&
         (startsWithWord("off", tbOff) || startsWithWord("noGenome", tbOff)))
         {
         slAddHead(&accessControlTrackRefList, slRefNew(tdb));
         if (! startsWithWord("off", tbOff))
             slAddHead(&newList, tdb);
         }
     else
 	slAddHead(&newList, tdb);
     }
+slReverse(&newList);
 list = newList;
 
-/* add wikiTrack if enabled */
-if (wikiTrackEnabled(db, NULL))
-    slAddHead(&list, wikiTrackDb());
-
-slSort(&list, trackDbCmp);
-
 // Add custom tracks at head of list
 struct customTrack *ctList, *ct;
 ctList = customTracksParseCart(db, cart, NULL, NULL);
 for (ct = ctList; ct != NULL; ct = ct->next)
     {
     slAddHead(&list, ct->tdb);
     }
 
 return list;
 }
 
 static struct grp *makeGroupList(char *db, struct trackDb *trackList, struct grp **pHubGrpList,
                                  boolean allTablesOk)
 /* Get list of groups that actually have something in them. */
 {