[cgi-wiki-dev] CGI::Wiki::Plugin::RSS::ModWiki
Earle Martin
cgi-wiki-dev@earth.li
Tue, 5 Apr 2005 19:28:57 +0100
--Fba/0zbH8Xs+Fj9o
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hello,
(Quiet round these parts.)
In responding to a request from Jo Walsh yesterday to add some rdfs:seeAlso
properties to the items in the london.openguides.org RSS feed, I took a look
at the code of C::W::P::R::MW for the first time and realised it could do
with some changing.
Namely, the code appears to have been based on part of
http://www.usemod.com/cgi-bin/wiki.pl?WikiPatches/XmlRss which in itself is
really not the best code it could be. In particular, it uses XML::RSS to do
a lot of stuff that could be seamlessly replaced with simple string
concatenation, and by relying on XML::RSS's pre-rolled methods to generate
things like "<dc:title>Something Or Other</dc:title>" you lose the ability
to write your own custom RDF.
So, I stripped out anything to do with XML::RSS and replaced it with a bunch
of simple strings. I can't prove it, but my instincts tell me the resulting
code actually runs a little faster. (Certainly no objects are generated and
laden with attributes etcetera.) I've actually put it to run live, and the
result can be seen at http://london.openguides.org/?action=rss .
A patch is attached to this message for my update. Kake, could you do the
honours? I'm not sure if CGI::Wiki provides an RDF option, though - at
least, I don't think it does - so you'll need to remove the four lines that
match "$rdf_url". This is the complete patch just so you can see what I did.
I should probably work out a way to get those lines into OpenGuides::RDF
somehow - any suggestions, anyone?
I'm not sure how many CGI::Wiki modules (and consequently OpenGuides
modules) use any of the XML::* modules, but hopefully this will cut down the
dependencies a bit.
Cheers,
Earle.
hopefully this will cut down
--
Earle Martin
http://downlode.org/
http://purl.oclc.org/net/earlemartin/
--Fba/0zbH8Xs+Fj9o
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="noxmlrss.patch"
--- ModWiki.pm.bak 2005-04-04 22:37:07.000000000 +0100
+++ ModWiki.pm 2005-04-05 00:22:23.000000000 +0100
@@ -5,7 +5,6 @@
use vars qw( $VERSION );
$VERSION = '0.06';
-use XML::RSS;
use Time::Piece;
use URI::Escape;
use Carp qw( croak );
@@ -78,10 +77,6 @@
C<wiki> must be a L<CGI::Wiki> object. C<make_node_url>, and
C<make_diff_url> and C<make_history_url>, if supplied, must be coderefs.
-B<NOTE:> If you try to put ampersands (C<&>) in your URLs then
-L<XML::RSS> will escape them to C<&>, so use semicolons (C<;>) to
-separate any CGI parameter pairs instead.
-
The mandatory arguments are:
=over 4
@@ -180,27 +175,27 @@
sub recent_changes {
my ($self, %args) = @_;
- my $rss = new XML::RSS (version => '1.0');
-
- $rss->add_module(
- prefix => 'wiki',
- uri => 'http://purl.org/rss/1.0/modules/wiki/'
- );
-
my $time = localtime;
my $timestamp = $time->strftime( "%Y-%m-%dT%H:%M:%S" );
- $rss->channel(
- title => $self->{site_name},
- link => $self->{recent_changes_link},
- description => $self->{site_description},
- dc => {
- date => $timestamp
- },
- wiki => {
- interwiki => $self->{interwiki_identifier}
- }
- );
+ my $rss = qq{<?xml version="1.0" encoding="UTF-8"?>
+
+<rdf:RDF
+ xmlns = "http://purl.org/rss/1.0/"
+ xmlns:dc = "http://purl.org/dc/elements/1.1/"
+ xmlns:wiki = "http://purl.org/rss/1.0/modules/wiki/"
+ xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:rdfs = "http://www.w3.org/2000/01/rdf-schema#"
+>
+
+<channel rdf:about="} . $self->{recent_changes_link} . qq{">
+<title>} . $self->{site_name} . qq{</title>
+<link>} . $self->{recent_changes_link} . qq{</link>
+<description>} . $self->{site_description} . qq{</description>
+<dc:date>} . $timestamp . qq{</dc:date>
+<wiki:interwiki>} . $self->{interwiki_identifier} . qq{</wiki:interwiki>};
+
+ my (@urls, @items);
# If we're not passed any parameters to limit the items returned,
# default to 15, which is apparently the modwiki standard.
@@ -242,6 +237,8 @@
my $url = $self->{make_node_url}->( $node_name, $version );
+ push @urls, qq{ <rdf:li rdf:resource="$url" />\n};
+
my $diff_url = "";
if ( $self->{make_diff_url} ) {
$diff_url = $self->{make_diff_url}->( $node_name );
@@ -252,25 +249,38 @@
$history_url = $self->{make_history_url}->( $node_name );
}
- $rss->add_item(
- title => $node_name,
- link => $url,
- description => $description,
- dc => {
- date => $timestamp,
- contributor => $author,
- },
- wiki => {
- status => $status,
- importance => $importance,
- diff => $diff_url,
- version => $version,
- history => $history_url
- },
- );
- }
+ my $node_url = $self->{make_node_url}->( $node_name );
- return $rss->as_string;
+ my $rdf_url = $node_url;
+ $rdf_url =~ s/\?/\?id=/;
+ $rdf_url .= ';format=rdf';
+
+ push @items, qq{
+<item rdf:about="$url">
+ <title>$node_name</title>
+ <link>$url</link>
+ <description>$description</description>
+ <dc:date>$timestamp</dc:date>
+ <dc:contributor>$author</dc:contributor>
+ <wiki:status>$status</wiki:status>
+ <wiki:importance>$importance</wiki:importance>
+ <wiki:diff>$diff_url</wiki:diff>
+ <wiki:version>$version</wiki:version>
+ <wiki:history>$history_url</wiki:history>
+ <rdfs:seeAlso rdf:resource="$rdf_url" />
+</item>
+};
+ }
+
+ $rss .= qq{
+<items>
+ <rdf:Seq>
+} . join('', @urls) . qq{ </rdf:Seq>
+</items>
+</channel>
+} . join('', @items) . "\n</rdf:RDF>\n";
+
+ return $rss;
}
=head1 SEE ALSO
@@ -296,12 +306,9 @@
=head1 CREDITS
-The people on #core on irc.rhizomatic.net gave encouragement and
+The people on #swig on irc.freenode.net gave encouragement and
useful advice.
-I cribbed some of this code from
-L<http://www.usemod.com/cgi-bin/wiki.pl?WikiPatches/XmlRss>
-
=cut
--Fba/0zbH8Xs+Fj9o--