X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fwikilib.ml;h=b11b5900767124b8bce037dd45a99be005ca802d;hb=019c80476c64b5cd86b6e9d115c86162b2ae462c;hp=77ba13a9882cf0e582994512f5065871bccf43c1;hpb=3986e1738463c7e5462691fd2c454a404f9b3524;p=cocanwiki.git diff --git a/scripts/wikilib.ml b/scripts/wikilib.ml index 77ba13a..b11b590 100644 --- a/scripts/wikilib.ml +++ b/scripts/wikilib.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: wikilib.ml,v 1.6 2004/09/17 15:09:48 rich Exp $ + * $Id: wikilib.ml,v 1.11 2004/10/09 11:03:58 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 @@ -42,8 +42,9 @@ let nontrivial_re = Pcre.regexp ~flags:[`CASELESS] "[a-z0-9]" 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 @@ -90,7 +91,7 @@ let obscure_mailto url = (* This matches any markup. *) let markup_re = let link = "\\[\\[\\s*(?:.+?)\\s*(?:\\|.+?\\s*)?\\]\\]" in - let tag = "" in + let tag = "" in Pcre.regexp ("(.*?)((?:" ^ link ^ ")|(?:" ^ tag ^ "))(.*)") (* This matches links only, and should be compatible with the link contained @@ -220,8 +221,7 @@ let markup_link dbh hostid link = ) 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 @@ -233,7 +233,27 @@ let markup_link dbh hostid link = "/" ^ 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 " (* handle specially ... *) escape_html first :: loop (rest, elem :: []) + | FoundOpen (first, elem, rest) when elem = "br" -> + (* handle
specially ... *) + escape_html first :: "
" :: loop (rest, []) | FoundOpen (first, elem, rest) -> (* open tag - push it onto the stack *) escape_html first :: "<" :: elem :: ">" :: loop (rest, [elem]) @@ -343,6 +366,9 @@ let _markup_paragraph dbh hostid text = | FoundOpen (first, elem, rest) when elem = "nowiki" -> (* handle specially ... *) escape_html first :: loop (rest, elem :: stack) + | FoundOpen (first, elem, rest) when elem = "br" -> + (* handle
specially ... *) + escape_html first :: "
" :: loop (rest, stack) | FoundOpen (first, elem, rest) -> (* open tag - push it onto the stack *) escape_html first :: "<" :: elem :: ">" :: @@ -399,10 +425,12 @@ let allowed_elements = "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