From: rich Date: Mon, 20 Sep 2004 15:34:36 +0000 (+0000) Subject: Very primitive, but working, RSS feeds. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=35f3941cfe3d70d720604da0b2c8850ef704a92d;p=cocanwiki.git Very primitive, but working, RSS feeds. --- diff --git a/MANIFEST b/MANIFEST index 692bd8d..0ec51e2 100644 --- a/MANIFEST +++ b/MANIFEST @@ -29,6 +29,7 @@ html/_graphics/markup-preview.png html/_graphics/newpage.png html/_graphics/ok.png html/_graphics/tick.png +html/_graphics/xml.png html/_js/editor.js html/_static/markup.html html/robots.txt @@ -93,6 +94,7 @@ scripts/preview.ml scripts/recent.ml scripts/restore.ml scripts/restore_form.ml +scripts/rss.ml scripts/search.ml scripts/signup.ml scripts/sitemap.ml @@ -136,6 +138,7 @@ templates/page.html templates/page_404.html templates/recent.html templates/restore_form.html +templates/rss.xml templates/sitemap.html templates/undelete_file_form.html templates/undelete_image_form.html diff --git a/Makefile b/Makefile index b6c340e..d063bad 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.6 2004/09/17 12:35:37 rich Exp $ +# $Id: Makefile,v 1.7 2004/09/20 15:34:36 rich Exp $ include Makefile.config @@ -38,7 +38,7 @@ pkg-install: install -m 0644 html/_graphics/*.png $(DESTDIR)$(WIKIINSTALLDIR)/html/_graphics install -m 0644 html/_js/*.js $(DESTDIR)$(WIKIINSTALLDIR)/html/_js install -m 0644 html/_static/*.html $(DESTDIR)$(WIKIINSTALLDIR)/html/_static - install -m 0644 templates/*.html templates/*.txt $(DESTDIR)$(WIKIINSTALLDIR)/templates + install -m 0644 templates/*.html templates/*.txt templates/*.xml $(DESTDIR)$(WIKIINSTALLDIR)/templates install -m 0644 templates/admin/*.html $(DESTDIR)$(WIKIINSTALLDIR)/templates/admin clean: diff --git a/conf/cocanwiki.conf b/conf/cocanwiki.conf index 4391c39..658aac2 100644 --- a/conf/cocanwiki.conf +++ b/conf/cocanwiki.conf @@ -1,5 +1,5 @@ # Apache configuration for COCANWIKI. -# $Id: cocanwiki.conf,v 1.4 2004/09/17 12:35:37 rich Exp $ +# $Id: cocanwiki.conf,v 1.5 2004/09/20 15:34:36 rich Exp $ # Uncomment the following lines if necessary. You will probably need # to adjust the paths to reflect where cocanwiki is really installed. @@ -70,6 +70,7 @@ 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 ^/([^_].*)/history$ /_bin/history.cmo?page=$1 [PT,L,QSA] +RewriteRule ^/([^_].*)/index.rss$ /_bin/rss.cmo?page=$1 [PT,L,QSA] RewriteRule ^/([^_].*)/styles.css$ /_bin/pagestyle.cmo?page=$1 [PT,L,QSA] # Serve pages. diff --git a/html/_graphics/xml.png b/html/_graphics/xml.png new file mode 100644 index 0000000..12e8d4a Binary files /dev/null and b/html/_graphics/xml.png differ diff --git a/scripts/.depend b/scripts/.depend index 39ea508..cf4a8c2 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -81,9 +81,9 @@ login_form.cmx: cocanwiki.cmx cocanwiki_strings.cmx cocanwiki_template.cmx logout.cmo: cocanwiki.cmo cocanwiki_ok.cmo logout.cmx: cocanwiki.cmx cocanwiki_ok.cmx page.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_ok.cmo \ - cocanwiki_template.cmi wikilib.cmi + cocanwiki_strings.cmo cocanwiki_template.cmi wikilib.cmi page.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_ok.cmx \ - cocanwiki_template.cmx wikilib.cmx + cocanwiki_strings.cmx cocanwiki_template.cmx wikilib.cmx pagestyle.cmo: cgi_expires.cmo cocanwiki.cmo pagestyle.cmx: cgi_expires.cmx cocanwiki.cmx preview.cmo: cocanwiki.cmo wikilib.cmi @@ -98,6 +98,8 @@ restore_form.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_ok.cmo \ cocanwiki_template.cmi restore_form.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_ok.cmx \ cocanwiki_template.cmx +rss.cmo: cocanwiki.cmo cocanwiki_template.cmi wikilib.cmi +rss.cmx: cocanwiki.cmx cocanwiki_template.cmx wikilib.cmx search.cmo: cocanwiki.cmo search.cmx: cocanwiki.cmx signup.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo diff --git a/scripts/Makefile b/scripts/Makefile index 2ac30f9..6cf7991 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.12 2004/09/17 16:03:34 rich Exp $ +# $Id: Makefile,v 1.13 2004/09/20 15:34:36 rich Exp $ include ../Makefile.config @@ -55,6 +55,7 @@ OBJS := 00-TEMPLATE.cmo \ recent.cmo \ restore.cmo \ restore_form.cmo \ + rss.cmo \ search.cmo \ signup.cmo \ sitemap.cmo \ diff --git a/scripts/cocanwiki.ml b/scripts/cocanwiki.ml index 837028a..ae07362 100644 --- a/scripts/cocanwiki.ml +++ b/scripts/cocanwiki.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki.ml,v 1.7 2004/09/17 15:24:54 rich Exp $ + * $Id: cocanwiki.ml,v 1.8 2004/09/20 15:34:36 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 @@ -25,6 +25,7 @@ open Cgi open Printf open Cocanwiki_ok +open Cocanwiki_strings module Pool = DbiPool (Dbi_postgres) @@ -188,3 +189,15 @@ let register_script ?(restrict = []) ?(anonymous = true) run = ~title:"Access denied" q "You do not have permission to access this part of the site." ) + +(* Convert a section name into something valid for use in + * XXX This breaks horribly for non-7-bit strings. + * XXX This is stuck here because we don't have a good place for it, and + * because it needs to be fixed for i18n compliance. + *) +let linkname_of_sectionname str = + let str = String.copy str in + for i = 0 to String.length str - 1 do + if not (isalnum str.[i]) then str.[i] <- '_' + done; + str diff --git a/scripts/page.ml b/scripts/page.ml index 366d34e..9378107 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.14 2004/09/20 11:11:15 rich Exp $ + * $Id: page.ml,v 1.15 2004/09/20 15:34:36 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 @@ -30,7 +30,6 @@ open Cocanwiki open Cocanwiki_template open Cocanwiki_ok open Cocanwiki_date -open Cocanwiki_strings (* Maximum level of redirection. *) let max_redirect = 4 @@ -60,17 +59,6 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = let can_manage_users = can_manage_users user in let can_manage_contacts = can_manage_contacts user in - (* Convert a section name into something valid for use in - * XXX This breaks horribly for non-7-bit strings. - *) - let linkname_of_sectionname str = - let str = String.copy str in - for i = 0 to String.length str - 1 do - if not (isalnum str.[i]) then str.[i] <- '_' - done; - str - in - (* This code generates ordinary pages. *) let make_page title description pageid last_modified_date has_page_css version page page' = diff --git a/scripts/rss.ml b/scripts/rss.ml new file mode 100644 index 0000000..5d35898 --- /dev/null +++ b/scripts/rss.ml @@ -0,0 +1,89 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: rss.ml,v 1.1 2004/09/20 15:34:36 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. + * + *--- + * + * This generates an RSS feed from a page. Articles in the RSS feed are + * mapped to sections in the page. At the moment it's fairly crude, but + * it's good enough for blogging at the moment. We can think about + * cleaning it up later. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template + +let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} _ = + let template = get_template dbh hostid "rss.xml" in + + let page = q#param "page" in + let page = if page = "" then "index" else page in + template#set "page" page; + + template#set "hostname" hostname; + + (* Get the title and description of the page. *) + let sth = dbh#prepare_cached "select id, title, description + from pages + where hostid = ? and url = ? + and redirect is null" in + sth#execute [`Int hostid; `String page]; + + let pageid, title, description = + match sth#fetch1 () with + [ `Int id; `String title; `String description ] -> + id, title, description + | _ -> assert false in + + template#set "title" title; + template#set "description" description; + + (* Get the sections in the live page. *) + let sth = dbh#prepare_cached "select sectionname, content, ordering + from contents + where pageid = ? + and sectionname is not null + order by ordering" in + sth#execute [`Int pageid]; + + let sections = + sth#map (function [`String sectionname; `String content; _] -> + sectionname, content + | _ -> assert false) in + + let sections = + List.map (fun (sectionname, content) -> + let content = Wikilib.xhtml_of_content dbh hostid content in + let linkname = linkname_of_sectionname sectionname in + [ "sectionname", Template.VarString sectionname; + "linkname", Template.VarString linkname; + "content", Template.VarString content ] + ) sections in + + template#table "sections" sections; + + q#template ~content_type:"text/xml" template + +let () = + register_script run diff --git a/templates/rss.xml b/templates/rss.xml new file mode 100644 index 0000000..9874255 --- /dev/null +++ b/templates/rss.xml @@ -0,0 +1,29 @@ + + + + ::title_html:: + http://::hostname_html_tag::/::page_html_tag:: + ::description_html:: + en-GB + + + ::table(sections):: + + ::end:: + + + +::table(sections):: + + ::sectionname_html:: + http://::hostname_html_tag::/::page_html_tag::#::linkname_html_tag:: + ::content_html_textarea:: + + + +::end:: +