line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wiki::Toolkit::Plugin::JSON; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
39884
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
86
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
12
|
use vars qw( $VERSION ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
120
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.05'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
24
|
use JSON; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
13
|
|
9
|
2
|
|
|
2
|
|
1967
|
use POSIX 'strftime'; |
|
2
|
|
|
|
|
17059
|
|
|
2
|
|
|
|
|
12
|
|
10
|
2
|
|
|
2
|
|
6108
|
use Time::Piece; |
|
2
|
|
|
|
|
27636
|
|
|
2
|
|
|
|
|
12
|
|
11
|
2
|
|
|
2
|
|
2973
|
use URI::Escape; |
|
2
|
|
|
|
|
2922
|
|
|
2
|
|
|
|
|
134
|
|
12
|
2
|
|
|
2
|
|
11
|
use Carp qw( croak ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1625
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
16
|
0
|
|
|
|
|
|
my $self = {@_}; |
17
|
0
|
|
|
|
|
|
bless $self, $class; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
0
|
|
|
|
unless ( $self->{wiki} && UNIVERSAL::isa( $self->{wiki}, 'Wiki::Toolkit' ) ) |
20
|
|
|
|
|
|
|
{ |
21
|
0
|
|
|
|
|
|
croak 'No Wiki::Toolkit object supplied'; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Mandatory arguments. |
25
|
0
|
|
|
|
|
|
foreach my $arg (qw/site_name site_url make_node_url recent_changes_link/) { |
26
|
0
|
0
|
|
|
|
|
croak "No $arg supplied" unless $self->{$arg}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$self->{timestamp_fmt} = $Wiki::Toolkit::Store::Database::timestamp_fmt; |
30
|
0
|
|
|
|
|
|
$self->{utc_offset} = strftime "%z", localtime; |
31
|
0
|
|
|
|
|
|
$self->{utc_offset} =~ s/(..)(..)$/$1:$2/; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub recent_changes { |
37
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
38
|
0
|
|
|
|
|
|
my $wiki = $self->{wiki}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# If we're not passed any parameters to limit the items returned, default to 15. |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my %criteria = ( ignore_case => 1, ); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if ( $args{days} ) { |
45
|
0
|
|
|
|
|
|
$criteria{days} = $args{days}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
0
|
|
0
|
|
|
|
$criteria{last_n_changes} = $args{items} || 15; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ( $args{ignore_minor_edits} ) { |
52
|
0
|
|
|
|
|
|
$criteria{metadata_wasnt} = { major_change => 0 }; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if ( $args{filter_on_metadata} ) { |
56
|
0
|
|
|
|
|
|
$criteria{metadata_was} = $args{filter_on_metadata}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my @changes = $wiki->list_recent_changes(%criteria); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
foreach my $change (@changes) { |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$change->{timestamp} = $change->{last_modified}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Make a Time::Piece object. |
66
|
0
|
|
|
|
|
|
my $time = |
67
|
|
|
|
|
|
|
Time::Piece->strptime( $change->{timestamp}, $self->{timestamp_fmt} ); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $utc_offset = $self->{utc_offset}; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$change->{timestamp} = $time->strftime("%Y-%m-%dT%H:%M:%S$utc_offset"); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
0
|
|
|
|
$change->{author} = $change->{metadata}{username}[0] |
74
|
|
|
|
|
|
|
|| $change->{metadata}{host}[0] |
75
|
|
|
|
|
|
|
|| ''; |
76
|
0
|
|
0
|
|
|
|
$change->{description} = $change->{metadata}{comment}[0] || ''; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
$change->{status} = ( 1 == $change->{version} ) ? 'new' : 'updated'; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$change->{major_change} = $change->{metadata}{major_change}[0]; |
81
|
0
|
0
|
|
|
|
|
$change->{major_change} = 1 unless defined $change->{major_change}; |
82
|
0
|
0
|
|
|
|
|
$change->{importance} = $change->{major_change} ? 'major' : 'minor'; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$change->{url} = |
85
|
|
|
|
|
|
|
$self->{make_node_url}->( $change->{name}, $change->{version} ); |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
if ( $self->{make_diff_url} ) { |
88
|
0
|
|
|
|
|
|
$change->{diff_url} = $self->{make_diff_url}->( $change->{name} ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
if ( $self->{make_history_url} ) { |
92
|
0
|
|
|
|
|
|
$change->{history_url} = |
93
|
|
|
|
|
|
|
$self->{make_history_url}->( $change->{name} ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$change->{node_url} = $self->{make_node_url}->( $change->{name} ); |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $rdf_url = $change->{node_url}; |
99
|
0
|
|
|
|
|
|
$rdf_url =~ s/\?/\?id=/; |
100
|
0
|
|
|
|
|
|
$rdf_url .= ';format=rdf'; |
101
|
0
|
|
|
|
|
|
$change->{rdf_url} = $rdf_url; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# make XML-clean |
104
|
0
|
|
|
|
|
|
my $title = $change->{name}; |
105
|
0
|
|
|
|
|
|
$title =~ s/&/&/g; |
106
|
0
|
|
|
|
|
|
$title =~ s/</g; |
107
|
0
|
|
|
|
|
|
$title =~ s/>/>/g; |
108
|
0
|
|
|
|
|
|
$change->{title} = $title; |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
|
return $self->make_json( \@changes ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub make_json { |
114
|
0
|
|
|
0
|
0
|
|
my ( $self, $data ) = @_; |
115
|
0
|
|
|
|
|
|
return JSON::to_json( $data ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |