Version 1.0.0-RC1
[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.1 2004/09/07 10:14:09 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_ok
16
17 let template = get_template "create_form.html"
18
19 let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname) _ =
20   (* Get the page title. *)
21   let title = q#param "title" in
22
23   let url =
24     match Wikilib.generate_url_of_title dbh hostid title with
25         Wikilib.GenURL_OK url -> url
26       | Wikilib.GenURL_TooShort | Wikilib.GenURL_BadURL ->
27           error ~back_button:true ~title:"Bad page name"
28             q "The page name supplied is too short or invalid.";
29           raise CgiExit
30       | Wikilib.GenURL_Duplicate url ->
31           q#redirect ("http://" ^ hostname ^ "/" ^ url);
32           raise CgiExit in
33
34   (* Show the form. *)
35   template#set "title" title;
36
37   q#template template
38
39 let () =
40   register_script run