From 35f3941cfe3d70d720604da0b2c8850ef704a92d Mon Sep 17 00:00:00 2001 From: rich Date: Mon, 20 Sep 2004 15:34:36 +0000 Subject: [PATCH] Very primitive, but working, RSS feeds. --- MANIFEST | 3 ++ Makefile | 4 +-- conf/cocanwiki.conf | 3 +- html/_graphics/xml.png | Bin 0 -> 568 bytes scripts/.depend | 6 ++-- scripts/Makefile | 3 +- scripts/cocanwiki.ml | 15 ++++++++- scripts/page.ml | 14 +------- scripts/rss.ml | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ templates/rss.xml | 29 ++++++++++++++++ 10 files changed, 146 insertions(+), 20 deletions(-) create mode 100644 html/_graphics/xml.png create mode 100644 scripts/rss.ml create mode 100644 templates/rss.xml 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 0000000000000000000000000000000000000000..12e8d4ad2fd17010d57b4e46d6b087e9f2c97efb GIT binary patch literal 568 zcmV-80>}M{P)bC zdL-m}G+ZVG>}nMJrff781l(E#+@5sw;?(?(MEusY{L-}i&a{j=1k`>+?82n{dK~PZY2Ev{QUa-^sa>bqGbH$)coSq^qO4Unr!sm%P3`{Nl{~-pt&VWTZ+A^wz}e z(!BhJG~|Xv{DL(6#-#LqEbMk9?6#ErZVdct4CHDY^kxL~Vg&s5?ELcV)LsniqHO${ zRQ#4y^pZ^Uj!fK+T=dSo)QVL6f-L;ToczL^+;%klY6Sdd1mtEE{O;uZ>g4>EO#G5e z{MNkDN)f66008JoL_t(|oMVU(#tQ-%!h(W=0)ub@K8A20siZHd6yz&u#;C_C7-Z|l z>Z_#Z4p#s&LC8{FLx@M(+*3+SB1j=bOvg&fP#f8VATw!a%Me+Ya4Gc=WmR!84kjrR zc4QNRg4~?cMO?JFq)gNWqz%P56s6?YQA`Nra#r)U4+@tOu@N(o#bSb$fdPZFrX5g$ zBCnAT$OKMNMnPM+34(s1J^@nF9zX@bj_mRv1W(gLy_wHzHmG>8$Tr458&6O5Vh0yY55BT4N-)wLD?0000. * 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:: + -- 1.8.3.1