editing capabilities.
(* 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
q#redirect ("http://" ^ hostname ^ "/" ^ url ^ "/edit")
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#redirect ("http://" ^ hostname ^ "/_files")
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#redirect ("http://" ^ hostname ^ "/_images")
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
"Note: You must RELOAD the page to see changes to stylesheets.")
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
| 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
| [ `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' =
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
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 (
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#redirect ("http://" ^ hostname ^ "/" ^ page)
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#redirect ("http://" ^ hostname ^ "/_files")
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#redirect ("http://" ^ hostname ^ "/_images")
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q "File was uploaded successfully."
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q "Image was uploaded successfully."
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
(* 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
q#template template
let () =
- register_script run
+ register_script ~restrict:[CanEdit] run
<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 this page</strong></a> | </li>
+::end::
<li> <a href="/">Home page</a> | </li>
<li> <a href="/_sitemap">Sitemap</a> | </li>
+::if(can_edit)::
<li> <a href="/_recent">Recent changes</a> | </li>
<li> <a href="/::page_html_tag::/history">Versions of this page</a> </li>
+::end::
</ul>
<ul id="bottommenu" class="menu">
+::if(can_edit)::
<li> <a href="/::page_html_tag::/edit"><strong>Edit this page</strong></a> | </li>
+::end::
<li> <a href="/">Home page</a> | </li>
<li> <a href="/_sitemap">Sitemap</a> | </li>
+::if(can_edit)::
<li> <a href="/_recent">Recent changes</a> | </li>
<li> <a href="/::page_html_tag::/history">Versions of this 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 stylesheet for this page</a> | </li>
<li> <a href="/_bin/admin/admin.cmo">Wiki administration</a> | </li>
+::end::
<li> ::if(user_logged_in):: ::username_html:: <a href="/_logout">(logout)</a> ::else:: <a href="/_login">Create account or login</a> ::end:: </li>
</ul>