7ef1462ddbfa4d9017a98fbe460df3b0e95b25d9
chinhli
  Fri May 4 15:31:46 2012 -0700
Reuse the wiki cookies so that the existing session user can stay logged in and do not need to login to the new hgLogin system after the switch over.
diff --git src/hg/lib/wikiLink.c src/hg/lib/wikiLink.c
index bd7ecfd..729834a 100644
--- src/hg/lib/wikiLink.c
+++ src/hg/lib/wikiLink.c
@@ -1,27 +1,38 @@
 /* wikiLink - interoperate with a wiki site (share user identities). */
 
 #include "common.h"
 #include "hash.h"
 #include "htmshell.h"
 #include "cheapcgi.h"
 #include "hgConfig.h"
 #include "hui.h"
 #include "cart.h"
 #include "web.h"
 #include "wikiLink.h"
 
+char *loginSystemName()
+/* Return the wiki host specified in hg.conf, or NULL.  Allocd here. */
+{
+return cloneString(cfgOption(CFG_LOGIN_SYSTEM_NAME));
+}
+
+boolean loginSystemEnabled()
+/* Return TRUE if login.systemName  parameter is defined in hg.conf . */
+{
+return (cfgOption(CFG_LOGIN_SYSTEM_NAME) != NULL);
+}
 
 char *wikiLinkHost()
 /* Return the wiki host specified in hg.conf, or NULL.  Allocd here. */
 {
 return cloneString(cfgOption(CFG_WIKI_HOST));
 }
 
 boolean wikiLinkEnabled()
 /* Return TRUE if all wiki.* parameters are defined in hg.conf . */
 {
 return ((cfgOption(CFG_WIKI_HOST) != NULL) &&
 	(cfgOption(CFG_WIKI_USER_NAME_COOKIE) != NULL) &&
 	(cfgOption(CFG_WIKI_LOGGED_IN_COOKIE) != NULL));
 }
 
@@ -59,39 +70,61 @@
 
 static char *encodedHgSessionReturnUrl(int hgsid)
 /* Return a CGI-encoded hgSession URL with hgsid.  Free when done. */
 {
 char retBuf[1024];
 safef(retBuf, sizeof(retBuf), "http://%s/cgi-bin/hgSession?hgsid=%d",
       cgiServerNamePort(), hgsid);
 return cgiEncode(retBuf);
 }
 
 char *wikiLinkUserLoginUrl(int hgsid)
 /* Return the URL for the wiki user login page. */
 {
 char buf[2048];
 char *retEnc = encodedHgSessionReturnUrl(hgsid);
+if (loginSystemEnabled())
+{
+    if (! wikiLinkEnabled())
+        errAbort("wikiLinkUserLoginUrl called when login system is not enabled "
+           "(specified in hg.conf).");
+        safef(buf, sizeof(buf),
+      "http://%s/cgi-bin/hgLogin?hgLogin.do.displayLoginPage=1&returnto=%s",
+      wikiLinkHost(), retEnc);
+
+} else {
 if (! wikiLinkEnabled())
     errAbort("wikiLinkUserLoginUrl called when wiki is not enabled (specified "
 	     "in hg.conf).");
 safef(buf, sizeof(buf),
       "http://%s/index.php?title=Special:UserloginUCSC&returnto=%s",
       wikiLinkHost(), retEnc);
+}
 freez(&retEnc);
 return(cloneString(buf));
 }
 
 char *wikiLinkUserLogoutUrl(int hgsid)
 /* Return the URL for the wiki user logout page. */
 {
 char buf[2048];
 char *retEnc = encodedHgSessionReturnUrl(hgsid);
+
+if (loginSystemEnabled())
+{
+    if (! wikiLinkEnabled())
+        errAbort("wikiLinkUserLogoutUrl called when login system is not enabled "
+                 "(specified in hg.conf).");
+    safef(buf, sizeof(buf),
+          "http://%s/cgi-bin/hgLogin?hgLogin.do.displayLogout=1&returnto=%s",
+          wikiLinkHost(), retEnc);
+} else {
 if (! wikiLinkEnabled())
     errAbort("wikiLinkUserLogoutUrl called when wiki is not enable (specified "
 	     "in hg.conf).");
 safef(buf, sizeof(buf),
       "http://%s/index.php?title=Special:UserlogoutUCSC&returnto=%s",
       wikiLinkHost(), retEnc);
+}
 freez(&retEnc);
 return(cloneString(buf));
 }