From: rich Date: Sat, 25 Sep 2004 16:05:03 +0000 (+0000) Subject: Edit page title. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=d393f7e88c96b944d447a959935cfe84722a72b7;p=cocanwiki.git Edit page title. Updated MANIFEST. Bumped for release. --- diff --git a/MANIFEST b/MANIFEST index b929636..82433a5 100644 --- a/MANIFEST +++ b/MANIFEST @@ -92,6 +92,8 @@ scripts/edit_host_settings.ml scripts/edit_host_settings_form.ml scripts/edit_page_css.ml scripts/edit_page_css_form.ml +scripts/edit_page_title.ml +scripts/edit_page_title_form.ml scripts/edit_sitemenu.ml scripts/edit_user.ml scripts/edit_user_form.ml @@ -170,6 +172,7 @@ templates/edit_host_css_form.html templates/edit_host_settings_form.html templates/edit_page_css_form.html templates/edit_page_email.txt +templates/edit_page_title_form.html templates/edit_sitemenu.html templates/edit_user_form.html templates/files.html diff --git a/conf/cocanwiki.conf b/conf/cocanwiki.conf index 0731e9c..1dd6854 100644 --- a/conf/cocanwiki.conf +++ b/conf/cocanwiki.conf @@ -1,5 +1,5 @@ # Apache configuration for COCANWIKI. -# $Id: cocanwiki.conf,v 1.10 2004/09/24 17:07:10 rich Exp $ +# $Id: cocanwiki.conf,v 1.11 2004/09/25 16:05:03 rich Exp $ # Uncomment the following lines if necessary. You will probably need # to adjust the paths to reflect where cocanwiki is really installed. @@ -74,6 +74,7 @@ RewriteRule ^/_dist/ / [R] 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 ^/([^_].*)/index.rss$ /_bin/rss.cmo?page=$1 [PT,L,QSA] RewriteRule ^/([^_].*)/stats$ /_bin/stats.cmo?page=$1 [PT,L,QSA] diff --git a/debian/changelog b/debian/changelog index e7565c8..826d150 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -cocanwiki (1.1.1-4) unstable; urgency=low +cocanwiki (1.1.1-5) unstable; urgency=low * Initial Release. diff --git a/scripts/Makefile b/scripts/Makefile index ff2f470..a3179c6 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.26 2004/09/25 13:17:00 rich Exp $ +# $Id: Makefile,v 1.27 2004/09/25 16:05:03 rich Exp $ include ../Makefile.config @@ -53,6 +53,8 @@ OBJS := 00-TEMPLATE.cmo \ edit_host_settings_form.cmo \ edit_page_css.cmo \ edit_page_css_form.cmo \ + edit_page_title.cmo \ + edit_page_title_form.cmo \ edit_sitemenu.cmo \ edit_user.cmo \ edit_user_form.cmo \ diff --git a/scripts/edit_page_title.ml b/scripts/edit_page_title.ml new file mode 100644 index 0000000..c05d897 --- /dev/null +++ b/scripts/edit_page_title.ml @@ -0,0 +1,139 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: edit_page_title.ml,v 1.1 2004/09/25 16:05:03 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 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 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 diff --git a/scripts/edit_page_title_form.ml b/scripts/edit_page_title_form.ml new file mode 100644 index 0000000..d968901 --- /dev/null +++ b/scripts/edit_page_title_form.ml @@ -0,0 +1,48 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: edit_page_title_form.ml,v 1.1 2004/09/25 16:05:03 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 : Dbi.connection) hostid _ _ = + let template = get_template dbh hostid "edit_page_title_form.html" in + + let page = q#param "page" in + + let sth = dbh#prepare_cached "select title from pages + where hostid = ? and url = ?" in + sth#execute [`Int hostid; `String page]; + + let title = sth#fetch1string () in + + template#set "page" page; + template#conditional "limited_changes" (page <> "index"); + template#set "title" title; + + q#template template + +let () = + register_script ~restrict:[CanEdit] run diff --git a/scripts/wikilib.ml b/scripts/wikilib.ml index 77ba13a..081385f 100644 --- a/scripts/wikilib.ml +++ b/scripts/wikilib.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: wikilib.ml,v 1.6 2004/09/17 15:09:48 rich Exp $ + * $Id: wikilib.ml,v 1.7 2004/09/25 16:05:03 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 @@ -42,8 +42,9 @@ let nontrivial_re = Pcre.regexp ~flags:[`CASELESS] "[a-z0-9]" let generate_url_of_title (dbh : Dbi.connection) hostid title = (* Create a suitable URL from this title. *) - let url = String.map (function '\000' .. ' ' | '<' | '>' | '&' | '"' -> '_' - | c -> Char.lowercase c) title in + let url = + String.map (function '\000' .. ' ' | '<' | '>' | '&' | '"' | '+' -> '_' + | c -> Char.lowercase c) title in (* Check URL is not too trivial. *) if not (Pcre.pmatch ~rex:nontrivial_re url) then diff --git a/templates/edit_page_title_form.html b/templates/edit_page_title_form.html new file mode 100644 index 0000000..bd66469 --- /dev/null +++ b/templates/edit_page_title_form.html @@ -0,0 +1,66 @@ + + + +Edit page title + + + + +

Edit page title

+ +
+ + + + + + + + + + + +::if(limited_changes):: + + + + +::end:: + + + + + +
Current title: ::title_html::
New title:
Warning: +You can only make limited changes to this title, such as +changing lowercase to Uppercase. +Why is this? +
+
+ + + + + + + + + \ No newline at end of file diff --git a/templates/page.html b/templates/page.html index 6b67969..0d35ebc 100644 --- a/templates/page.html +++ b/templates/page.html @@ -62,6 +62,7 @@
  • Recent changes
  • Versions of this page
  • Edit stylesheet for this page
  • +
  • Edit title
  • Edit site menu
  • Largest pages
  • Images