Author: earle Date: 2005-10-23 20:00:10 +0100 (Sun, 23 Oct 2005) New Revision: 700
Modified: trunk/lib/OpenGuides.pm trunk/templates/header.tt trunk/templates/home_node.tt trunk/templates/userstats.tt trunk/wiki.cgi Log: Change "action=rss" parameter to "action=rc;format=rss". Extract RecentChanges code in OpenGuides.pm to its own sub (display_recent_changes()). Fix references to old params in templates. Put redirect to URL with new parameters into wiki.cgi for old parameter.
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2005-10-23 17:14:20 UTC (rev 699) +++ trunk/lib/OpenGuides.pm 2005-10-23 19:00:10 UTC (rev 700) @@ -153,7 +153,7 @@ $tt_vars{index_type} = lc($type); $tt_vars{index_value} = $2; $tt_vars{"rss_".lc($type)."_url"} = - $config->script_name . "?action=rss;" + $config->script_name . "?action=rc;format=rss;" . lc($type) . "=" . lc(CGI->escape($2)); }
@@ -223,77 +223,7 @@ $tt_vars{current} = 1 unless $version;
if ($id eq "RecentChanges") { - my $minor_edits = $self->get_cookie( "show_minor_edits_in_rc" ); - my %recent_changes; - my $q = CGI->new; - my $since = $q->param("since"); - if ( $since ) { - $tt_vars{since} = $since; - my $t = localtime($since); # overloaded by Time::Piece - $tt_vars{since_string} = $t->strftime; - my %criteria = ( since => $since ); - $criteria{metadata_was} = { edit_type => "Normal edit" } - unless $minor_edits; - my @rc = $self->{wiki}->list_recent_changes( %criteria ); - - @rc = map { - { - name => CGI->escapeHTML($_->{name}), - last_modified => CGI->escapeHTML($_->{last_modified}), - version => CGI->escapeHTML($_->{version}), - comment => CGI->escapeHTML($_->{metadata}{comment}[0]), - username => CGI->escapeHTML($_->{metadata}{username}[0]), - host => CGI->escapeHTML($_->{metadata}{host}[0]), - username_param => CGI->escape($_->{metadata}{username}[0]), - edit_type => CGI->escapeHTML($_->{metadata}{edit_type}[0]), - url => $config->script_name . "?" - . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), - } - } @rc; - if ( scalar @rc ) { - $recent_changes{since} = @rc; - } - } else { - for my $days ( [0, 1], [1, 7], [7, 14], [14, 30] ) { - my %criteria = ( between_days => $days ); - $criteria{metadata_was} = { edit_type => "Normal edit" } - unless $minor_edits; - my @rc = $self->{wiki}->list_recent_changes( %criteria ); - - @rc = map { - { - name => CGI->escapeHTML($_->{name}), - last_modified => CGI->escapeHTML($_->{last_modified}), - version => CGI->escapeHTML($_->{version}), - comment => CGI->escapeHTML($_->{metadata}{comment}[0]), - username => CGI->escapeHTML($_->{metadata}{username}[0]), - host => CGI->escapeHTML($_->{metadata}{host}[0]), - username_param => CGI->escape($_->{metadata}{username}[0]), - edit_type => CGI->escapeHTML($_->{metadata}{edit_type}[0]), - url => $config->script_name . "?" - . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), - } - } @rc; - if ( scalar @rc ) { - $recent_changes{$days->[1]} = @rc; - } - } - } - $tt_vars{recent_changes} = %recent_changes; - my %processing_args = ( - id => $id, - template => "recent_changes.tt", - tt_vars => %tt_vars, - ); - if ( !$since && $self->get_cookie("track_recent_changes_views") ) { - my $cookie = OpenGuides::CGI->make_recent_changes_cookie(config => $config ); - $processing_args{cookies} = $cookie; - $tt_vars{last_viewed} = OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); - } - return %tt_vars if $args{return_tt_vars}; - my $output = $self->process_template( %processing_args ); - return $output if $return_output; - print $output; + $self->display_recent_changes(%args); } elsif ( $id eq $self->config->home_name ) { my @recent = $wiki->list_recent_changes( last_n_changes => 10, @@ -331,6 +261,95 @@ } }
+=item B<display_recent_changes> + + $guide->display_recent_changes; + +As with other methods, the C<return_output> parameter can be used to +return the output instead of printing it to STDOUT. + +=cut + +sub display_recent_changes { + my ($self, %args) = @_; + my $config = $self->config; + my $wiki = $self->wiki; + my $minor_edits = $self->get_cookie( "show_minor_edits_in_rc" ); + my $id = $args{id} || $self->config->home_name; + my $return_output = $args{return_output} || 0; + my (%tt_vars, %recent_changes); + my $q = CGI->new; + my $since = $q->param("since"); + if ( $since ) { + $tt_vars{since} = $since; + my $t = localtime($since); # overloaded by Time::Piece + $tt_vars{since_string} = $t->strftime; + my %criteria = ( since => $since ); + $criteria{metadata_was} = { edit_type => "Normal edit" } + unless $minor_edits; + my @rc = $self->{wiki}->list_recent_changes( %criteria ); + + @rc = map { + { + name => CGI->escapeHTML($_->{name}), + last_modified => CGI->escapeHTML($_->{last_modified}), + version => CGI->escapeHTML($_->{version}), + comment => CGI->escapeHTML($_->{metadata}{comment}[0]), + username => CGI->escapeHTML($_->{metadata}{username}[0]), + host => CGI->escapeHTML($_->{metadata}{host}[0]), + username_param => CGI->escape($_->{metadata}{username}[0]), + edit_type => CGI->escapeHTML($_->{metadata}{edit_type}[0]), + url => $config->script_name . "?" + . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), + } + } @rc; + if ( scalar @rc ) { + $recent_changes{since} = @rc; + } + } else { + for my $days ( [0, 1], [1, 7], [7, 14], [14, 30] ) { + my %criteria = ( between_days => $days ); + $criteria{metadata_was} = { edit_type => "Normal edit" } + unless $minor_edits; + my @rc = $self->{wiki}->list_recent_changes( %criteria ); + + @rc = map { + { + name => CGI->escapeHTML($_->{name}), + last_modified => CGI->escapeHTML($_->{last_modified}), + version => CGI->escapeHTML($_->{version}), + comment => CGI->escapeHTML($_->{metadata}{comment}[0]), + username => CGI->escapeHTML($_->{metadata}{username}[0]), + host => CGI->escapeHTML($_->{metadata}{host}[0]), + username_param => CGI->escape($_->{metadata}{username}[0]), + edit_type => CGI->escapeHTML($_->{metadata}{edit_type}[0]), + url => $config->script_name . "?" + . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), + } + } @rc; + if ( scalar @rc ) { + $recent_changes{$days->[1]} = @rc; + } + } + } + $tt_vars{recent_changes} = %recent_changes; + my %processing_args = ( + id => $id, + template => "recent_changes.tt", + tt_vars => %tt_vars, + ); + if ( !$since && $self->get_cookie("track_recent_changes_views") ) { + my $cookie = + OpenGuides::CGI->make_recent_changes_cookie(config => $config ); + $processing_args{cookies} = $cookie; + $tt_vars{last_viewed} = OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); + } + return %tt_vars if $args{return_tt_vars}; + my $output = $self->process_template( %processing_args ); + return $output if $return_output; + print $output; +} + =item B<display_diffs>
$guide->display_diffs(
Modified: trunk/templates/header.tt =================================================================== --- trunk/templates/header.tt 2005-10-23 17:14:20 UTC (rev 699) +++ trunk/templates/header.tt 2005-10-23 19:00:10 UTC (rev 700) @@ -25,11 +25,8 @@ <meta name="DC.title" content="[% site_name %]" /> [% END %] [% IF (node_name == 'RecentChanges') %] - <link rel="alternate" type="application/rss+xml" title="RSS feed for this page" href="[% full_cgi_url %]?action=rss" /> + <link rel="alternate" type="application/rss+xml" title="RSS feed for this page" href="[% full_cgi_url %]?action=rc;format=rss" /> [% END %] - [% IF rss_link %] - <link rel="alternate" type="application/rss+xml" title="RSS feed for this page" href="[% rss_link %]" /> - [% END %] [% IF deter_robots %] <meta name="robots" content="noindex,nofollow" /> [% END %]
Modified: trunk/templates/home_node.tt =================================================================== --- trunk/templates/home_node.tt 2005-10-23 17:14:20 UTC (rev 699) +++ trunk/templates/home_node.tt 2005-10-23 19:00:10 UTC (rev 700) @@ -30,7 +30,7 @@ <div id="recent">
<h3>Ten most <a href="[% cgi_url %]?RecentChanges">recent changes</a> - (<a href="[% full_cgi_url %]?action=rss">RSS</a>):</h3> + (<a href="[% full_cgi_url %]?action=rc;format=rss">RSS</a>):</h3>
<dl> [% FOREACH node = recent_changes %]
Modified: trunk/templates/userstats.tt =================================================================== --- trunk/templates/userstats.tt 2005-10-23 17:14:20 UTC (rev 699) +++ trunk/templates/userstats.tt 2005-10-23 19:00:10 UTC (rev 700) @@ -38,10 +38,10 @@ [% IF username %] <h2>Personalised RSS feeds:</h2> <ul> - <li><a href="[% full_cgi_url %]?action=rss;username=[% CGI.escape(username) %];items=10">Last ten edits made by [% username %]</a></li> - <li><a href="[% full_cgi_url %]?action=rss;username=[% CGI.escape(username) %];items=20">Last twenty edits made by [% username %]</a></li> - <li><a href="[% full_cgi_url %]?action=rss;username=[% CGI.escape(username) %];items=10;ignore_minor_edits=1">Last ten edits made by [% username %], ignoring minor edits</a></li> - <li><a href="[% full_cgi_url %]?action=rss;username=[% CGI.escape(username) %];items=20;ignore_minor_edits=1">Last twenty edits made by [% username %], ignoring minor edits</a></li> + <li><a href="[% full_cgi_url %]?action=rc;format=rss;username=[% CGI.escape(username) %];items=10">Last ten edits made by [% username %]</a></li> + <li><a href="[% full_cgi_url %]?action=rc;format=rss;username=[% CGI.escape(username) %];items=20">Last twenty edits made by [% username %]</a></li> + <li><a href="[% full_cgi_url %]?action=rc;format=rss;username=[% CGI.escape(username) %];items=10;ignore_minor_edits=1">Last ten edits made by [% username %], ignoring minor edits</a></li> + <li><a href="[% full_cgi_url %]?action=rc;format=rss;username=[% CGI.escape(username) %];items=20;ignore_minor_edits=1">Last twenty edits made by [% username %], ignoring minor edits</a></li> </ul> [% END %]
Modified: trunk/wiki.cgi =================================================================== --- trunk/wiki.cgi 2005-10-23 17:14:20 UTC (rev 699) +++ trunk/wiki.cgi 2005-10-23 19:00:10 UTC (rev 700) @@ -1,10 +1,11 @@ #!/usr/local/bin/perl
use strict; +use lib qw( /home/earle/openguides.org/testing/lib ); use warnings;
use vars qw( $VERSION ); -$VERSION = '0.50'; +$VERSION = '0.51';
use CGI qw/:standard/; use CGI::Carp qw(croak); @@ -97,18 +98,24 @@ ); } elsif ($action eq 'list_all_versions') { $guide->list_all_versions( id => $node ); - } elsif ($action eq 'rss') { - my $feed = $q->param("feed"); - if ( !defined $feed or $feed eq "recent_changes" ) { - my %args = map { $_ => ( $q->param($_) || "" ) } - qw( feed items days ignore_minor_edits username - category locale ); - $guide->display_rss( %args ); - } elsif ( $feed eq "chef_dan" ) { - display_node_rdf( node => $node ); + } elsif ($action eq 'rc') { + if ($format && $format eq 'rss') { + my $feed = $q->param("feed"); + if ( !defined $feed or $feed eq "recent_changes" ) { + my %args = map { $_ => ( $q->param($_) || "" ) } + qw( feed items days ignore_minor_edits username + category locale ); + $guide->display_rss( %args ); + } elsif ( $feed eq "chef_dan" ) { + display_node_rdf( node => $node ); + } else { + croak "Unknown RSS feed type '$feed'"; + } } else { - croak "Unknown RSS feed type '$feed'"; + $guide->display_node( id => 'RecentChanges' ); } + } elsif ($action eq 'rss') { + print $q->redirect( $script_url . '?action=rc;format=rss' ); } else { # Default is to display a node. if ( $format and $format eq "rdf" ) { display_node_rdf( node => $node ); @@ -119,7 +126,7 @@ ); } else { my $version = $q->param("version"); - my $other_ver = $q->param("diffversion"); + my $other_ver = $q->param("diffversion"); if ( $other_ver ) { $guide->display_diffs( id => $node,
openguides-commits@lists.openguides.org