Don't forget the date\!
[cocanwiki.git] / scripts / edit.ml
index f28ba2d..a3d50a4 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: edit.ml,v 1.35 2006/08/04 12:45:31 rich Exp $
+ * $Id: edit.ml,v 1.38 2006/12/06 09:46:57 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
@@ -35,9 +35,9 @@ open Cocanwiki_strings
 open Cocanwiki_pages
 
 let run r (q : cgi) dbh hostid {hostname = hostname} user =
-  let template = get_template dbh hostid "edit.html" in
-  let template_conflict = get_template dbh hostid "edit_conflict.html" in
-  let template_email = get_template dbh hostid "edit_page_email.txt" in
+  let template = get_template dbh hostid "edit.html" in
+  let template_conflict = get_template dbh hostid "edit_conflict.html" in
+  let template_email = get_template dbh hostid "edit_page_email.txt" in
 
   (* Workaround bugs in IE, specifically lack of support for <button>
    * elements.
@@ -58,6 +58,11 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
     let keywords = q#param "keywords" in
     let keywords =
       if string_is_whitespace keywords then None else Some keywords in
+    let noodp = match q#param "noodp" with
+      | "" -> None
+      | "t" -> Some true
+      | "f" -> Some false
+      | _ -> failwith "unknown value for noodp parameter" in
     let redirect = q#param "redirect" in
     let redirect =
       if string_is_whitespace redirect then None else Some redirect in
@@ -76,9 +81,12 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
       let divname = q#param ("divname_" ^ string_of_int !i) in
       let divname =
        if string_is_whitespace divname then None else Some divname in
+      let divclass = q#param ("divclass_" ^ string_of_int !i) in
+      let divclass =
+       if string_is_whitespace divclass then None else Some divclass in
       let jsgo = q#param ("jsgo_" ^ string_of_int !i) in
       let jsgo = if string_is_whitespace jsgo then None else Some jsgo in
-      contents := (sectionname, divname, jsgo, content) :: !contents;
+      contents := (sectionname, divname, divclass, jsgo, content) :: !contents;
       incr i
     done;
     let contents = List.rev !contents in
@@ -87,6 +95,7 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
       pt = pt;
       description = description;
       keywords = keywords;
+      noodp = noodp;
       redirect = redirect;
       contents_ = contents; }
   in
@@ -132,22 +141,22 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
      *)
     if model.contents_ <> [] then
       List.iter (function
-                | (None, _, _, _) ->
+                | (None, _, _, _, _) ->
                     add_error
                       "Every section except the first must have a title.";
                 | _ -> ())
        (List.tl model.contents_);
 
     (* There are two constraints on any non-null jsgo's:
-     * (1) Must only be present if divname is non-null.
+     * (1) Must only be present if divname or divclass is non-null.
      * (2) Must point to a valid URL on the current host.
      *)
     List.iter (
       function
-      | (_, None, Some _, _) ->
+      | (_, None, None, Some _, _) ->
          add_error
-           "Javascript onclick can only be used with a CSS id."
-      | (_, _, Some jsgo, _) ->
+           "Javascript onclick can only be used with a CSS id/class."
+      | (_, _, _, Some jsgo, _) ->
          let rows =
            PGSQL(dbh) "select 1 from pages
                          where hostid = $hostid
@@ -227,6 +236,14 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
     template#set "keywords"
       (match model.keywords with None -> "" | Some keywords -> keywords);
 
+    template#conditional "noodp_null" false;
+    template#conditional "noodp_true" false;
+    template#conditional "noodp_false" false;
+    (match model.noodp with
+     | None -> template#conditional "noodp_null" true
+     | Some true -> template#conditional "noodp_true" true
+     | Some false -> template#conditional "noodp_false" true);
+
     (match model.pt with
         Page page ->
           template#set "pt_type" "page";
@@ -274,14 +291,16 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
     let ordering = ref 0 in
     let table =
       List.map
-       (fun (sectionname, divname, jsgo, content) ->
+       (fun (sectionname, divname, divclass, jsgo, content) ->
           incr ordering; let ordering = Int32.of_int !ordering in
           let sectionname = match sectionname with None -> "" | Some s -> s in
           let divname = match divname with None -> "" | Some s -> s in
+          let divclass = match divclass with None -> "" | Some s -> s in
           let jsgo = match jsgo with None -> "" | Some s -> s in
           [ "ordering", Template.VarString (Int32.to_string ordering);
             "sectionname", Template.VarString sectionname;
             "divname", Template.VarString divname;
+            "divclass", Template.VarString divclass;
             "jsgo", Template.VarString jsgo;
             "content", Template.VarString content ]) model.contents_ in
     template#table "contents" table;
@@ -321,7 +340,7 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
             q#redirect ("http://" ^ hostname ^ "/" ^ url)
         | Wikilib.GenURL_TooShort | Wikilib.GenURL_BadURL ->
             error ~back_button:true ~title:"Bad page name"
-              dbh hostid q
+              dbh hostid q
               "The page name supplied is too short or invalid.";
             return ()
     );
@@ -374,7 +393,7 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
       let posn = get_action "insert" in
       let item =
        Some "The title of this section",
-       None, None,
+       None, None, None,
        "Write something here." in
       model := action_insert !model posn item
     ) else if is_action "moveup" then (
@@ -405,8 +424,9 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
        with
            SaveURLError ->
              error ~back_button:true ~title:"Page exists"
-               dbh hostid q ("While you were editing that page, it looks " ^
-                             "like another user created the same page.");
+               r dbh hostid q
+               ("While you were editing that page, it looks " ^
+                  "like another user created the same page.");
              return ()
 
          | SaveConflict (new_version, old_version, url, css) ->