X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fwikilib.ml;h=f4b309bafbd68be58c7faa27e4536e8b5d917ba4;hb=22c5eb291c13270f17f2cee76b760634f230347e;hp=b366ae2f9de26b906e90d854f59ee1cb570020b3;hpb=b14e7a6af18b251499d9c769986b69eb456059c4;p=cocanwiki.git diff --git a/scripts/wikilib.ml b/scripts/wikilib.ml index b366ae2..f4b309b 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.8 2004/09/30 14:58:14 rich Exp $ + * $Id: wikilib.ml,v 1.13 2004/10/14 15:57:15 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 @@ -43,7 +43,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' .. ' ' | '<' | '>' | '&' | '"' | '+' -> '_' + String.map (function + '\000' .. ' ' | '<' | '>' | '&' | '"' | '+' | '#' | '%' + -> '_' | c -> Char.lowercase c) title in (* Check URL is not too trivial. *) @@ -91,7 +93,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 @@ -216,13 +218,14 @@ let markup_link dbh hostid link = let url, clasz, title = if Pcre.pmatch ~rex:url_re url then escape_html_tag url, "external", url (* http://.... *) - else if Pcre.pmatch ~rex:mailto_re url then ( + else if Pcre.pmatch ~rex:mailto_re url then obscure_mailto url, "mailto", url - ) else ( + else if String.length url >= 1 && url.[0] = '/' then (* /index etc. *) + escape_html_tag url, "internal", url + 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 @@ -234,7 +237,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 "