Changeset 753


Ignore:
Timestamp:
Apr 5, 2006, 2:26:00 AM (15 years ago)
Author:
Earle Martin
Message:

New module, OpenGuides::Feed: this extracts the stuff formerly in OpenGuides::RDF (as sub make_recentchanges_rss) that was invoking CGI::Wiki::Plugin::RSS::ModWiki, and replaces it with a single make_feed method that can be used for any feed format, including Atom (using the new CGI::Wiki::Plugin::Atom). Changes to OpenGuides.pm and wiki.cgi are to use this new module appropriately.

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r733 r753  
    221221        'CGI::Wiki'                       => '0.62',  # fixed delete version
    222222        'CGI::Wiki::Formatter::UseMod'    => '0.16',  # macros
     223        'CGI::Wiki::Plugin::Atom'         => 0,
    223224        'CGI::Wiki::Plugin::Categoriser'  => 0,
    224225        'CGI::Wiki::Plugin::Diff'         => '0.08',  # earlier buggy
  • trunk/MANIFEST

    r742 r753  
    1818lib/OpenGuides/CGI.pm
    1919lib/OpenGuides/Config.pm
     20lib/OpenGuides/Feed.pm
    2021lib/OpenGuides/RDF.pm
    2122lib/OpenGuides/Search.pm
  • trunk/PREREQUISITES

    r743 r753  
    99CGI::Wiki (version 0.62 or later)
    1010CGI::Wiki::Formatter::UseMod (version 0.16 or later)
     11CGI::Wiki::Plugin::Atom
    1112CGI::Wiki::Plugin::Categoriser
    1213CGI::Wiki::Plugin::Diff (version 0.08 or later)
  • trunk/lib/OpenGuides.pm

    r752 r753  
    77use CGI::Wiki::Plugin::Locator::Grid;
    88use OpenGuides::CGI;
     9use OpenGuides::Feed;
    910use OpenGuides::Template;
    1011use OpenGuides::Utils;
     
    1415use vars qw( $VERSION );
    1516
    16 $VERSION = '0.52';
     17$VERSION = '0.53';
    1718
    1819=head1 NAME
     
    155156        $tt_vars{"rss_".lc($type)."_url"} =
    156157                           $config->script_name . "?action=rc;format=rss;"
     158                           . lc($type) . "=" . lc(CGI->escape($2));
     159        $tt_vars{"atom_".lc($type)."_url"} =
     160                           $config->script_name . "?action=rc;format=atom;"
    157161                           . lc($type) . "=" . lc(CGI->escape($2));
    158162    }
     
    637641}
    638642
    639 =item B<display_rss>
    640 
    641   # Last ten non-minor edits to Hammersmith pages.
    642   $guide->display_rss(
     643=item B<display_feed>
     644
     645  # Last ten non-minor edits to Hammersmith pages in RSS 1.0 format
     646  $guide->display_feed(
     647                         feed_type          => 'rss',
    643648                         items              => 10,
    644649                         ignore_minor_edits => 1,
     
    646651                     );
    647652
    648   # All edits bob has made to pub pages in the last week.
    649   $guide->display_rss(
    650                          days     => 7,
    651                          username => "bob",
    652                          category => "Pubs",
     653  # All edits bob has made to pub pages in the last week in Atom format
     654  $guide->display_feed(
     655                         feed_type => 'atom',
     656                         days      => 7,
     657                         username  => "bob",
     658                         category  => "Pubs",
    653659                     );
     660
     661C<feed_type> is a mandatory parameter. Supported values at present are
     662"rss" and "atom".
    654663
    655664As with other methods, the C<return_output> parameter can be used to
     
    658667=cut
    659668
    660 sub display_rss {
     669sub display_feed {
    661670    my ($self, %args) = @_;
    662671
     672    my $feed_type = $args{feed_type};
     673    croak "No feed type given" unless $feed_type;
     674   
    663675    my $return_output = $args{return_output} ? 1 : 0;
    664676
     
    673685                       days               => $days,
    674686                       ignore_minor_edits => $ignore_minor_edits,
     687                       feed_type          => $feed_type,
    675688                   );
    676689    my %filter;
     
    682695    }
    683696
    684     my $rdf_writer = OpenGuides::RDF->new(
    685                                              wiki       => $self->wiki,
    686                                              config     => $self->config,
    687                                              og_version => $VERSION,
    688                                          );
    689     my $output = "Content-Type: application/rdf+xml\n";
    690     $output .= "Last-Modified: " . $rdf_writer->rss_timestamp( %criteria ) . "\n\n";
    691     $output .= $rdf_writer->make_recentchanges_rss( %criteria );
     697    my $feed = OpenGuides::Feed->new(
     698                                        wiki       => $self->wiki,
     699                                        config     => $self->config,
     700                                        og_version => $VERSION,
     701                                    );
     702
     703    my $output;
     704   
     705    if ($feed_type eq 'rss') {
     706        $output = "Content-Type: application/rdf+xml\n";
     707    }
     708    elsif ($feed_type eq 'atom') {
     709        $output = "Content-Type: application/atom+xml\n";
     710    }
     711    else {
     712        croak "Unknown feed type given: $feed_type";
     713    }
     714   
     715    $output .= "Last-Modified: " . $feed->feed_timestamp( %criteria ) . "\n\n";
     716
     717    $output .= $feed->make_feed( %criteria );
     718
    692719    return $output if $return_output;
    693720    print $output;
  • trunk/lib/OpenGuides/RDF.pm

    r741 r753  
    44
    55use vars qw( $VERSION );
    6 $VERSION = '0.08';
     6$VERSION = '0.09';
    77
    88use CGI::Wiki::Plugin::RSS::ModWiki;
     
    200200}
    201201
    202 sub rss_maker {
    203     my $self = shift;
    204 
    205     # OAOO, please.
    206     unless ($self->{rss_maker}) {
    207         $self->{rss_maker} = CGI::Wiki::Plugin::RSS::ModWiki->new(
    208           wiki                => $self->{wiki},
    209           site_name           => $self->{site_name},
    210           site_url            => $self->{config}->script_url,
    211           site_description    => $self->{site_description},
    212           make_node_url       => $self->{make_node_url},
    213           recent_changes_link => $self->{config}->script_url . '?action=rc',
    214           software_name       => 'OpenGuides',
    215           software_homepage   => 'http://openguides.org/',
    216           software_version    => $self->{og_version},
    217         );
    218     }
    219    
    220     $self->{rss_maker};
    221 }
    222 
    223 sub make_recentchanges_rss {
    224     my ($self, %args) = @_;
    225 
    226     $self->rss_maker->recent_changes(%args);
    227 }
    228 
    229 sub rss_timestamp {
    230     my ($self, %args) = @_;
    231    
    232     $self->rss_maker->rss_timestamp(%args);
    233 }
    234 
    235202=head1 NAME
    236203
     
    258225    print "Content-Type: application/rdf+xml\n\n";
    259226    print $rdf_writer->emit_rdfxml( node => "Masala Zone, N1 0NU" );
    260 
    261     # Ten most recent changes.
    262     print "Content-Type: application/rdf+xml\n";
    263     print "Last-Modified: " . $self->rss_timestamp( items => 10 ) . "\n\n";
    264     print $rdf_writer->make_recentchanges_rss( items => 10 );
    265227
    266228=head1 METHODS
     
    315277=back
    316278
    317 =item B<rss_maker>
    318 
    319 Returns a raw L<CGI::Wiki::Plugin::RSS::ModWiki> object created with the values you
    320 invoked this module with.
    321 
    322 =item B<make_recentchanges_rss>
    323 
    324     # Ten most recent changes.
    325     print "Content-Type: application/rdf+xml\n";
    326     print "Last-Modified: " . $rdf_writer->rss_timestamp( items => 10 ) . "\n\n";
    327     print $rdf_writer->make_recentchanges_rss( items => 10 );
    328 
    329     # All the changes made by bob in the past week, ignoring minor edits.
    330 
    331     my %args = (
    332                  days               => 7,
    333                  ignore_minor_edits => 1,
    334                  filter_on_metadata => { username => "bob" },
    335                );
    336 
    337     print "Content-Type: application/rdf+xml\n";
    338     print "Last-Modified: " . $rdf_writer->rss_timestamp( %args ) . "\n\n";
    339     print $rdf_writer->make_recentchanges_rss( %args );
    340 
    341 =item B<rss_timestamp>
    342 
    343     print "Last-Modified: " . $rdf_writer->rss_timestamp( %args ) . "\n\n";
    344 
    345 Returns the timestamp of the RSS feed in POSIX::strftime style ("Tue, 29 Feb 2000
    346 12:34:56 GMT"), which is equivalent to the timestamp of the most recent item
    347 in the feed. Takes the same arguments as make_recentchanges_rss(). You will most
    348 likely need this to print a Last-Modified HTTP header so user-agents can determine
    349 whether they need to reload the feed or not.
     279=head1 SEE ALSO
     280
     281=over 4
     282
     283=item * L<CGI::Wiki>
     284
     285=item * L<http://openguides.org/>
     286
     287=item * L<http://chefmoz.org/>
    350288
    351289=back
    352290
    353 =head1 SEE ALSO
    354 
    355 =over 4
    356 
    357 =item * L<CGI::Wiki>
    358 
    359 =item * L<http://openguides.org/>
    360 
    361 =item * L<http://chefmoz.org/>
    362 
    363 =back
    364 
    365291=head1 AUTHOR
    366292
     
    369295=head1 COPYRIGHT
    370296
    371 Copyright (C) 2003-2005 The OpenGuides Project.  All Rights Reserved.
     297Copyright (C) 2003-2006 The OpenGuides Project.  All Rights Reserved.
    372298
    373299This module is free software; you can redistribute it and/or modify it
  • trunk/t/22_rss_modwiki.t

    r587 r753  
    4343my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
    4444
    45 my $rdf_writer = OpenGuides::RDF->new( wiki   => $wiki,
    46                                        config => $config );
     45my $feed = OpenGuides::Feed->new( wiki   => $wiki,
     46                                  config => $config );
    4747
    48 my $rss = eval { $rdf_writer->make_recentchanges_rss; };
    49 is( $@, "", "->make_recentchanges_rss doesn't croak" );
     48my $rss = eval { $feed->make_feed(feed_type => 'rss'); };
     49is( $@, "", "->make_feed for rss doesn't croak" );
    5050
    5151# Now write some data, first a minor edit then a non-minor one.
     
    9898
    9999# Check that the minor edits can be filtered out.
    100 $output = $guide->display_rss(
     100$output = $guide->display_feed(
     101                               feed_type          => "rss",
    101102                               items              => 5,
    102103                               username           => "bob",
  • trunk/wiki.cgi

    r748 r753  
    55
    66use vars qw( $VERSION );
    7 $VERSION = '0.52';
     7$VERSION = '0.53';
    88
    99use CGI qw/:standard/;
     
    104104                           qw( feed items days ignore_minor_edits username
    105105                               category locale );
    106                 $guide->display_rss( %args );
     106                $args{feed_type} = 'rss';
     107                $guide->display_feed( %args );
    107108            } elsif ( $feed eq "chef_dan" ) {
    108109                display_node_rdf( node => $node );
     
    110111                croak "Unknown RSS feed type '$feed'";
    111112            }
     113        } elsif ($format && $format eq 'atom') {
     114            my %args = map { $_ => ( $q->param($_) || "" ) }
     115                       qw( feed items days ignore_minor_edits username
     116                           category locale );
     117            $args{feed_type} = 'atom';
     118            $guide->display_feed( %args );
    112119        } else {
    113120            $guide->display_node( id => 'RecentChanges' );
Note: See TracChangeset for help on using the changeset viewer.