Code cleanup and other adjustments to RSS feed code.
authorRobert Haas <[email protected]>
Sat, 1 Aug 2009 04:39:48 +0000 (00:39 -0400)
committerRobert Haas <[email protected]>
Sat, 1 Aug 2009 04:39:48 +0000 (00:39 -0400)
perl-lib/PgCommitFest/CommitFest.pm
perl-lib/PgCommitFest/Handler.pm
perl-lib/PgCommitFest/Request.pm
template/commitfest_activity_rss.tt2 [new file with mode: 0644]
template/header.tt2

index 7e67f970b9080c1b212fc5d2da70d17764168edb..db6e4ed04e6df4cc2f12ad5d9973d944bafa9d46 100644 (file)
@@ -6,7 +6,11 @@ use XML::RSS;
 sub activity {
        my ($r, $extrapath) = @_;
        my $d = setup($r, $extrapath);
-       $r->set_title('CommitFest %s: Activity Log', $d->{'name'});
+       my $title = sprintf 'CommitFest %s: Activity Log', $d->{'name'};
+       my $rss = '/action/commitfest_activity.rss?id=' . $d->{'id'};
+       $r->set_title($title);
+       $r->set_rss_alternate($title, $rss);
+       $r->add_link($rss, 'RSS');
        $r->add_link('/action/commitfest_view?id=' . $d->{'id'},
                'Back to CommitFest');
        my $activity = $r->db->select(<<EOM, $d->{'id'});
@@ -26,14 +30,14 @@ EOM
 
 sub activity_rss {
        my ($r, $extrapath) = @_;
-       my $where = ''; # By default, show all commitfests
-       my @l = ();
+       my $d = setup($r, $extrapath, 1);
 
-       if (defined($extrapath)) {
-               $l[0] = setup($r, $extrapath)->{'id'};
-               $where = 'WHERE v.commitfest_id = ?';
+       # Fetch most recent 50 updates for relevant CommitFest, or all CommitFests.
+       my $sqlbit = '';
+       if (defined $d) {
+               $sqlbit = "WHERE v.commitfest_id = " . $d->{'id'};
        }
-       my $activity = $r->db->select(<<EOM, @l);
+       my $activity = $r->db->select(<<EOM);
 SELECT
        to_char(v.last_updated_time, 'YYYY-MM-DD HH24:MI:SS') AS last_updated_time,
        v.last_updater, v.patch_name, v.patch_id, v.activity_type, v.details,
@@ -42,30 +46,34 @@ FROM
        commitfest_activity_log v
 INNER JOIN
        commitfest ON v.commitfest_id=commitfest.id
-$where
+$sqlbit
 ORDER BY
        v.last_updated_time DESC LIMIT 50
 EOM
 
-       my $rss = new XML::RSS(version=>'2.0');
-       $rss->channel(  title           => 'PostgreSQL commitfest updates',
-                       link            => 'http://commitfest.postgresql.org',
-                       language        => 'en',
-                       description     => 'PostgreSQL commitfest updates'
-                       );
+       # Construct RSS channel.
+       my $rssname = defined $d ?
+               sprintf('PostgreSQL CommitFest %s: Activity Log', $d->{'name'})
+                       : 'PostgreSQL CommitFest Activity Log';
+       my $rss = XML::RSS->new('version' => '2.0');
+       $rss->channel(
+               'title'                 => $rssname,
+               'link'                  => 'http://commitfest.postgresql.org',
+               'language'              => 'en',
+               'description'   => $rssname,
+       );
        foreach my $row (@$activity) {
-               $rss->add_item(guid     => 'http://commitfest.postgresql.org/activity/' .
+               my $content;
+               $rss->add_item(
+                       'guid'  => 'http://commitfest.postgresql.org/activity/' .
                                        $row->{'patch_id'} . '/' . $row->{'last_updated_time'},
-                               title   => $row->{'commitfest_name'} . ': ' . $row->{'patch_name'},
-                               description => 'Commitfest: ' . $row->{'commitfest_name'} .
-                                       '<br/>Patch: <a href="http://commitfest.postgresql.org/action/patch_view?id=' .
-                                       $row->{'patch_id'} . '">' . $row->{'patch_name'} . '</a><br/>Change by: ' .
-                                       $row->{'last_updater'} . '<br/>Change: ' . $row->{'activity_type'} . ': ' .
-                                       $row->{'details'}
-                               );
+                       'title' => $row->{'commitfest_name'} . ': ' . $row->{'patch_name'},
+                       'description' => $r->eval_template('commitfest_activity_rss',
+                               { 'd' => $row })
+               );
        }
-       print "Content-type: application/xml+rss\n\n";
 
+       print "Content-type: application/xml+rss\n\n";
        print $rss->as_string;
        $r->{'response_sent'} = 1;
 }
@@ -144,9 +152,12 @@ sub search {
        my ($r) = @_;
        my $aa = $r->authenticate();
        $r->set_title('CommitFest Index');
+       $r->set_rss_alternate('PostgreSQL CommitFest Activity Log',
+               '/action/commitfest_activity.rss');
        if (defined $aa && $aa->{'is_administrator'}) {
                $r->add_link('/action/commitfest_form', 'New CommitFest');
        }
+       $r->add_link('/action/commitfest_activity.rss', 'RSS');
        my $list = $r->db->select(<<EOM);
 SELECT id, name, commitfest_status FROM commitfest_view ORDER BY name DESC
 EOM
@@ -154,7 +165,7 @@ EOM
 }
 
 sub setup {
-       my ($r, $extrapath) = @_;
+       my ($r, $extrapath, $is_optional) = @_;
 
        # Target commitfest can be specified either by ID, or we allow special
        # magic to fetch it by 
@@ -180,6 +191,7 @@ EOM
                }
        }
        if (!defined $sqlbit) {
+               return undef if $is_optional;
                $r->error_exit("Unable to identify target CommitFest.");
        }
 
index 57dc859931169b2e94cbece6ab71e81ac12c9822..c27ae1064a1c3c04f1afa3bd7ae143b814a442f5 100644 (file)
@@ -13,7 +13,7 @@ our %ACTION = (
        'login'                                     => \&PgCommitFest::Handler::login,
        'logout'                                    => \&PgCommitFest::Handler::logout,
        'commitfest_activity'           => \&PgCommitFest::CommitFest::activity,
-       'commitfest_activity.rss'               => \&PgCommitFest::CommitFest::activity_rss,
+       'commitfest_activity.rss'       => \&PgCommitFest::CommitFest::activity_rss,
        'commitfest_delete'                     => \&PgCommitFest::CommitFest::delete,
        'commitfest_form'                       => \&PgCommitFest::CommitFest::form,
        'commitfest_search'                 => \&PgCommitFest::CommitFest::search,
index de6d32febe4800808296ada09f20ed2049bcf8e6..a12ab4a633c5ab78a752de45cacdd632485e4d62 100644 (file)
@@ -36,6 +36,7 @@ sub new {
                },
                'link' => [],
                'response_sent' => 0,
+               'rss_alternate' => undef,
                'title' => '',
        }, $class;
 }
@@ -140,6 +141,14 @@ sub error_exit {
        die "DONE\n";
 }
 
+sub eval_template {
+       my ($self, $name, $stash) = @_;
+       my $content;
+       $template->process($name . '.tt2', $stash, \$content)
+               || die $template->error();
+       return $content;
+}
+
 sub generate_headers {
        my ($self) = @_;
        my @header;
@@ -196,6 +205,7 @@ sub render_template {
        $template->process('header.tt2', {
                'authenticate' => $self->authenticate(),
                'link' => $self->{'link'},
+               'rss_alternate' => $self->{'rss_alternate'},
                'title' => $self->{'title'},
                'error_list' => $self->{'error_list'},
                'script_name' => $ENV{'SCRIPT_NAME'},
@@ -216,6 +226,11 @@ sub response_sent {
        $self->{'response_sent'};
 }
 
+sub set_rss_alternate {
+       my ($self, $name, $url) = @_;
+       $self->{'rss_alternate'} = { 'name' => $name, 'url' => $url };
+}
+
 sub set_title {
        my ($self, $fmt, @args) = @_;
        $self->{'title'} = sprintf($fmt, @args);
diff --git a/template/commitfest_activity_rss.tt2 b/template/commitfest_activity_rss.tt2
new file mode 100644 (file)
index 0000000..8187c23
--- /dev/null
@@ -0,0 +1,4 @@
+<div>Commitfest: [% d.commitfest_name | htmlsafe %]</div>
+<div>Patch: <a href='http://commitfest.postgresql.org/action/patch_view?id=[% d.patch_id %]'>[% d.patch_name | htmlsafe %]</a></div>
+<div>User: [% d.last_updater | htmlsafe %]</div>
+<div>[% d.activity_type | htmlsafe %]: [% d.details | htmlsafe %]</div>
index f9648ecc028f8ec4c349ae246975e5cc7f56ab72..2ab304bab4a11cae82f37a13ef30134d5800d573 100644 (file)
@@ -5,8 +5,8 @@
   <title>PostgreSQL CommitFest Management[% IF title != '' %]: [% title | htmlsafe %][% END %]</title>
     <style type="text/css" media="screen" title="Normal Text">@import url("/layout/css/blue/commitfest.css");</style>
     <script type="text/javascript" src="/layout/js/geckostyle.js"></script>
-    <link rel="alternate" type="application/rss+xml" title="Commitfest changes" href="/action/commitfest_activity.rss" />
-</head>
+[% IF rss_alternate %]    <link rel="alternate" type="application/rss+xml" title="[% rss_alternate.name | htmlsafe %]" href="[% rss_alternate.url | html %]" />
+[% END %]</head>
 <body>
 <table id="commitfestHeader">
   <tr>