# Apache configuration for COCANWIKI.
-# $Id: cocanwiki.conf,v 1.20 2004/11/04 22:18:47 rich Exp $
+# $Id: cocanwiki.conf,v 1.21 2004/11/22 11:07:32 rich Exp $
# Uncomment the following lines if necessary. You will probably need
# to adjust the paths to reflect where cocanwiki is really installed.
RewriteRule ^/([^_].*)/diff$ /_bin/diff.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/edit$ /_bin/edit.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/editcss$ /_bin/edit_page_css_form.cmo?page=$1 [PT,L,QSA]
-RewriteRule ^/([^_].*)/edittitle$ /_bin/edit_page_title_form.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/history$ /_bin/history.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/history.rss$ /_bin/history_rss.cmo?page=$1 [PT,L,QSA]
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 ^/([^_].*)/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: edit_page_title.ml,v 1.6 2004/10/30 10:16:10 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_emailnotify
-open Cocanwiki_strings
-
-let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
- let page = q#param "page" in
- let new_title = trim (q#param "title") in
-
- (* Get the old title. *)
- let sth = dbh#prepare_cached "select title from pages
- where hostid = ? and url = ?" in
- sth#execute [`Int hostid; `String page];
-
- let old_title = sth#fetch1string () in
-
- (* New title mustn't be empty string. *)
- if new_title = "" then (
- error ~back_button:true ~title:"Empty title not allowed"
- q "The new title cannot be empty.";
- return ()
- );
-
- (* If it's the index page, then they can change the title however
- * they want. On other pages, however, you are only allowed limited
- * edits which preserve the title -> url mapping.
- *)
- if page <> "index" then (
- let new_page =
- match Wikilib.generate_url_of_title dbh hostid new_title with
- Wikilib.GenURL_OK url -> url
- | Wikilib.GenURL_TooShort
- | Wikilib.GenURL_BadURL -> ""
- | Wikilib.GenURL_Duplicate url -> url in
-
- if new_page <> page then (
- error ~back_button:true ~title:"Title altered too much"
- q ("The new title is too different from the old one. You can only " ^
- "make limited changes to the title of a page. The manual " ^
- "describes why, and how to copy pages instead.");
- return ()
- )
- );
-
- (* Get the IP address of the user, if available. *)
- let logged_ip =
- try `String (Connection.remote_ip (Request.connection r))
- with Not_found -> `Null in
-
- let logged_user =
- match user with
- | User (id, _, _, _) -> `Int id
- | _ -> `Null in
-
- (* Changing the title creates a new version of the page. This enables
- * us to revert changes.
- *)
- let sth = dbh#prepare_cached "select id, description, creation_date,
- redirect, css
- from pages
- where hostid = ? and url = ?" in
- sth#execute [`Int hostid; `String page];
-
- let oldpageid, description, creation_date, redirect, css =
- match sth#fetch1 () with
- [ `Int id; description; creation_date; redirect; css ] ->
- id, description, creation_date, redirect, css
- | _ -> assert false in
-
- let sth = dbh#prepare_cached
- "set constraints pages_redirect_cn, sitemenu_url_cn,
- page_emails_url_cn, links_from_cn, recently_visited_url_cn
- deferred" in
- sth#execute [];
-
- let sth = dbh#prepare_cached "update pages set url_deleted = url,
- url = null
- where hostid = ? and id = ?" in
- sth#execute [`Int hostid; `Int oldpageid];
-
- let sth = dbh#prepare_cached "insert into pages (hostid, url, title,
- description, creation_date, logged_ip,
- logged_user, redirect, css)
- values (?, ?, ?, ?, ?, ?, ?, ?, ?)" in
- sth#execute [`Int hostid; `String page; `String new_title; description;
- creation_date; logged_ip; logged_user; redirect; css ];
-
- let pageid = sth#serial "pages_id_seq" in
-
- let sth = dbh#prepare_cached "insert into contents (pageid, ordering,
- sectionname, content, divname)
- select ? as pageid, ordering, sectionname,
- content, divname
- from contents
- where pageid = ?" in
- sth#execute [`Int pageid; `Int oldpageid];
-
- dbh#commit ();
-
- (* Email notification. *)
- let subject = "Title of page " ^ page ^ " has been modified" in
- let body = fun () ->
- "Page: http://" ^ hostname ^ "/" ^ page ^ "\n\n" ^
- "Old title: " ^ old_title ^ "\n" ^
- "New title: " ^ new_title ^ "\n" in
-
- email_notify ~subject ~body ~user dbh hostid;
-
- let buttons = [ ok_button ("/" ^ page) ] in
- ok ~title:"Title changed" ~buttons
- q "The page title was changed successfully."
-
-let () =
- register_script ~restrict:[CanEdit] run
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_pages.ml,v 1.2 2004/10/30 10:16:10 rich Exp $
+ * $Id: cocanwiki_pages.ml,v 1.3 2004/11/22 11:07:32 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
creation_date, url, title, css
| _ -> assert false in
+ (* Title changed? *)
+ let title =
+ match model.pt with
+ Title new_title when title <> new_title -> new_title
+ | _ -> title in
+
(* Has someone else edited this page in the meantime? *)
let sth = dbh#prepare_cached "select max(id) from pages
where hostid = ? and url = ?" in
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: page.ml,v 1.39 2004/11/05 11:35:53 rich Exp $
+ * $Id: page.ml,v 1.40 2004/11/22 11:07:32 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
t#set "search_terms" search_terms;
- t#conditional "has_host_css" has_host_css;
t#conditional "can_edit" can_edit;
t#conditional "can_manage_users" can_manage_users;
t#conditional "has_stats" has_stats;
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: rename_page.ml,v 1.1 2004/11/22 11:07:32 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
+
+let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
+ let page = q#param "page" in
+
+ (* Cancelled? *)
+ if q#param_true "cancel" then (
+ q#redirect ("http://" ^ hostname ^ "/" ^ page);
+ return ()
+ );
+
+ 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"
+ q "The new title cannot be empty.";
+ return ()
+ );
+
+ (* Get the old title. *)
+ let sth = dbh#prepare_cached "select title from pages
+ where hostid = ? and url = ?" in
+ sth#execute [`Int hostid; `String page];
+
+ let old_title = sth#fetch1string () in
+
+ (* Generate URL for the new title. *)
+ let new_page =
+ if page = "index" then page
+ else
+ match Wikilib.generate_url_of_title 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
+ 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 (
+ (* If it's the same as the old URL, then this is a simple title change. *)
+ let model = load_page dbh hostid ~url:page () in
+ let model = { model with pt = Title new_title } in
+ let url, _ = save_page dbh hostid ~user ~r model in
+ assert (url = new_page)
+ ) else (
+ (* Not the same as the old URL, so set the old page to a redirect and
+ * create a new page.
+ *)
+ 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;
+ contents = old_model.contents } in
+ let old_model = { old_model with redirect = new_page } in
+ save_page dbh hostid ~user ~r old_model;
+
+ try
+ ignore (save_page dbh hostid ~user ~r new_model)
+ with
+ SaveURLError ->
+ error ~title:"Page exists"
+ q ("Another page with the same title exists. " ^
+ "If you tried to rename a page, then rename it back to the " ^
+ "original title, then you may see this error. This is a bug " ^
+ "which you should raise with the site administrator.");
+ return ()
+ );
+
+ (* Finish off XXX *)
+ dbh#commit ();
+
+ let buttons = [ ok_button ("/" ^ new_page) ] in
+ ok ~title:"Page renamed" ~buttons
+ q "That page was renamed."
+
+let () =
+ register_script ~restrict:[CanEdit] run
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_page_title_form.ml,v 1.1 2004/09/25 16:05:03 rich Exp $
+ * $Id: rename_page_form.ml,v 1.1 2004/11/22 11:07:32 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
open Cocanwiki_template
let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
- let template = get_template dbh hostid "edit_page_title_form.html" in
+ let template = get_template dbh hostid "rename_page_form.html" in
let page = q#param "page" in
let title = sth#fetch1string () in
template#set "page" page;
- template#conditional "limited_changes" (page <> "index");
template#set "title" title;
q#template template
<li class="versions_li"> <a href="/::page_html_tag::/history">Versions of this page</a> </li>
<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="edittitle_li"> <a href="/::page_html_tag::/edittitle">Rename page</a> </li>
+<li class="rename_li"> <a href="/::page_html_tag::/rename">Rename 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>
<meta name="author" content="http://www.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"/>
-::if(has_host_css)::<link rel="stylesheet" href="/_global.css" type="text/css" title="Standard"/>::end::
</head><body>
<h1><span>Page not found</span></h1>
<!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>Edit page title</title>
+<title>Rename page</title>
<meta name="author" content="http://www.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>Edit page title</span></h1>
+<h1><span>Rename page</span></h1>
-<form method="post" action="/_bin/edit_page_title.cmo">
+<form method="post" action="/_bin/rename_page.cmo">
<input type="hidden" name="page" value="::page_html_tag::"/>
<table class="left_table">
<tr>
<tr>
<th> New title: </th>
-<td> <input name="title" value="::title_html_tag::" size="50" /> </td>
+<td> <input name="new_title" value="::title_html_tag::" size="50" /> </td>
</tr>
-::if(limited_changes)::
<tr>
-<th> Warning: </th>
+<td></td>
<td>
-You can only make limited changes to this title, such as
-changing lowercase to Uppercase.
-<a target="_blank" href="http://help.merjis.com/title_changes">Why is this?</a>
+ <input type="submit" name="submit" value=" Rename page "/>
+ <input type="submit" name="cancel" value=" Cancel "/>
</td>
</tr>
-::end::
-
-<tr>
-<td></td>
-<td> <input type="submit" value=" Save changes "/> </td>
-</tr>
</table>
</form>