From: rich Date: Mon, 20 Sep 2004 10:56:46 +0000 (+0000) Subject: Allow empty

first. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;ds=sidebyside;h=4a1bf584fe7e2f731645378201d9cc087b2b846d;p=cocanwiki.git Allow empty

first. - In the database, contents.sectionname is no longer 'not null'. - Edit script has been changed to allow first section name to be empty (setting contents.sectionname to null). Only for the first section, however. - Create script now creates an empty first sectionname by default. - Page has been changed to render empty sectionnames properly (no

title or anchor). --- diff --git a/cocanwiki.sql b/cocanwiki.sql index ac84730..32b0387 100644 --- a/cocanwiki.sql +++ b/cocanwiki.sql @@ -73,7 +73,7 @@ CREATE TABLE contents ( id serial NOT NULL, pageid integer NOT NULL, ordering integer NOT NULL, - sectionname text NOT NULL, + sectionname text, content text NOT NULL, divname text ); diff --git a/scripts/cocanwiki_diff.ml b/scripts/cocanwiki_diff.ml index 8bfd4af..97f4b65 100644 --- a/scripts/cocanwiki_diff.ml +++ b/scripts/cocanwiki_diff.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_diff.ml,v 1.3 2004/09/09 12:21:22 rich Exp $ + * $Id: cocanwiki_diff.ml,v 1.4 2004/09/20 10:56:47 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 @@ -59,7 +59,7 @@ let get_version_for_diff (dbh : Dbi.connection) version = let css = sth#fetch1string () in - let sth = dbh#prepare_cached "select sectionname, content + let sth = dbh#prepare_cached "select coalesce (sectionname, ''), content from contents where pageid = ? order by ordering" in sth#execute [`Int version]; diff --git a/scripts/create.ml b/scripts/create.ml index d33dd5c..a1d1d72 100644 --- a/scripts/create.ml +++ b/scripts/create.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: create.ml,v 1.5 2004/09/09 12:21:22 rich Exp $ + * $Id: create.ml,v 1.6 2004/09/20 10:56:47 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 @@ -69,12 +69,11 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = let pageid = sth#serial "pages_id_seq" in (* Create a single section. *) - let sectionname = "Section title - change this" in let content = "Write some content here." in let sth = dbh#prepare_cached "insert into contents (pageid, ordering, sectionname, content) values (?, 1, ?, ?)" in - sth#execute [`Int pageid; `String sectionname; `String content]; + sth#execute [`Int pageid; `Null; `String content]; (* Commit. *) dbh#commit (); diff --git a/scripts/edit.ml b/scripts/edit.ml index 47ab1fc..bf7b482 100644 --- a/scripts/edit.ml +++ b/scripts/edit.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit.ml,v 1.8 2004/09/09 12:21:22 rich Exp $ + * $Id: edit.ml,v 1.9 2004/09/20 10:56:47 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 @@ -118,12 +118,16 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = "(ie. not to a page which is itself a redirect).") ); - (* All sections have sectionnames? *) - List.iter (function (sectionnames, _, _) - when string_is_whitespace sectionnames -> - add_error ("Every section must have a title."); - | _ -> ()) - model.contents; + (* All sections after the first one have sectionnames? The first + * section ONLY is allowed to have an empty title. + *) + if model.contents <> [] then + List.iter (function (sectionnames, _, _) + when string_is_whitespace sectionnames -> + add_error + ("Every section except the first must have a title."); + | _ -> ()) + (List.tl model.contents); get_errors () in @@ -247,7 +251,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = | _ -> assert false in (* Get the sections. *) - let sth = dbh#prepare_cached "select sectionname, content, + let sth = dbh#prepare_cached "select coalesce (sectionname, ''), + content, coalesce (divname, '') from contents where pageid = ? @@ -429,9 +434,12 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = let divname = if string_is_whitespace divname then `Null else `String divname in + let sectionname = + if string_is_whitespace sectionname then `Null + else `String sectionname in incr ordering; let ordering = !ordering in sth#execute [`Int pageid; `Int ordering; - `String sectionname; divname; + sectionname; divname; `String content]) model.contents; diff --git a/scripts/page.ml b/scripts/page.ml index 70c25b3..b219afa 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.12 2004/09/17 15:24:54 rich Exp $ + * $Id: page.ml,v 1.13 2004/09/20 10:56:47 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 @@ -94,13 +94,20 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = let sections = sth#map - (function [`Int ordering; `String sectionname; `String content; + (function [`Int ordering; + (`Null | `String _) as sectionname; + `String content; (`Null | `String _) as divname] -> let divname, has_divname = match divname with `Null -> "", false | `String divname -> divname, true in + let sectionname, has_sectionname = + match sectionname with + `Null -> "", false + | `String sectionname -> sectionname, true in [ "ordering", Template.VarString (string_of_int ordering); + "has_sectionname", Template.VarConditional has_sectionname; "sectionname", Template.VarString sectionname; "content", Template.VarString diff --git a/templates/page.html b/templates/page.html index e32169e..c5011b1 100644 --- a/templates/page.html +++ b/templates/page.html @@ -31,7 +31,7 @@ ::end:: ::table(sections):: -::if(has_divname)::
::end::::if(can_edit)::::end::

::sectionname_html::

+::if(has_divname)::
::end::::if(can_edit)::::end::::if(has_sectionname)::

::sectionname_html::

::end:: ::content:: ::if(has_divname)::
::end::::end::