Diff
Not logged in

Differences From:

File src/wiki.c part of check-in [bfb4d414dd] - minor refactorings to the wiki commands by stephan on 2008-05-15 20:26:25. [view]

To:

File src/wiki.c part of check-in [29374daa0d] - /home link content can now be pulled from a Wiki entry or an arbitrary link relative to the fossil root url. See the WWW Configuration dialog for details. by stephan on 2008-05-15 22:05:52. [view]

@@ -78,20 +78,40 @@
 ** WEBPAGE: index
 ** WEBPAGE: not_found
 */
 void home_page(void){
-  char *zPageName = db_get("project-name",0);
-  if( zPageName ){
-    login_check_credentials();
-    g.zExtra = zPageName;
-    cgi_set_parameter_nocopy("name", g.zExtra);
-    g.okRdWiki = 1;
-    g.okApndWiki = 0;
-    g.okWrWiki = 0;
-    g.okHistory = 0;
-    wiki_page();
+  char *zHomePage;        /* name of home page */
+  char *zProjName;        /* name of project */
+  zProjName = db_get("project-name",0);
+  zHomePage = db_get("project-home", zProjName );
+  if( zProjName && zHomePage[0] ){
+    /* beware: this code causes cyclic redirects on a 404 because
+       not_found is directed here.
+     */
+    int lenP;             /* strncmp() bounder */
+    int lenH;             /* length of zProjName */
+    if(  zHomePage && ! zHomePage[0] ){
+        zHomePage = zProjName;
+    }
+    lenP = strlen(zProjName);
+    lenH = strlen(zHomePage);
+    if( lenP < lenH ) lenP = lenH;
+    if( (zProjName == zHomePage) || (0==strncmp(zProjName,zHomePage,lenP)) ||
+      (0==strncmp(zHomePage,"home",lenP)/*avoid endless loop*/) ){
+        login_check_credentials();
+        g.zExtra = zHomePage;
+        cgi_set_parameter_nocopy("name", g.zExtra);
+        g.okRdWiki = 1;
+        g.okApndWiki = 0;
+        g.okWrWiki = 0;
+        g.okHistory = 0;
+        wiki_page();
+    }else{
+        cgi_redirect( zHomePage );
+    }
     return;
   }
+
   style_header("Home");
   @ <p>This is a stub home-page for the project.
   @ To fill in this page, first go to
   @ <a href="%s(g.zBaseURL)/setup_config">setup/config</a>
@@ -631,12 +651,12 @@
   char * zDate;           /* timestamp */
   char * zUuid;           /* uuid for rid */
 
   rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
-	       " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
+               " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
 	       " ORDER BY x.mtime DESC LIMIT 1",
-	       zPageName
-	       );
+               zPageName
+               );
   if( ! rid ){
     fossil_fatal("wiki commit NewEntry not yet implemented.");
   }