← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:27:13 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/HistoryPlugin.pm
StatementsExecuted 20 statements in 2.60ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11128µs36µsFoswiki::Plugins::HistoryPlugin::::BEGIN@5Foswiki::Plugins::HistoryPlugin::BEGIN@5
11126µs81µsFoswiki::Plugins::HistoryPlugin::::initPluginFoswiki::Plugins::HistoryPlugin::initPlugin
11125µs47µsFoswiki::Plugins::HistoryPlugin::::BEGIN@6Foswiki::Plugins::HistoryPlugin::BEGIN@6
11118µs158µsFoswiki::Plugins::HistoryPlugin::::BEGIN@12Foswiki::Plugins::HistoryPlugin::BEGIN@12
11116µs390µsFoswiki::Plugins::HistoryPlugin::::BEGIN@8Foswiki::Plugins::HistoryPlugin::BEGIN@8
11110µs10µsFoswiki::Plugins::HistoryPlugin::::BEGIN@9Foswiki::Plugins::HistoryPlugin::BEGIN@9
1119µs9µsFoswiki::Plugins::HistoryPlugin::::BEGIN@7Foswiki::Plugins::HistoryPlugin::BEGIN@7
0000s0sFoswiki::Plugins::HistoryPlugin::::_formatTimeFoswiki::Plugins::HistoryPlugin::_formatTime
0000s0sFoswiki::Plugins::HistoryPlugin::::_handleHeadFootFoswiki::Plugins::HistoryPlugin::_handleHeadFoot
0000s0sFoswiki::Plugins::HistoryPlugin::::_handleHistoryFoswiki::Plugins::HistoryPlugin::_handleHistory
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2
3package Foswiki::Plugins::HistoryPlugin;
4
5253µs244µs
# spent 36µs (28+8) within Foswiki::Plugins::HistoryPlugin::BEGIN@5 which was called: # once (28µs+8µs) by Foswiki::Plugin::BEGIN@2.8 at line 5
use strict;
# spent 36µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@5 # spent 8µs making 1 call to strict::import
6250µs268µs
# spent 47µs (25+21) within Foswiki::Plugins::HistoryPlugin::BEGIN@6 which was called: # once (25µs+21µs) by Foswiki::Plugin::BEGIN@2.8 at line 6
use warnings;
# spent 47µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@6 # spent 21µs making 1 call to warnings::import
7247µs19µs
# spent 9µs within Foswiki::Plugins::HistoryPlugin::BEGIN@7 which was called: # once (9µs+0s) by Foswiki::Plugin::BEGIN@2.8 at line 7
use Foswiki::Func ();
# spent 9µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@7
8248µs2763µs
# spent 390µs (16+373) within Foswiki::Plugins::HistoryPlugin::BEGIN@8 which was called: # once (16µs+373µs) by Foswiki::Plugin::BEGIN@2.8 at line 8
use Error qw(:try);
# spent 390µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@8 # spent 373µs making 1 call to Error::import
9249µs110µs
# spent 10µs within Foswiki::Plugins::HistoryPlugin::BEGIN@9 which was called: # once (10µs+0s) by Foswiki::Plugin::BEGIN@2.8 at line 9
use Foswiki::AccessControlException ();
# spent 10µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@9
10
11# =========================
1222.32ms2298µs
# spent 158µs (18+140) within Foswiki::Plugins::HistoryPlugin::BEGIN@12 which was called: # once (18µs+140µs) by Foswiki::Plugin::BEGIN@2.8 at line 12
use vars qw( $VERSION $RELEASE $NO_PREFS_IN_TOPIC $SHORTDESCRIPTION);
# spent 158µs making 1 call to Foswiki::Plugins::HistoryPlugin::BEGIN@12 # spent 140µs making 1 call to vars::import
13
1412µs$VERSION = '$Rev: 15950 $';
1511µs$RELEASE = '1.9';
1611µs$NO_PREFS_IN_TOPIC = 1;
1711µs$SHORTDESCRIPTION = 'Shows a complete history of a topic';
18
19# =========================
20
# spent 81µs (26+55) within Foswiki::Plugins::HistoryPlugin::initPlugin which was called: # once (26µs+55µs) by Foswiki::Plugin::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm:235] at line 228 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm
sub initPlugin {
21
22 # check for Plugins.pm versions
2312µs if ( $Foswiki::Plugins::VERSION < 1.021 ) {
24 Foswiki::Func::writeWarning(
25 "Version mismatch between HistoryPlugin and Plugins.pm");
26 return 0;
27 }
28
29112µs155µs Foswiki::Func::registerTagHandler( 'HISTORY', \&_handleHistory );
# spent 55µs making 1 call to Foswiki::Func::registerTagHandler
30
3118µs return 1;
32}
33
34sub _handleHistory {
35 my ( $session, $params, $theTopic, $theWeb ) = @_;
36
37 my $web = $params->{web} || $theWeb;
38 my $topic = $params->{topic} || $theTopic;
39 ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( $web, $topic );
40
41 # check topic exists
42 unless ( Foswiki::Func::topicExists( $web, $topic ) ) {
43 return
44"<noautolink><span class='foswikiAlert'>HistoryPlugin error: Topic $web.$topic does not exist</noautolink>";
45 }
46
47 # check access permissions
48 unless (
49 Foswiki::Func::checkAccessPermission(
50 "VIEW", $session->{user}, undef, $topic, $web
51 )
52 )
53 {
54 throw Foswiki::AccessControlException( "VIEW", $session->{user}, $web,
55 $topic, $Foswiki::Meta::reason );
56 }
57
58 my $reverse = Foswiki::Func::isTrue( $params->{reverse}, 1 );
59
60 my $versions = $params->{versions};
61 my $versionStart;
62 my $versionEnd;
63 my $maxrev = ( Foswiki::Func::getRevisionInfo( $web, $topic ) )[2];
64 my $rev1 = $params->{rev1} ? $params->{rev1} : 1;
65 my $rev2 = $params->{rev2} ? $params->{rev2} : $maxrev;
66 my $nrev = $params->{nrev} ? $params->{nrev} : 10;
67
68 if ($versions) {
69 $versions =~ /([0-9\-]*)(\.\.)*([0-9\-]*)/;
70 if ( defined $1 && length $1 ) {
71 $rev1 = $1;
72 }
73 if ( defined $2 && length $2 ) {
74
75 # dots
76 $rev2 = $3 if ( defined $3 && length $3 );
77 }
78 else {
79 $rev2 = $rev1;
80 }
81
82 # wrap
83 $rev1 = $maxrev + $rev1 if $rev1 < 0;
84 $rev2 = $maxrev + $rev2 if $rev2 < 0;
85
86 # normalize
87 $rev1 = 1 if $rev1 == 0;
88 $rev2 = 1 if $rev2 == 0;
89 $rev1 = $maxrev if $rev1 > $maxrev;
90 $rev2 = $maxrev if $rev2 > $maxrev;
91 if ( $rev1 > $rev2 ) {
92 $reverse = 0;
93 ( $rev1, $rev2 ) = ( $rev2, $rev1 );
94 }
95 }
96 else {
97
98 # deprecated syntax
99
100 $rev1 = $params->{rev1};
101 $rev1 =~ s/1\.// if $rev1;
102 $rev2 = $params->{rev2};
103 $rev2 =~ s/1\.// if $rev2;
104 $nrev = $params->{nrev} || 10;
105
106 $rev2 ||= $rev1 ? $rev1 + $nrev - 1 : $maxrev;
107 $rev1 ||= $rev2 - $nrev + 1;
108
109 ( $rev1, $rev2 ) = ( $rev2, $rev1 ) if $rev1 > $rev2;
110 $rev1 = $maxrev if $rev1 > $maxrev;
111 $rev1 = 1 if $rev1 < 1;
112 $rev2 = $maxrev if $rev2 > $maxrev;
113 $rev2 = 1 if $rev2 < 1;
114 }
115
116 my $format =
117 $params->{format}
118 || $params->{_DEFAULT}
119 || 'r$rev - $date - $wikiusername%BR%';
120 my $header = $params->{header};
121 $header = "\$next{'...'}%BR%" unless defined($header);
122 my $footer = $params->{footer};
123 $footer = "\$previous{'...'}" unless defined($footer);
124
125 Foswiki::Func::setPreferencesValue( "HISTORY_MAXREV", $maxrev );
126 Foswiki::Func::setPreferencesValue( "HISTORY_REV1", $rev1 );
127 Foswiki::Func::setPreferencesValue( "HISTORY_REV2", $rev2 );
128 Foswiki::Func::setPreferencesValue( "HISTORY_NREV", $nrev );
129
130 # Start the output
131 my $out = _handleHeadFoot( $header, $rev1, $rev2, $nrev, $maxrev );
132
133 # Print revision info
134
135 my @revs = ( $rev1 .. $rev2 );
136
137 @revs = reverse(@revs) if $reverse;
138 my $mixedAlphaNum = Foswiki::Func::getRegularExpression('mixedAlphaNum');
139 my $checkFlag = 0;
140
141 foreach my $rev (@revs) {
142
143 my ( $date, $user, $revout, $comment ) =
144 Foswiki::Func::getRevisionInfo( $web, $topic, $rev );
145
146 my $wikiName = Foswiki::Func::userToWikiName( $user, 1 );
147 my $wikiUserName = Foswiki::Func::userToWikiName( $user, 0 );
148
149 my $revinfo = $format;
150 my $checked1 = '';
151 my $checked2 = '';
152 $checked1 = 'checked' if $checkFlag == 0;
153 $checked2 = 'checked' if $checkFlag == 1;
154 $checkFlag++;
155 $revinfo =~ s/\$web/$web/g;
156 $revinfo =~ s/\$topic/$topic/g;
157 $revinfo =~ s/\$rev/$rev/g;
158 $revinfo =~ s/\$date/Foswiki::Func::formatTime($date)/ge;
159 $revinfo =~
160s/\$(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;
161 $revinfo =~ s/\$username/$user/g;
162 $revinfo =~ s/\$wikiname/$wikiName/g;
163 $revinfo =~ s/\$wikiusername/$wikiUserName/g;
164 $revinfo =~ s/\$checked1/$checked1/g;
165 $revinfo =~ s/\$checked2/$checked2/g;
166
167 # This space to tabs conversion must be for Cairo compatibility
168 $revinfo =~ s|^(( )+)|"\t" x (length($1)/3)|e;
169
170 $out .= $revinfo . "\n";
171
172 $rev--;
173 }
174 $out .= _handleHeadFoot( $footer, $rev1, $rev2, $nrev, $maxrev );
175 $out = Foswiki::Func::decodeFormatTokens($out);
176
177 return $out;
178}
179
180sub _formatTime {
181 my ( $format, $topic, $web ) = @_;
182
183 return Foswiki::Func::expandCommonVariables( '%REVINFO{"' . $format . '"}%',
184 $topic, $web );
185}
186
187sub _handleHeadFoot {
188
189 my ( $text, $rev1, $rev2, $nrev, $maxrev ) = @_;
190
191 if ( $rev2 >= $maxrev ) {
192 $text =~ s/\$next({.*?})//g;
193 }
194 else {
195 while ( $text =~ /\$next({(.*?)})/ ) {
196 my $args = $2 || '';
197
198 my $newrev1 = $rev2 < $maxrev ? $rev2 + 1 : $rev2;
199 my $newrev2 = $newrev1 + $nrev - 1;
200 $newrev2 = $maxrev if $newrev2 > $maxrev;
201
202 $args =~ s/'/"/g;
203 $args =~ s/\$rev1/$newrev1/g;
204 $args =~ s/\$rev2/$newrev2/g;
205 $args =~ s/\$nrev/$nrev/g;
206
207 my %params = Foswiki::Func::extractParameters($args);
208 my $newtext = $params{text} || $params{_DEFAULT} || '';
209 my $url = $params{url} || '';
210 my $replace =
211 $url
212 ? "<a href='$url' class='foswikiButton'>$newtext</a>"
213 : $newtext;
214 $text =~ s/\$next({.*?})/$replace/;
215 }
216 }
217
218 if ( $rev1 <= 1 ) {
219 $text =~ s/\$previous({.*?})//g;
220 }
221 else {
222 while ( $text =~ /\$previous({(.*?)})/ ) {
223 my $args = $2 || '';
224
225 my $newrev2 = $rev1 > 1 ? $rev1 - 1 : 1;
226 my $newrev1 = $newrev2 - $nrev + 1;
227 $newrev1 = 1 if $newrev1 < 1;
228
229 $args =~ s/'/"/g;
230 $args =~ s/\$rev1/$newrev1/g;
231 $args =~ s/\$rev2/$newrev2/g;
232 $args =~ s/\$nrev/$nrev/g;
233
234 my %params = Foswiki::Func::extractParameters($args);
235 my $newtext = $params{text} || $params{_DEFAULT} || '';
236 my $url = $params{url} || '';
237 my $replace =
238 $url
239 ? "<a href='$url' class='foswikiButton'>$newtext</a>"
240 : $newtext;
241 $text =~ s/\$previous({.*?})/$replace/;
242 }
243 }
244
245 return $text;
246}
247
24816µs1;
249__END__