diff options
author | Robert Haas | 2009-08-01 04:39:48 +0000 |
---|---|---|
committer | Robert Haas | 2009-08-01 04:39:48 +0000 |
commit | effaa1f609c33737430966dc0cac20020f9d2b71 (patch) | |
tree | b74650c97e74d88738e1217c844e6b341db77f30 | |
parent | fe5d9e3ed729b793d8508f6d7cf8990920e1fbdd (diff) |
Code cleanup and other adjustments to RSS feed code.
-rw-r--r-- | perl-lib/PgCommitFest/CommitFest.pm | 60 | ||||
-rw-r--r-- | perl-lib/PgCommitFest/Handler.pm | 2 | ||||
-rw-r--r-- | perl-lib/PgCommitFest/Request.pm | 15 | ||||
-rw-r--r-- | template/commitfest_activity_rss.tt2 | 4 | ||||
-rw-r--r-- | template/header.tt2 | 4 |
5 files changed, 58 insertions, 27 deletions
diff --git a/perl-lib/PgCommitFest/CommitFest.pm b/perl-lib/PgCommitFest/CommitFest.pm index 7e67f97..db6e4ed 100644 --- a/perl-lib/PgCommitFest/CommitFest.pm +++ b/perl-lib/PgCommitFest/CommitFest.pm @@ -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."); } diff --git a/perl-lib/PgCommitFest/Handler.pm b/perl-lib/PgCommitFest/Handler.pm index 57dc859..c27ae10 100644 --- a/perl-lib/PgCommitFest/Handler.pm +++ b/perl-lib/PgCommitFest/Handler.pm @@ -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, diff --git a/perl-lib/PgCommitFest/Request.pm b/perl-lib/PgCommitFest/Request.pm index de6d32f..a12ab4a 100644 --- a/perl-lib/PgCommitFest/Request.pm +++ b/perl-lib/PgCommitFest/Request.pm @@ -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 index 0000000..8187c23 --- /dev/null +++ b/template/commitfest_activity_rss.tt2 @@ -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> diff --git a/template/header.tt2 b/template/header.tt2 index f9648ec..2ab304b 100644 --- a/template/header.tt2 +++ b/template/header.tt2 @@ -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("/https/git.postgresql.org/layout/css/blue/commitfest.css");</style> <script type="text/javascript" src="/https/git.postgresql.org/layout/js/geckostyle.js"></script> - <link rel="alternate" type="application/rss+xml" title="Commitfest changes" href="/https/git.postgresql.org/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> |