Added the framework to allow us to populate standards parts of the
[cocanwiki.git] / scripts / create_form.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: create_form.ml,v 1.4 2004/09/08 15:46:52 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open ExtString
13
14 open Cocanwiki
15 open Cocanwiki_template
16 open Cocanwiki_ok
17
18 let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
19   let template = get_template dbh hostid "create_form.html" in
20
21   (* Get the page title. *)
22   let title = q#param "title" in
23
24   let url =
25     match Wikilib.generate_url_of_title dbh hostid title with
26         Wikilib.GenURL_OK url -> url
27       | Wikilib.GenURL_TooShort | Wikilib.GenURL_BadURL ->
28           error ~back_button:true ~title:"Bad page name"
29             q "The page name supplied is too short or invalid.";
30           raise CgiExit
31       | Wikilib.GenURL_Duplicate url ->
32           q#redirect ("http://" ^ hostname ^ "/" ^ url);
33           raise CgiExit in
34
35   (* Show the form. *)
36   template#set "title" title;
37
38   q#template template
39
40 let () =
41   register_script ~restrict:[CanEdit] run