Modified all scripts with appropriate restrictions based on
authorrich <rich>
Wed, 8 Sep 2004 09:54:28 +0000 (09:54 +0000)
committerrich <rich>
Wed, 8 Sep 2004 09:54:28 +0000 (09:54 +0000)
editing capabilities.

26 files changed:
scripts/create.ml
scripts/create_form.ml
scripts/delete_file.ml
scripts/delete_file_form.ml
scripts/delete_image.ml
scripts/delete_image_form.ml
scripts/diff.ml
scripts/edit.ml
scripts/edit_page_css.ml
scripts/edit_page_css_form.ml
scripts/files.ml
scripts/history.ml
scripts/images.ml
scripts/page.ml
scripts/recent.ml
scripts/restore.ml
scripts/restore_form.ml
scripts/undelete_file.ml
scripts/undelete_file_form.ml
scripts/undelete_image.ml
scripts/undelete_image_form.ml
scripts/upload_file.ml
scripts/upload_file_form.ml
scripts/upload_image.ml
scripts/upload_image_form.ml
templates/page.html

index c7bc6f2..c1f5f23 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: create.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
+ * $Id: create.ml,v 1.3 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -75,4 +75,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
   q#redirect ("http://" ^ hostname ^ "/" ^ url ^ "/edit")
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 124be21..829b72a 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: create_form.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
+ * $Id: create_form.ml,v 1.3 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -38,4 +38,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 430d008..2efd82f 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: delete_file.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: delete_file.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -41,4 +41,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
     q#redirect ("http://" ^ hostname ^ "/_files")
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 11d2362..5283ad4 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: delete_file_form.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: delete_file_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -29,4 +29,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 1480e86..aa3bb1d 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: delete_image.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: delete_image.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -40,4 +40,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
     q#redirect ("http://" ^ hostname ^ "/_images")
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index f004f08..3efe9bc 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: delete_image_form.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: delete_image_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -37,4 +37,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index bf5eb42..ceeaed7 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: diff.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: diff.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -47,4 +47,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index c00c79d..410e9e0 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: edit.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -479,4 +479,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 43219aa..9c91d32 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_page_css.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: edit_page_css.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -88,4 +88,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
        "Note: You must RELOAD the page to see changes to stylesheets.")
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index c262495..ec9ff2f 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_page_css_form.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
+ * $Id: edit_page_css_form.ml,v 1.3 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -33,4 +33,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 3deb0f2..cfade36 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: files.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: files.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -48,4 +48,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index bc008c4..ae47e64 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: history.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: history.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -67,4 +67,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 30f585f..9484239 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: images.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: images.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -68,4 +68,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 1fcc223..53e6791 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: page.ml,v 1.4 2004/09/07 16:19:43 rich Exp $
+ * $Id: page.ml,v 1.5 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -26,7 +26,7 @@ type fp_status = FPOK of int * string * string * Dbi.datetime * bool
               | FPRedirect of string
               | FPNotFound
 
-let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) user =
+let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, edit_anon) user =
   let page = q#param "page" in
   let page = if page = "" then "index" else page in
 
@@ -39,6 +39,9 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) user =
       | [ `Bool has_host_css ] -> has_host_css
       | _ -> assert false in
 
+  (* Can the user edit? *)
+  let can_edit = can_edit edit_anon user in
+
   (* This code generates ordinary pages. *)
   let make_page title description pageid last_modified_date has_page_css
       version page page' =
@@ -62,6 +65,8 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) user =
     t#conditional "has_host_css" has_host_css;
     t#conditional "has_page_css" has_page_css;
 
+    t#conditional "can_edit" can_edit;
+
     (* Pull out the sections in this page. *)
     let sth = dbh#prepare_cached
                "select ordering, sectionname, content, divname
@@ -194,9 +199,13 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) user =
   in
 
   (* Here we deal with the complex business of redirects and versions. *)
-  let allow_redirect = not (q#param_true "no_redirect") in
-  let version =
-    try Some (int_of_string (q#param "version")) with Not_found -> None in
+  (* Only allow the no_redirect and version syntax for editors. *)
+  let allow_redirect, version =
+    if can_edit then (
+      not (q#param_true "no_redirect"),
+      try Some (int_of_string (q#param "version")) with Not_found -> None
+    ) else
+      (true, None) in
 
   let rec loop page' i =
     if i > max_redirect then (
index f726245..4af4886 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: recent.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: recent.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -67,4 +67,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index c8f9d3f..274a3e6 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: restore.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: restore.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -84,4 +84,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
     q#redirect ("http://" ^ hostname ^ "/" ^ page)
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index b7dde16..41e7c4a 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: restore_form.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: restore_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -47,4 +47,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index f95c1e9..8be78f6 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: undelete_file.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: undelete_file.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -52,4 +52,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
     q#redirect ("http://" ^ hostname ^ "/_files")
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 152842d..f8ada78 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: undelete_file_form.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: undelete_file_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -34,4 +34,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index e0d9f57..fbce7bf 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: undelete_image.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: undelete_image.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -57,4 +57,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
     q#redirect ("http://" ^ hostname ^ "/_images")
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index a287e42..0fe6ee3 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: undelete_image_form.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: undelete_image_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -38,4 +38,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 77c5e9e..bca6237 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: upload_file.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: upload_file.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -73,4 +73,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
     q "File was uploaded successfully."
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 24f8e22..8606a9d 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: upload_file_form.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: upload_file_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -18,4 +18,4 @@ let run r (q : cgi) (dbh : Dbi.connection) _ _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 579f609..c22fa45 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: upload_image.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: upload_image.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -122,4 +122,4 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
     q "Image was uploaded successfully."
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index bdd18f3..3706417 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: upload_image_form.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: upload_image_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
  *)
 
 open Apache
@@ -18,4 +18,4 @@ let run r (q : cgi) (dbh : Dbi.connection) _ _ =
   q#template template
 
 let () =
-  register_script run
+  register_script ~restrict:[CanEdit] run
index 986c5f1..10aab87 100644 (file)
 <li> Go to the <a href="/::page_html_tag::">live version</a> of this page.</li>
 <li> See other <a href="/::page_html_tag::/history">old versions</a> of this page.</li>
 <li> See the <a href="/::page_html_tag::/diff?version=::old_version::">differences</a> between this version and the previous version of this page.</li>
+::if(can_edit)::
 <li> <a href="/_bin/restore_form.cmo?page=::page_url::&version=::old_version::">Restore</a> this version live.</li>
+::end::
 </ul>
 </div>
 ::end::
 
 ::table(sections)::
-::if(has_divname)::<div id="::divname_html_tag::">::end::<p class="edit_link">[<a href="/::page_html_tag::/edit#::ordering::" title="Edit this section">edit</a>]</p><a name="::sectionname_html_tag::"></a><h2>::sectionname_html::</h2>
+::if(has_divname)::<div id="::divname_html_tag::">::end::::if(can_edit)::<p class="edit_link">[<a href="/::page_html_tag::/edit#::ordering::" title="Edit this section">edit</a>]</p>::end::<a name="::sectionname_html_tag::"></a><h2>::sectionname_html::</h2>
 ::content::
 ::if(has_divname)::</div>::end::::end::
 
 <ul id="topmenu" class="menu">
+::if(can_edit)::
 <li> <a href="/::page_html_tag::/edit"><strong>Edit&nbsp;this&nbsp;page</strong></a> | </li>
+::end::
 <li> <a href="/">Home&nbsp;page</a> | </li>
 <li> <a href="/_sitemap">Sitemap</a> | </li>
+::if(can_edit)::
 <li> <a href="/_recent">Recent&nbsp;changes</a> | </li>
 <li> <a href="/::page_html_tag::/history">Versions&nbsp;of&nbsp;this&nbsp;page</a> </li>
+::end::
 </ul>
 
 <ul id="bottommenu" class="menu">
+::if(can_edit)::
 <li> <a href="/::page_html_tag::/edit"><strong>Edit&nbsp;this&nbsp;page</strong></a> | </li>
+::end::
 <li> <a href="/">Home&nbsp;page</a> | </li>
 <li> <a href="/_sitemap">Sitemap</a> | </li>
+::if(can_edit)::
 <li> <a href="/_recent">Recent&nbsp;changes</a> | </li>
 <li> <a href="/::page_html_tag::/history">Versions&nbsp;of&nbsp;this&nbsp;page</a> | </li>
 <li> <a href="/_images">Images</a> | </li>
 <li> <a href="/_files">Files</a> | </li>
 <li> <a href="/::page_html_tag::/editcss">Edit&nbsp;stylesheet&nbsp;for&nbsp;this&nbsp;page</a> | </li>
 <li> <a href="/_bin/admin/admin.cmo">Wiki&nbsp;administration</a> | </li>
+::end::
 <li> ::if(user_logged_in):: ::username_html:: <a href="/_logout">(logout)</a> ::else:: <a href="/_login">Create&nbsp;account&nbsp;or&nbsp;login</a> ::end:: </li>
 </ul>