scripts/delete_user.ml
scripts/delete_user_form.ml
scripts/diff.ml
+scripts/duplicate_page.ml
+scripts/duplicate_page_form.ml
scripts/edit.ml
scripts/edit_contact.ml
scripts/edit_contact_form.ml
templates/delete_macro_form.html
templates/delete_user_form.html
templates/diff.html
+templates/duplicate_page_form.html
templates/edit.html
templates/edit_conflict.html
templates/edit_contact_form.html
# Apache configuration for COCANWIKI.
-# $Id: cocanwiki.conf,v 1.25 2006/12/06 09:46:54 rich Exp $
+# $Id: cocanwiki.conf,v 1.26 2006/12/11 16:59:29 rich Exp $
# Uncomment the following lines if necessary. You will probably need
# to adjust the paths to reflect where cocanwiki is really installed.
RewriteRule ^/([^_].*)/index.rss$ /_bin/page_rss.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/links$ /_bin/links.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/rename$ /_bin/rename_page_form.cmo?page=$1 [PT,L,QSA]
+RewriteRule ^/([^_].*)/duplicate$ /_bin/duplicate_page_form.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/source$ /_bin/source.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/stats$ /_bin/stats.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/styles.css$ /_bin/pagestyle.cmo?page=$1 [PT,L,QSA]
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: duplicate_page.ml,v 1.1 2006/12/11 16:59:29 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_ok
+open Cocanwiki_pages
+open Cocanwiki_strings
+open Cocanwiki_emailnotify
+
+let run r (q : cgi) dbh hostid {hostname = hostname} user =
+ let page = q#param "page" in
+
+ (* Cancelled? *)
+ if q#param_true "cancel" then
+ q#redirect ("http://" ^ hostname ^ "/" ^ page);
+
+ let new_title = trim (q#param "new_title") in
+
+ (* New title mustn't be empty string. *)
+ if new_title = "" then (
+ error ~back_button:true ~title:"Empty title not allowed"
+ r dbh hostid q "The new title cannot be empty.";
+ return ()
+ );
+
+ (* Get the old title. *)
+ let old_title = List.hd (
+ PGSQL (dbh) "select title from pages
+ where hostid = $hostid and url = $page"
+ ) in
+
+ (* Generate URL for the new title. *)
+ let new_page =
+ if page = "index" then page
+ else
+ match Wikilib.generate_url_of_title r dbh hostid new_title with
+ | Wikilib.GenURL_OK url | Wikilib.GenURL_Duplicate url -> url
+ | Wikilib.GenURL_TooShort | Wikilib.GenURL_BadURL ->
+ error ~title:"Bad title" ~back_button:true
+ r dbh hostid q
+ ("The new title for the page isn't valid. " ^
+ "It may be too short or it may not contain " ^
+ "enough alphabet letters.");
+ return () in
+
+ if page = new_page then (
+ (* This is an error - the new page must have a new URL. *)
+ error ~back_button:true ~title:"Bad title"
+ r dbh hostid q "The new title must be different from the old title in a significant way (eg. not just a change of capitalisation).";
+ return ()
+ );
+
+ (* Create the new page from the old one. *)
+ let old_model = load_page dbh hostid ~url:page () in
+ let new_model = new_page_with_title new_title in
+ let new_model = { new_model with
+ description = old_model.description;
+ keywords = old_model.keywords;
+ noodp = old_model.noodp;
+ contents_ = old_model.contents_ } in
+ (try
+ ignore (save_page r dbh hostid ~user new_model)
+ with
+ SaveURLError ->
+ error ~title:"Page exists"
+ r dbh hostid q
+ "Another page with the same title exists.";
+ return ()
+ );
+
+ (* Finish off. *)
+ PGOCaml.commit dbh;
+
+ (* Email notification. *)
+ let subject = "Page " ^ page ^ " has been duplicated" in
+
+ let body = fun () ->
+ "Old title: " ^ old_title ^ "\n" ^
+ "New title: " ^ new_title in
+
+ email_notify ~body ~subject ~user dbh hostid;
+
+ let buttons = [ ok_button ("/" ^ new_page) ] in
+ ok ~title:"Page duplicated." ~buttons
+ r dbh hostid q "That page was duplicated."
+
+let () =
+ register_script ~restrict:[CanEdit] run
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: duplicate_page_form.ml,v 1.1 2006/12/11 16:59:29 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+
+let run r (q : cgi) dbh hostid _ _ =
+ let template = get_template r dbh hostid "duplicate_page_form.html" in
+
+ let page = q#param "page" in
+
+ let title = List.hd (
+ PGSQL(dbh) "select title from pages
+ where hostid = $hostid and url = $page"
+ ) in
+
+ template#set "page" page;
+ template#set "title" title;
+
+ q#template template
+
+let () =
+ register_script ~restrict:[CanEdit] run
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Duplicate page</title>
+<meta name="author" content="http://merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+<link rel="alternate stylesheet" href="/_css/easytoread.css" type="text/css" title="High contrast, big fonts"/>
+</head><body>
+
+<h1><span>Duplicate page</span></h1>
+
+<form method="post" action="/_bin/duplicate_page.cmo">
+<input type="hidden" name="page" value="::page_html_tag::"/>
+<table class="left_table">
+<tr>
+<th> Current title: </th> <td> <strong>::title_html::</strong> </td>
+</tr>
+
+<tr>
+<th> New title: </th>
+<td> <input name="new_title" value="::title_html_tag::" size="50" /> </td>
+</tr>
+
+<tr>
+<td></td>
+<td>
+ <input type="submit" name="submit" value=" Duplicate page "/>
+ <input type="submit" name="cancel" value=" Cancel "/>
+</td>
+</tr>
+</table>
+</form>
+
+::include(footer.html)::
+</body>
+</html>
\ No newline at end of file
<li class="wlh_li"> <a href="/_bin/what_links_here.cmo?page=::page_url::">What links here?</a> </li>
<li class="stylesheet_li"> <a href="/::page_html_tag::/editcss">Edit stylesheet</a> </li>
<li class="rename_li"> <a href="/::page_html_tag::/rename">Rename page</a> </li>
+<li class="duplicate_li"> <a href="/::page_html_tag::/duplicate">Duplicate page</a> </li>
<li class="new_li"> <a href="/_bin/new_page_form.cmo">New page</a> </li>
<li class="images_li"> <a href="/_images">Images</a> </li>
<li class="files_li"> <a href="/_files">Files</a> </li>