(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: wikilib.ml,v 1.5 2004/09/16 18:06:31 rich Exp $
+ * $Id: wikilib.ml,v 1.12 2004/10/11 14:13:04 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
let generate_url_of_title (dbh : Dbi.connection) hostid title =
(* Create a suitable URL from this title. *)
- let url = String.map (function '\000' .. ' ' | '<' | '>' | '&' | '"' -> '_'
- | c -> Char.lowercase c) title in
+ let url =
+ String.map (function
+ '\000' .. ' ' | '<' | '>' | '&' | '"' | '+' | '#' | '%'
+ -> '_'
+ | c -> Char.lowercase c) title in
(* Check URL is not too trivial. *)
if not (Pcre.pmatch ~rex:nontrivial_re url) then
(* This matches any markup. *)
let markup_re =
let link = "\\[\\[\\s*(?:.+?)\\s*(?:\\|.+?\\s*)?\\]\\]" in
- let tag = "</?(?:b|i|strong|em|code|sup|sub|nowiki)>" in
+ let tag = "</?(?:b|i|strong|em|code|tt|sup|sub|nowiki|big|small|strike|s|br)>" in
Pcre.regexp ("(.*?)((?:" ^ link ^ ")|(?:" ^ tag ^ "))(.*)")
(* This matches links only, and should be compatible with the link contained
) else (
let title = url in
(* Look up the 'URL' against the titles in the database and
- * obtain the real URL. If none is found then it's a link to
- * create a new page.
+ * obtain the real URL.
*)
let sth = dbh#prepare_cached "select url from pages
where hostid = ? and url is not null
"/" ^ url, "internal", title
with
Not_found ->
- "/_bin/create_form.cmo?title=" ^ escape_url url, "newpage", title
+ (* It might be a template page ... These pages don't
+ * exist in the template, but can be synthesized on the
+ * fly by page.ml.
+ *)
+ let is_template_page url =
+ let sth = dbh#prepare_cached "select 1 from templates
+ where ? ~ url_regexp
+ order by ordering
+ limit 1" in
+ sth#execute [`String url];
+
+ try sth#fetch1int () = 1 with Not_found -> false
+ in
+
+ if is_template_page url then
+ "/" ^ url, "internal", title
+ else
+ (* No, it really doesn't exist, so make it a link to
+ * a new page.
+ *)
+ "/_bin/edit.cmo?title=" ^ escape_url url, "newpage", title
) in
"<a href=\"" ^ url ^
| FoundOpen (first, elem, rest) when elem = "nowiki" ->
(* handle <nowiki> specially ... *)
escape_html first :: loop (rest, elem :: [])
+ | FoundOpen (first, elem, rest) when elem = "br" ->
+ (* handle <br> specially ... *)
+ escape_html first :: "<br/>" :: loop (rest, [])
| FoundOpen (first, elem, rest) ->
(* open tag - push it onto the stack *)
escape_html first :: "<" :: elem :: ">" :: loop (rest, [elem])
| FoundOpen (first, elem, rest) when elem = "nowiki" ->
(* handle <nowiki> specially ... *)
escape_html first :: loop (rest, elem :: stack)
+ | FoundOpen (first, elem, rest) when elem = "br" ->
+ (* handle <br> specially ... *)
+ escape_html first :: "<br/>" :: loop (rest, stack)
| FoundOpen (first, elem, rest) ->
(* open tag - push it onto the stack *)
escape_html first :: "<" :: elem :: ">" ::
"p", [];
"ul", []; "ol", []; "li", [];
"pre", []; "blockquote", ["cite"];
- "strong", []; "em", []; "dfn", []; "code", []; "samp", []; "kbd", [];
- "var", []; "cite", []; "sup", []; "sub", []; "q", [];
+ "strong", []; "em", []; "dfn", []; "code", []; "tt", [];
+ "samp", []; "kbd", []; "var", []; "cite", [];
+ "sup", []; "sub", []; "q", [];
"abbr", []; "acronym", [];
"b", []; "i", [];
+ "big", []; "small", []; "strike", []; "s", [];
"div", []; "span", [];
"br", [];
] in
let forms = [
"form", [ "method"; "action"; "enctype" ];
"input", [ "name"; "value"; "type"; "size"; "maxlength" ];
+ "textarea", [ "name"; "rows"; "cols" ];
] in
let tables = [