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'});
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,
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;
}
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
}
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
}
}
if (!defined $sqlbit) {
+ return undef if $is_optional;
$r->error_exit("Unable to identify target CommitFest.");
}
},
'link' => [],
'response_sent' => 0,
+ 'rss_alternate' => undef,
'title' => '',
}, $class;
}
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;
$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'},
$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);