Links to empty template pages are now shown as ordinary links.
authorrich <rich>
Sat, 9 Oct 2004 09:48:37 +0000 (09:48 +0000)
committerrich <rich>
Sat, 9 Oct 2004 09:48:37 +0000 (09:48 +0000)
scripts/wikilib.ml

index 8d7b83b..619f049 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.9 2004/10/09 09:41:39 rich Exp $
+ * $Id: wikilib.ml,v 1.10 2004/10/09 09:48:37 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
@@ -221,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
@@ -234,6 +233,26 @@ let markup_link dbh hostid link =
          "/" ^ url, "internal", title
        with
            Not_found ->
+             (* 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