Filename | /var/www/foswiki11/lib/Foswiki/Plugins/HistoryPlugin.pm |
Statements | Executed 18 statements in 1.38ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 24µs | 64µs | initPlugin | Foswiki::Plugins::HistoryPlugin::
1 | 1 | 1 | 13µs | 26µs | BEGIN@5 | Foswiki::Plugins::HistoryPlugin::
1 | 1 | 1 | 9µs | 15µs | BEGIN@6 | Foswiki::Plugins::HistoryPlugin::
1 | 1 | 1 | 9µs | 116µs | BEGIN@8 | Foswiki::Plugins::HistoryPlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@9 | Foswiki::Plugins::HistoryPlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@7 | Foswiki::Plugins::HistoryPlugin::
0 | 0 | 0 | 0s | 0s | _formatTime | Foswiki::Plugins::HistoryPlugin::
0 | 0 | 0 | 0s | 0s | _handleHeadFoot | Foswiki::Plugins::HistoryPlugin::
0 | 0 | 0 | 0s | 0s | _handleHistory | Foswiki::Plugins::HistoryPlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | package Foswiki::Plugins::HistoryPlugin; | ||||
4 | |||||
5 | 2 | 27µs | 2 | 38µs | # spent 26µs (13+13) within Foswiki::Plugins::HistoryPlugin::BEGIN@5 which was called:
# once (13µs+13µs) by Foswiki::Plugin::BEGIN@2.16 at line 5 # spent 26µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@5
# spent 13µs making 1 call to strict::import |
6 | 2 | 25µs | 2 | 20µs | # spent 15µs (9+6) within Foswiki::Plugins::HistoryPlugin::BEGIN@6 which was called:
# once (9µs+6µs) by Foswiki::Plugin::BEGIN@2.16 at line 6 # spent 15µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@6
# spent 6µs making 1 call to warnings::import |
7 | 2 | 22µs | 1 | 4µs | # spent 4µs within Foswiki::Plugins::HistoryPlugin::BEGIN@7 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.16 at line 7 # spent 4µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@7 |
8 | 2 | 31µs | 2 | 224µs | # spent 116µs (9+108) within Foswiki::Plugins::HistoryPlugin::BEGIN@8 which was called:
# once (9µs+108µs) by Foswiki::Plugin::BEGIN@2.16 at line 8 # spent 116µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@8
# spent 108µs making 1 call to Error::import |
9 | 2 | 1.24ms | 1 | 4µs | # spent 4µs within Foswiki::Plugins::HistoryPlugin::BEGIN@9 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.16 at line 9 # spent 4µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@9 |
10 | |||||
11 | # ========================= | ||||
12 | # Simple decimal version, no leading "v" | ||||
13 | 1 | 600ns | our $VERSION = "1.11"; | ||
14 | 1 | 200ns | our $RELEASE = '1.11'; | ||
15 | 1 | 100ns | our $NO_PREFS_IN_TOPIC = 1; | ||
16 | 1 | 200ns | our $SHORTDESCRIPTION = 'Shows a complete history of a topic'; | ||
17 | |||||
18 | # ========================= | ||||
19 | # spent 64µs (24+40) within Foswiki::Plugins::HistoryPlugin::initPlugin which was called:
# once (24µs+40µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm | ||||
20 | |||||
21 | # check for Plugins.pm versions | ||||
22 | 1 | 20µs | 1 | 11µs | if ( $Foswiki::Plugins::VERSION < 1.021 ) { # spent 11µs making 1 call to version::vxs::VCMP |
23 | Foswiki::Func::writeWarning( | ||||
24 | "Version mismatch between HistoryPlugin and Plugins.pm"); | ||||
25 | return 0; | ||||
26 | } | ||||
27 | |||||
28 | 1 | 4µs | 1 | 29µs | Foswiki::Func::registerTagHandler( 'HISTORY', \&_handleHistory ); # spent 29µs making 1 call to Foswiki::Func::registerTagHandler |
29 | |||||
30 | 1 | 7µs | return 1; | ||
31 | } | ||||
32 | |||||
33 | sub _handleHistory { | ||||
34 | my ( $session, $params, $theTopic, $theWeb ) = @_; | ||||
35 | |||||
36 | my $web = $params->{web} || $theWeb; | ||||
37 | my $topic = $params->{topic} || $theTopic; | ||||
38 | ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( $web, $topic ); | ||||
39 | |||||
40 | # check topic exists | ||||
41 | unless ( Foswiki::Func::topicExists( $web, $topic ) ) { | ||||
42 | return | ||||
43 | "<noautolink><span class='foswikiAlert'>HistoryPlugin error: Topic $web.$topic does not exist</noautolink>"; | ||||
44 | } | ||||
45 | |||||
46 | # check access permissions | ||||
47 | unless ( | ||||
48 | Foswiki::Func::checkAccessPermission( | ||||
49 | "VIEW", $session->{user}, undef, $topic, $web | ||||
50 | ) | ||||
51 | ) | ||||
52 | { | ||||
53 | throw Foswiki::AccessControlException( "VIEW", $session->{user}, $web, | ||||
54 | $topic, $Foswiki::Meta::reason ); | ||||
55 | } | ||||
56 | |||||
57 | my $reverse = Foswiki::Func::isTrue( $params->{reverse}, 1 ); | ||||
58 | |||||
59 | my $versions = $params->{versions}; | ||||
60 | my $versionStart; | ||||
61 | my $versionEnd; | ||||
62 | my $maxrev = ( Foswiki::Func::getRevisionInfo( $web, $topic ) )[2]; | ||||
63 | my $rev1 = $params->{rev1} ? $params->{rev1} : 1; | ||||
64 | my $rev2 = $params->{rev2} ? $params->{rev2} : $maxrev; | ||||
65 | my $nrev = $params->{nrev} ? $params->{nrev} : 10; | ||||
66 | |||||
67 | if ($versions) { | ||||
68 | $versions =~ /([0-9\-]*)(\.\.)*([0-9\-]*)/; | ||||
69 | if ( defined $1 && length $1 ) { | ||||
70 | $rev1 = $1; | ||||
71 | } | ||||
72 | if ( defined $2 && length $2 ) { | ||||
73 | |||||
74 | # dots | ||||
75 | $rev2 = $3 if ( defined $3 && length $3 ); | ||||
76 | } | ||||
77 | else { | ||||
78 | $rev2 = $rev1; | ||||
79 | } | ||||
80 | |||||
81 | # wrap | ||||
82 | $rev1 = $maxrev + $rev1 if $rev1 < 0; | ||||
83 | $rev2 = $maxrev + $rev2 if $rev2 < 0; | ||||
84 | |||||
85 | # normalize | ||||
86 | $rev1 = 1 if $rev1 == 0; | ||||
87 | $rev2 = 1 if $rev2 == 0; | ||||
88 | $rev1 = $maxrev if $rev1 > $maxrev; | ||||
89 | $rev2 = $maxrev if $rev2 > $maxrev; | ||||
90 | if ( $rev1 > $rev2 ) { | ||||
91 | $reverse = 0; | ||||
92 | ( $rev1, $rev2 ) = ( $rev2, $rev1 ); | ||||
93 | } | ||||
94 | } | ||||
95 | else { | ||||
96 | |||||
97 | # deprecated syntax | ||||
98 | |||||
99 | $rev1 = $params->{rev1}; | ||||
100 | $rev1 =~ s/1\.// if $rev1; | ||||
101 | $rev2 = $params->{rev2}; | ||||
102 | $rev2 =~ s/1\.// if $rev2; | ||||
103 | $nrev = $params->{nrev} || 10; | ||||
104 | |||||
105 | $rev2 ||= $rev1 ? $rev1 + $nrev - 1 : $maxrev; | ||||
106 | $rev1 ||= $rev2 - $nrev + 1; | ||||
107 | |||||
108 | ( $rev1, $rev2 ) = ( $rev2, $rev1 ) if $rev1 > $rev2; | ||||
109 | $rev1 = $maxrev if $rev1 > $maxrev; | ||||
110 | $rev1 = 1 if $rev1 < 1; | ||||
111 | $rev2 = $maxrev if $rev2 > $maxrev; | ||||
112 | $rev2 = 1 if $rev2 < 1; | ||||
113 | } | ||||
114 | |||||
115 | my $format = | ||||
116 | $params->{format} | ||||
117 | || $params->{_DEFAULT} | ||||
118 | || 'r$rev - $date - $wikiusername%BR%'; | ||||
119 | my $header = $params->{header}; | ||||
120 | $header = "\$next{'...'}%BR%" unless defined($header); | ||||
121 | my $footer = $params->{footer}; | ||||
122 | $footer = "\$previous{'...'}" unless defined($footer); | ||||
123 | |||||
124 | Foswiki::Func::setPreferencesValue( "HISTORY_MAXREV", $maxrev ); | ||||
125 | Foswiki::Func::setPreferencesValue( "HISTORY_REV1", $rev1 ); | ||||
126 | Foswiki::Func::setPreferencesValue( "HISTORY_REV2", $rev2 ); | ||||
127 | Foswiki::Func::setPreferencesValue( "HISTORY_NREV", $nrev ); | ||||
128 | |||||
129 | # Start the output | ||||
130 | my $out = _handleHeadFoot( $header, $rev1, $rev2, $nrev, $maxrev ); | ||||
131 | |||||
132 | # Print revision info | ||||
133 | |||||
134 | my @revs = ( $rev1 .. $rev2 ); | ||||
135 | |||||
136 | @revs = reverse(@revs) if $reverse; | ||||
137 | my $mixedAlphaNum = Foswiki::Func::getRegularExpression('mixedAlphaNum'); | ||||
138 | my $checkFlag = 0; | ||||
139 | |||||
140 | foreach my $rev (@revs) { | ||||
141 | |||||
142 | my ( $date, $user, $revout, $comment ) = | ||||
143 | Foswiki::Func::getRevisionInfo( $web, $topic, $rev ); | ||||
144 | |||||
145 | my $wikiName = Foswiki::Func::userToWikiName( $user, 1 ); | ||||
146 | my $wikiUserName = Foswiki::Func::userToWikiName( $user, 0 ); | ||||
147 | |||||
148 | my $revinfo = $format; | ||||
149 | my $checked1 = ''; | ||||
150 | my $checked2 = ''; | ||||
151 | $checked1 = 'checked' if $checkFlag == 0; | ||||
152 | $checked2 = 'checked' if $checkFlag == 1; | ||||
153 | $checkFlag++; | ||||
154 | $revinfo =~ s/\$web/$web/g; | ||||
155 | $revinfo =~ s/\$topic/$topic/g; | ||||
156 | $revinfo =~ s/\$rev/$rev/g; | ||||
157 | $revinfo =~ s/\$date/Foswiki::Func::formatTime($date)/ge; | ||||
158 | $revinfo =~ | ||||
159 | s/\$(year|ye|week|web|wday|tz|topic|time|seconds|rev|rcs|month|mo|minutes|longdate|isotz|iso|http|hours|epoch|email|dow|day)/_formatTime("\$$1", $topic, $web)/ge; | ||||
160 | $revinfo =~ s/\$username/$user/g; | ||||
161 | $revinfo =~ s/\$wikiname/$wikiName/g; | ||||
162 | $revinfo =~ s/\$wikiusername/$wikiUserName/g; | ||||
163 | $revinfo =~ s/\$checked1/$checked1/g; | ||||
164 | $revinfo =~ s/\$checked2/$checked2/g; | ||||
165 | |||||
166 | # This space to tabs conversion must be for Cairo compatibility | ||||
167 | $revinfo =~ s|^(( )+)|"\t" x (length($1)/3)|e; | ||||
168 | |||||
169 | $out .= $revinfo . "\n"; | ||||
170 | |||||
171 | $rev--; | ||||
172 | } | ||||
173 | $out .= _handleHeadFoot( $footer, $rev1, $rev2, $nrev, $maxrev ); | ||||
174 | $out = Foswiki::Func::decodeFormatTokens($out); | ||||
175 | |||||
176 | return $out; | ||||
177 | } | ||||
178 | |||||
179 | sub _formatTime { | ||||
180 | my ( $format, $topic, $web ) = @_; | ||||
181 | |||||
182 | return Foswiki::Func::expandCommonVariables( '%REVINFO{"' . $format . '"}%', | ||||
183 | $topic, $web ); | ||||
184 | } | ||||
185 | |||||
186 | sub _handleHeadFoot { | ||||
187 | |||||
188 | my ( $text, $rev1, $rev2, $nrev, $maxrev ) = @_; | ||||
189 | |||||
190 | if ( $rev2 >= $maxrev ) { | ||||
191 | $text =~ s/\$next({.*?})//g; | ||||
192 | } | ||||
193 | else { | ||||
194 | while ( $text =~ /\$next({(.*?)})/ ) { | ||||
195 | my $args = $2 || ''; | ||||
196 | |||||
197 | my $newrev1 = $rev2 < $maxrev ? $rev2 + 1 : $rev2; | ||||
198 | my $newrev2 = $newrev1 + $nrev - 1; | ||||
199 | $newrev2 = $maxrev if $newrev2 > $maxrev; | ||||
200 | |||||
201 | $args =~ s/'/"/g; | ||||
202 | $args =~ s/\$rev1/$newrev1/g; | ||||
203 | $args =~ s/\$rev2/$newrev2/g; | ||||
204 | $args =~ s/\$nrev/$nrev/g; | ||||
205 | |||||
206 | my %params = Foswiki::Func::extractParameters($args); | ||||
207 | my $newtext = $params{text} || $params{_DEFAULT} || ''; | ||||
208 | my $url = $params{url} || ''; | ||||
209 | my $replace = | ||||
210 | $url | ||||
211 | ? "<a href='$url' class='foswikiButton'>$newtext</a>" | ||||
212 | : $newtext; | ||||
213 | $text =~ s/\$next({.*?})/$replace/; | ||||
214 | } | ||||
215 | } | ||||
216 | |||||
217 | if ( $rev1 <= 1 ) { | ||||
218 | $text =~ s/\$previous({.*?})//g; | ||||
219 | } | ||||
220 | else { | ||||
221 | while ( $text =~ /\$previous({(.*?)})/ ) { | ||||
222 | my $args = $2 || ''; | ||||
223 | |||||
224 | my $newrev2 = $rev1 > 1 ? $rev1 - 1 : 1; | ||||
225 | my $newrev1 = $newrev2 - $nrev + 1; | ||||
226 | $newrev1 = 1 if $newrev1 < 1; | ||||
227 | |||||
228 | $args =~ s/'/"/g; | ||||
229 | $args =~ s/\$rev1/$newrev1/g; | ||||
230 | $args =~ s/\$rev2/$newrev2/g; | ||||
231 | $args =~ s/\$nrev/$nrev/g; | ||||
232 | |||||
233 | my %params = Foswiki::Func::extractParameters($args); | ||||
234 | my $newtext = $params{text} || $params{_DEFAULT} || ''; | ||||
235 | my $url = $params{url} || ''; | ||||
236 | my $replace = | ||||
237 | $url | ||||
238 | ? "<a href='$url' class='foswikiButton'>$newtext</a>" | ||||
239 | : $newtext; | ||||
240 | $text =~ s/\$previous({.*?})/$replace/; | ||||
241 | } | ||||
242 | } | ||||
243 | |||||
244 | return $text; | ||||
245 | } | ||||
246 | |||||
247 | 1 | 4µs | 1; | ||
248 | __END__ |