Allow username field to be prepopulated.
[cocanwiki.git] / scripts / wikilib.ml
index 619f049..f4b309b 100644 (file)
@@ -1,7 +1,7 @@
 (* 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.10 2004/10/09 09:48:37 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 = "</?(?:b|i|strong|em|code|sup|sub|nowiki|br)>" 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
@@ -216,9 +218,11 @@ 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.
@@ -425,15 +429,17 @@ 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
   let headers = [ "h3", []; "h4", []; "h5", []; "h6", [] ] in
-  let links = [ "a", ["href"] ] in
+  let links = [ "a", ["href"; "name"] ] in
   let images = [ "img", ["src"; "alt"; "width"; "height"; "longdesc"] ] in
 
   let forms = [