/usr/share/perl5/Wiki/Toolkit/Feed/Listing.pm is in libwiki-toolkit-perl 0.83-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | package Wiki::Toolkit::Feed::Listing;
use strict;
use Carp qw( croak );
=head1 NAME
Wiki::Toolkit::Feed::Listing - parent class for Feeds from Wiki::Toolkit.
=head1 DESCRIPTION
Handles common data fetching tasks, so that child classes need only
worry about formatting the feeds.
Also enforces some common methods that must be implemented.
=head1 METHODS
=head2 C<fetch_recently_changed_nodes>
Based on the supplied criteria, fetch a list of the recently changed nodes
=cut
sub fetch_recently_changed_nodes {
my ($self, %args) = @_;
my $wiki = $self->{wiki};
my %criteria = (
ignore_case => 1,
);
# If we're not passed any parameters to limit the items returned,
# default to 15.
$args{days} ? $criteria{days} = $args{days}
: $criteria{last_n_changes} = $args{items} || 15;
my %was_filter;
if ( $args{filter_on_metadata} ) {
%was_filter = %{ $args{filter_on_metadata} };
}
if ( $args{ignore_minor_edits} ) {
%was_filter = ( %was_filter, major_change => 1 );
}
$criteria{metadata_was} = \%was_filter;
my @changes = $wiki->list_recent_changes(%criteria);
return @changes;
}
=head2 C<fetch_newest_for_recently_changed>
Based on the supplied criteria (but not using all of those used by
B<fetch_recently_changed_nodes>), find the newest node from the recently
changed nodes set. Normally used for dating the whole of a Feed.
=cut
sub fetch_newest_for_recently_changed {
my ($self, %args) = @_;
my @changes = $self->fetch_recently_changed_nodes( %args );
return $changes[0];
}
=head2 C<fetch_node_all_versions>
For a given node (name or ID), return all the versions there have been,
including all metadata required for it to go into a "recent changes"
style listing.
=cut
sub fetch_node_all_versions {
my ($self, %args) = @_;
# Check we got the right options
unless($args{'name'}) {
return ();
}
# Do the fetch
my @nodes = $self->{wiki}->list_node_all_versions(
name => $args{'name'},
with_content => 0,
with_metadata => 1,
);
# Ensure that all the metadata fields are arrays and not strings
foreach my $node (@nodes) {
foreach my $mdk (keys %{$node->{'metadata'}}) {
unless(ref($node->{'metadata'}->{$mdk}) eq "ARRAY") {
$node->{'metadata'}->{$mdk} = [ $node->{'metadata'}->{$mdk} ];
}
}
}
return @nodes;
}
=head2 C<recent_changes>
Build an Atom Feed of the recent changes to the Wiki::Toolkit instance,
using any supplied parameters to narrow the results.
If the argument "also_return_timestamp" is supplied, it will return an
array of the feed, and the feed timestamp. Otherwise it just returns the feed.
=cut
sub recent_changes {
my ($self, %args) = @_;
my @changes = $self->fetch_recently_changed_nodes(%args);
my $feed_timestamp = $self->feed_timestamp(
$self->fetch_newest_for_recently_changed(%args)
);
my $feed = $self->generate_node_list_feed($feed_timestamp, @changes);
if ($args{'also_return_timestamp'}) {
return ($feed,$feed_timestamp);
} else {
return $feed;
}
}
=head2 C<node_all_versions>
Build an Atom Feed of all the different versions of a given node.
If the argument "also_return_timestamp" is supplied, it will return an
array of the feed, and the feed timestamp. Otherwise it just returns the feed.
=cut
sub node_all_versions {
my ($self, %args) = @_;
my @all_versions = $self->fetch_node_all_versions(%args);
my $feed_timestamp = $self->feed_timestamp( $all_versions[0] );
my $feed = $self->generate_node_list_feed($feed_timestamp, @all_versions);
if($args{'also_return_timestamp'}) {
return ($feed,$feed_timestamp);
} else {
return $feed;
}
}
=head2 C<format_geo>
Using the geo and space xml namespaces, format the supplied node metadata
into geo: and space: tags, suitable for inclusion in a feed with those
namespaces imported.
=cut
sub format_geo {
my ($self, @args) = @_;
my %metadata;
if(ref($args[0]) eq "HASH") {
%metadata = %{$_[1]};
} else {
%metadata = @args;
}
my %mapping = (
"os_x" => "space:os_x",
"os_y" => "space:os_y",
"latitude" => "geo:lat",
"longitude" => "geo:long",
"distance" => "space:distance",
);
my $feed = "";
foreach my $geo (keys %metadata) {
my $geo_val = $metadata{$geo};
if(ref($geo_val) eq "ARRAY") {
$geo_val = $geo_val->[0];
}
if($mapping{$geo}) {
my $tag = $mapping{$geo};
$feed .= " <$tag>$geo_val</$tag>\n";
}
}
return $feed;
}
# Utility method, to help with argument passing where one of a list of
# arguments must be supplied
sub handle_supply_one_of {
my ($self,$mref,$aref) = @_;
my %mustoneof = %{$mref};
my %args = %{$aref};
foreach my $oneof (keys %mustoneof) {
my $val = undef;
foreach my $poss (@{$mustoneof{$oneof}}) {
unless($val) {
if($args{$poss}) { $val = $args{$poss}; }
}
}
if($val) {
$self->{$oneof} = $val;
} else {
croak "No $oneof supplied, or one of its equivalents (".join(",", @{$mustoneof{$oneof}}).")";
}
}
}
=pod
The following are methods that any feed renderer must provide:
=head2 C<feed_timestamp>
All implementing feed renderers must implement a method to produce a
feed specific timestamp, based on the supplied node
=cut
sub feed_timestamp { die("Not implemented by feed renderer!"); }
=head2 C<generate_node_list_feed>
All implementing feed renderers must implement a method to produce a
feed from the supplied list of nodes
=cut
sub generate_node_list_feed { die("Not implemented by feed renderer!"); }
=head2 C<generate_node_name_distance_feed>
All implementing feed renderers must implement a method to produce a
stripped down feed from the supplied list of node names, and optionally
locations and distance from a reference point.
=cut
sub generate_node_name_distance_feed { die("Not implemented by feed renderer!"); }
=head2 C<parse_feed_timestamp>
Take a feed_timestamp and return a Time::Piece object.
=cut
sub parse_feed_timestamp { die("Not implemented by feed renderer!"); }
1;
__END__
=head1 MAINTAINER
The Wiki::Toolkit team, http://www.wiki-toolkit.org/.
=head1 COPYRIGHT AND LICENSE
Copyright 2006-2009 the Wiki::Toolkit team.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
|