If anonymous account creation isn't allowed, then don't print
[cocanwiki.git] / scripts / page.ml
index b6a4185..d1e8b09 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: page.ml,v 1.44 2006/03/28 13:20:00 rich Exp $
+ * $Id: page.ml,v 1.47 2006/07/26 13:19:49 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@ open Cocanwiki_date
 open Cocanwiki_server_settings
 open Cocanwiki_links
 
-type fp_status = FPOK of int * string * string * Dbi.datetime * bool
+type fp_status = FPOK of int32 * string * string * Calendar.t * bool
               | FPInternalRedirect of string
               | FPExternalRedirect of string
               | FPNotFound
@@ -223,8 +223,8 @@ let run r (q : cgi) dbh hostid
      * and background images while we compose the page.
      *)
     q#header ();
-    print_string r th#to_string;
-    Request.rflush r;
+    ignore (print_string r th#to_string);
+    ignore (Request.rflush r);
 
     t#conditional "has_feedback_email" has_feedback_email;
     t#conditional "mailing_list" mailing_list;
@@ -240,15 +240,19 @@ let run r (q : cgi) dbh hostid
          None -> []
        | Some pageid ->
            let rows = PGSQL(dbh)
-             "select ordering, sectionname, content, divname
+             "select ordering, sectionname, content, divname, jsgo
                  from contents where pageid = $pageid order by ordering" in
 
            List.map
-             (fun (ordering, sectionname, content, divname) ->
+             (fun (ordering, sectionname, content, divname, jsgo) ->
                 let divname, has_divname =
                   match divname with
                   | None -> "", false
                   | Some divname -> divname, true in
+                let jsgo, has_jsgo =
+                  match jsgo with
+                  | None -> "", false
+                  | Some jsgo -> jsgo, true in
                 let sectionname, has_sectionname =
                   match sectionname with
                   | None -> "", false
@@ -263,7 +267,9 @@ let run r (q : cgi) dbh hostid
                     Template.VarString
                       (Wikilib.xhtml_of_content dbh hostid content);
                   "has_divname", Template.VarConditional has_divname;
-                  "divname", Template.VarString divname ]) rows in
+                  "divname", Template.VarString divname;
+                  "has_jsgo", Template.VarConditional has_jsgo;
+                  "jsgo", Template.VarString jsgo ]) rows in
 
     (* Call an extension to generate the first section in this page? *)
     let sections =
@@ -278,6 +284,8 @@ let run r (q : cgi) dbh hostid
              "content", Template.VarString content;
              "has_divname", Template.VarConditional true;
              "divname", Template.VarString "form_div";
+             "has_jsgo", Template.VarConditional false;
+             "jsgo", Template.VarString "";
            ] in
            section :: sections in
 
@@ -291,6 +299,11 @@ let run r (q : cgi) dbh hostid
           t#conditional "user_logged_in" true;
           t#set "username" username);
 
+    (* Can anonymous users create accounts?  If not them we don't
+     * want to offer to create accounts for them.
+     *)
+    t#conditional "create_account_anon" host.create_account_anon;
+
     (* If logged in, we want to update the recently_visited table. *)
     if pageid <> None then (
       match user with
@@ -410,7 +423,7 @@ let run r (q : cgi) dbh hostid
                  from pages
                 where hostid = $hostid and lower (url) = lower ($page)" in
            match rows with
-           | [page', _, _, _, _, _, _]
+           | [Some page', _, _, _, _, _, _]
                when page <> page' -> (* different case *)
                FPExternalRedirect page'
            | [ _, None, id, title, description,
@@ -480,11 +493,10 @@ let run r (q : cgi) dbh hostid
        | FPInternalRedirect page' ->
            loop page' (i+1)
        | FPExternalRedirect page' ->
-           (* This normally happens when a user has request an uppercase
+           (* This normally happens when a user has requested an uppercase
             * page name.  We redirect to the true (lowercase) version.
             *)
-           q#redirect ("http://" ^ host.hostname ^ "/" ^ page');
-           return ()
+           q#redirect ("http://" ^ host.hostname ^ "/" ^ page')
        | FPNotFound ->
            (* Might be a templated page with no content in it. *)
            let extension = get_extension page' in