← 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:08 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/UI/View.pm
StatementsExecuted 147 statements in 7.32ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
54211.54ms1.54msFoswiki::UI::View::::CORE:substcontFoswiki::UI::View::CORE:substcont (opcode)
1111.00ms184sFoswiki::UI::View::::viewFoswiki::UI::View::view
751526µs526µsFoswiki::UI::View::::CORE:substFoswiki::UI::View::CORE:subst (opcode)
331369µs183sFoswiki::UI::View::::_prepareFoswiki::UI::View::_prepare
111246µs252µsFoswiki::UI::View::::BEGIN@15Foswiki::UI::View::BEGIN@15
111117µs313msFoswiki::UI::View::::revisionsAroundFoswiki::UI::View::revisionsAround
65191µs91µsFoswiki::UI::View::::CORE:matchFoswiki::UI::View::CORE:match (opcode)
11126µs67µsFoswiki::UI::View::::BEGIN@14Foswiki::UI::View::BEGIN@14
11125µs33µsFoswiki::UI::View::::BEGIN@13Foswiki::UI::View::BEGIN@13
11119µs63µsFoswiki::UI::View::::BEGIN@17Foswiki::UI::View::BEGIN@17
11110µs10µsFoswiki::UI::View::::BEGIN@16Foswiki::UI::View::BEGIN@16
1119µs9µsFoswiki::UI::View::::BEGIN@19Foswiki::UI::View::BEGIN@19
1119µs9µsFoswiki::UI::View::::BEGIN@20Foswiki::UI::View::BEGIN@20
1119µs9µsFoswiki::UI::View::::BEGIN@21Foswiki::UI::View::BEGIN@21
1118µs8µsFoswiki::UI::View::::BEGIN@22Foswiki::UI::View::BEGIN@22
1118µs8µsFoswiki::UI::View::::BEGIN@23Foswiki::UI::View::BEGIN@23
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
3=begin TML
4
5---+ package Foswiki::UI::View
6
7UI delegate for view function
8
9=cut
10
11package Foswiki::UI::View;
12
13259µs241µs
# spent 33µs (25+8) within Foswiki::UI::View::BEGIN@13 which was called: # once (25µs+8µs) by Foswiki::UI::BEGIN@2 at line 13
use strict;
# spent 33µs making 1 call to Foswiki::UI::View::BEGIN@13 # spent 8µs making 1 call to strict::import
14265µs2107µs
# spent 67µs (26+41) within Foswiki::UI::View::BEGIN@14 which was called: # once (26µs+41µs) by Foswiki::UI::BEGIN@2 at line 14
use warnings;
# spent 67µs making 1 call to Foswiki::UI::View::BEGIN@14 # spent 41µs making 1 call to warnings::import
152263µs2258µs
# spent 252µs (246+6) within Foswiki::UI::View::BEGIN@15 which was called: # once (246µs+6µs) by Foswiki::UI::BEGIN@2 at line 15
use integer;
# spent 252µs making 1 call to Foswiki::UI::View::BEGIN@15 # spent 6µs making 1 call to integer::import
16240µs110µs
# spent 10µs within Foswiki::UI::View::BEGIN@16 which was called: # once (10µs+0s) by Foswiki::UI::BEGIN@2 at line 16
use Monitor ();
# spent 10µs making 1 call to Foswiki::UI::View::BEGIN@16
17247µs2107µs
# spent 63µs (19+44) within Foswiki::UI::View::BEGIN@17 which was called: # once (19µs+44µs) by Foswiki::UI::BEGIN@2 at line 17
use Assert;
# spent 63µs making 1 call to Foswiki::UI::View::BEGIN@17 # spent 44µs making 1 call to Assert::import
18
19237µs19µs
# spent 9µs within Foswiki::UI::View::BEGIN@19 which was called: # once (9µs+0s) by Foswiki::UI::BEGIN@2 at line 19
use Foswiki ();
# spent 9µs making 1 call to Foswiki::UI::View::BEGIN@19
20237µs19µs
# spent 9µs within Foswiki::UI::View::BEGIN@20 which was called: # once (9µs+0s) by Foswiki::UI::BEGIN@2 at line 20
use Foswiki::UI ();
# spent 9µs making 1 call to Foswiki::UI::View::BEGIN@20
21236µs19µs
# spent 9µs within Foswiki::UI::View::BEGIN@21 which was called: # once (9µs+0s) by Foswiki::UI::BEGIN@2 at line 21
use Foswiki::Sandbox ();
# spent 9µs making 1 call to Foswiki::UI::View::BEGIN@21
22236µs18µs
# spent 8µs within Foswiki::UI::View::BEGIN@22 which was called: # once (8µs+0s) by Foswiki::UI::BEGIN@2 at line 22
use Foswiki::OopsException ();
# spent 8µs making 1 call to Foswiki::UI::View::BEGIN@22
2323.20ms18µs
# spent 8µs within Foswiki::UI::View::BEGIN@23 which was called: # once (8µs+0s) by Foswiki::UI::BEGIN@2 at line 23
use Foswiki::Store ();
# spent 8µs making 1 call to Foswiki::UI::View::BEGIN@23
24
25=begin TML
26
27---++ StaticMethod view( $session )
28
29=view= command handler.
30This method is designed to be
31invoked via the =UI::run= method.
32
33Generate a complete HTML page that represents the viewed topics.
34The view is controlled by CGI parameters as follows:
35
36| =rev= | topic revision to view |
37| =section= | restrict view to a named section |
38| =raw= | no format body text if set |
39| =skin= | comma-separated list of skin(s) to use |
40| =contenttype= | Allows you to specify an alternate content type |
41
42=cut
43
44
# spent 184s (1.00ms+184) within Foswiki::UI::View::view which was called: # once (1.00ms+184s) by Foswiki::UI::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/UI.pm:318] at line 316 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/UI.pm
sub view {
4512µs my $session = shift;
46
4712µs my $query = $session->{request};
4812µs my $web = $session->{webName};
4912µs my $topic = $session->{topicName};
50
5112µs my $cache = $session->{cache};
5211µs my $cachedPage;
5311µs $cachedPage = $cache->getPage( $web, $topic ) if $cache;
5411µs if ($cachedPage) {
55 print STDERR "found $web.$topic in cache\n"
56 if $Foswiki::cfg{Cache}{Debug};
57 Monitor::MARK("found page in cache");
58
59 # render uncacheable areas
60 my $text = $cachedPage->{text};
61 $cache->renderDirtyAreas( \$text ) if $cachedPage->{isDirty};
62
63 # set status
64 my $status = $cachedPage->{status};
65 if ( $status == 302 ) {
66 $session->{response}->redirect( $cachedPage->{location} );
67 }
68 else {
69
70 # See Item9941 to understand why do not set status when 200
71 $session->{response}->status($status) unless $status eq 200;
72 }
73
74 # set headers
75 $session->generateHTTPHeaders( 'view', $cachedPage->{contentType},
76 $text, $cachedPage );
77
78 # send it out
79 $session->{response}->print($text);
80
81 Monitor::MARK('Wrote HTML');
82 $session->logEvent( 'view', $web . '.' . $topic, '(cached)' );
83
84 return;
85 }
86
8714µs print STDERR "computing page for $web.$topic\n"
88 if $Foswiki::cfg{Cache}{Debug};
89
90113µs175µs my $raw = $query->param('raw') || '';
# spent 75µs making 1 call to Foswiki::Request::param
9116µs144µs my $contentType = $query->param('contenttype');
# spent 44µs making 1 call to Foswiki::Request::param
92
9314µs my $logEntry = '';
94
95 # is this view indexable by search engines? Default yes.
9612µs my $indexableView = 1;
9711µs my $viewTemplate;
98
99110µs1254µs Foswiki::UI::checkWebExists( $session, $web, 'view' );
# spent 254µs making 1 call to Foswiki::UI::checkWebExists
100
101115µs262µs my $requestedRev = Foswiki::Store::cleanUpRevID( $query->param('rev') );
# spent 48µs making 1 call to Foswiki::Request::param # spent 13µs making 1 call to Foswiki::Store::cleanUpRevID
10212µs my $showLatest = !$requestedRev;
10311µs my $showRev;
104
10511µs my $topicObject; # the stub of the topic we are to display
10611µs my $text; # the text to display, *not* necessarily
107 # the same as $topicObject->text
10811µs my $revIt; # Iterator over the range of available revs
10911µs my $maxRev;
110
11118µs1134µs if ( $session->topicExists( $web, $topic ) ) {
# spent 134µs making 1 call to Foswiki::topicExists
112
113 # Load the most recent rev. This *should* be maxRev, but may
114 # not say it is because the TOPICINFO could be up the spout
115112µs16.11ms $topicObject = Foswiki::Meta->load( $session, $web, $topic );
# spent 6.11ms making 1 call to Foswiki::Meta::load
116110µs12.31ms Foswiki::UI::checkAccess( $session, 'VIEW', $topicObject );
# spent 2.31ms making 1 call to Foswiki::UI::checkAccess
117
118112µs1308ms $revIt = $topicObject->getRevisionHistory();
# spent 308ms making 1 call to Foswiki::Meta::getRevisionHistory
119
120 # The topic exists; it must have at least one rev
121113µs112µs ASSERT( $revIt->hasNext() ) if DEBUG;
# spent 12µs making 1 call to Assert::ASSERTS_OFF
12217µs111µs $maxRev = $revIt->next();
# spent 11µs making 1 call to Foswiki::Iterator::NumberRangeIterator::next
123
12413µs if ( defined $requestedRev ) {
125
126 # Is the requested rev id known?
12716µs17µs $revIt->reset();
# spent 7µs making 1 call to Foswiki::Iterator::NumberRangeIterator::reset
12818µs110µs while ( $revIt->hasNext() ) {
# spent 10µs making 1 call to Foswiki::Iterator::NumberRangeIterator::hasNext
129115µs217µs if ( $requestedRev eq $revIt->next() ) {
# spent 9µs making 1 call to Foswiki::Iterator::NumberRangeIterator::next # spent 8µs making 1 call to Foswiki::Iterator::NumberRangeIterator::hasNext
130 $showRev = $requestedRev;
131 last;
132 }
133 }
134
135 # if rev was not found; show max rev
13612µs $showRev = $maxRev unless ( defined $showRev );
137
13812µs if ( $showRev ne $maxRev ) {
139
140 # Load the old revision instead
141 $topicObject =
142 Foswiki::Meta->load( $session, $web, $topic, $showRev );
143 if ( !$topicObject->haveAccess('VIEW') ) {
144 throw Foswiki::AccessControlException( 'VIEW',
145 $session->{user}, $web, $topic,
146 $Foswiki::Meta::reason );
147 }
148 $logEntry .= 'r' . $requestedRev;
149 }
150 }
151 else {
152 $showRev = $maxRev;
153 }
154
155120µs1102µs if ( my $section = $query->param('section') ) {
# spent 102µs making 1 call to Foswiki::Request::param
156
157 # Apply the 'section' selection (and maybe others in the
158 # future as well). $text is cleared unless a named section
159 # matching the 'section' URL parameter is found.
160 my ( $ntext, $sections ) =
161 Foswiki::parseSections( $topicObject->text() );
162 $text = ''; # in the beginning, there was ... NO section
163 FINDSECTION:
164 for my $s (@$sections) {
165 if ( $s->{type} eq 'section' && $s->{name} eq $section ) {
166 $text =
167 substr( $ntext, $s->{start}, $s->{end} - $s->{start} );
168 last FINDSECTION;
169 }
170 }
171 }
172 else {
173
174 # Otherwise take the full topic text
175114µs140µs $text = $topicObject->text();
# spent 40µs making 1 call to Foswiki::Meta::text
176 }
177 }
178 else { # Topic does not exist yet
179 $topicObject = Foswiki::Meta->new( $session, $web, $topic );
180 $indexableView = 0;
181 $session->enterContext('new_topic');
182 $session->{response}->status(404);
183 $showRev = 1;
184 $maxRev = 0;
185 $viewTemplate = 'TopicDoesNotExistView';
186 $logEntry .= ' (not exist)';
187 $raw = ''; # There is no raw view of a topic that doesn't exist
188 $revIt = new Foswiki::ListIterator( [1] );
189 }
190
19112µs if ($raw) {
192 $indexableView = 0;
193 $logEntry .= ' raw=' . $raw;
194 if ( $raw eq 'debug' || $raw eq 'all' ) {
195
196 # We want to see the embedded store form
197 $text = $topicObject->getEmbeddedStoreForm();
198 }
199 }
200
20112µs $text = '' unless defined $text;
202
203135µs38.68ms $session->logEvent( 'view', $topicObject->web . '.' . $topicObject->topic,
# spent 8.65ms making 1 call to Foswiki::logEvent # spent 14µs making 1 call to Foswiki::Meta::web # spent 11µs making 1 call to Foswiki::Meta::topic
204 $logEntry );
205
206 # Note; must enter all contexts before the template is read, as
207 # TMPL:P is expanded on the fly in the template reader. :-(
20814µs my ( $revTitle, $revArg ) = ( '', '' );
20917µs18µs $revIt->reset();
# spent 8µs making 1 call to Foswiki::Iterator::NumberRangeIterator::reset
21016µs110µs if ( $showRev && $showRev != $revIt->next() ) {
# spent 10µs making 1 call to Foswiki::Iterator::NumberRangeIterator::next
211 $session->enterContext('inactive');
212
213 # disable edit of previous revisions
214 $revTitle = '(r' . $showRev . ')';
215 $revArg = '&rev=' . $showRev;
216 }
217
218123µs2246µs my $template =
# spent 188µs making 1 call to Foswiki::Prefs::getPreference # spent 58µs making 1 call to Foswiki::Request::param
219 $viewTemplate
220 || $query->param('template')
221 || $session->{prefs}->getPreference('VIEW_TEMPLATE')
222 || 'view';
223
224 # Always use default view template for raw=debug, raw=all and raw=on
225114µs14µs if ( $raw =~ /^(debug|all|on)$/ ) {
# spent 4µs making 1 call to Foswiki::UI::View::CORE:match
226 $template = 'view';
227 }
228
229115µs2122ms my $tmpl = $session->templates->readTemplate( $template, no_oops => 1 );
# spent 111ms making 1 call to Foswiki::Templates::readTemplate # spent 10.9ms making 1 call to Foswiki::templates
230
231 # If the VIEW_TEMPLATE (or other) doesn't exist, default to view.
23212µs $tmpl = $session->templates->readTemplate('view') unless defined($tmpl);
233
234132µs119µs $tmpl =~ s/%REVTITLE%/$revTitle/g;
# spent 19µs making 1 call to Foswiki::UI::View::CORE:subst
235127µs118µs $tmpl =~ s/%REVARG%/$revArg/g;
# spent 18µs making 1 call to Foswiki::UI::View::CORE:subst
236
237118µs162µs if ( $indexableView
# spent 62µs making 1 call to Foswiki::Request::param
238 && $Foswiki::cfg{AntiSpam}{RobotsAreWelcome}
239 && !$query->param() )
240 {
241
242 # it's an indexable view type, there are no parameters
243 # on the url, and robots are welcome. Remove the NOINDEX meta tag
244151µs144µs $tmpl =~ s/<meta name="robots"[^>]*>//goi;
# spent 44µs making 1 call to Foswiki::UI::View::CORE:subst
245 }
246
247 # Show revisions around the one being displayed.
248182µs358µs $tmpl =~ s/%REVISIONS%/
# spent 43µs making 2 calls to Foswiki::UI::View::CORE:substcont, avg 21µs/call # spent 15µs making 1 call to Foswiki::UI::View::CORE:subst
249111µs1313ms revisionsAround(
# spent 313ms making 1 call to Foswiki::UI::View::revisionsAround
250 $session, $topicObject, $requestedRev, $showRev, $maxRev)/e;
251
252 ## SMELL: This is also used in Foswiki::_TOC. Could insert a tag in
253 ## TOC and remove all those here, finding the parameters only once
25413µs my @qparams = ();
255122µs181µs foreach my $name ( $query->param ) {
# spent 81µs making 1 call to Foswiki::Request::param
256 next if ( $name eq 'keywords' );
257 next if ( $name eq 'topic' );
258 push @qparams, $name => $query->param($name);
259 }
260
261# SMELL: %QUERYPARAMSTRING% isn't a documented macro, and is no longer used in core
262# or core extensions. Maintained for legacy only.
263120µs19µs if ( $tmpl =~ /%QUERYPARAMSTRING%/ ) {
# spent 9µs making 1 call to Foswiki::UI::View::CORE:match
264 my $qps = Foswiki::make_params(@qparams);
265 $qps =~ s/^.*\?/;/; # remove any anchor (there should be none) and the ?
266 $tmpl =~ s/%QUERYPARAMSTRING%/$qps/g;
267 }
268
269 # extract header and footer from the template, if there is a
270 # %TEXT% tag marking the split point. The topic text is inserted
271 # in place of the %TEXT% tag. The text before this tag is inserted
272 # as header, the text after is inserted as footer. If there is a
273 # %STARTTEXT% tag present, the header text between %STARTTEXT% and
274 # %TEXT is rendered together, as is the footer text between %TEXT%
275 # and %ENDTEXT%, if present. This allows correct handling of Foswiki
276 # markup in header or footer if those do require examination of the
277 # topic text to work correctly (e.g., %TOC%).
278 # Note: This feature is experimental and may be replaced by an
279 # alternative solution not requiring additional tags.
28012µs my ( $start, $end );
281
282 # SMELL: unchecked implicit untaint of data that *may* be coming from
283 # a topic (topics can be templates)
284182µs171µs if ( $tmpl =~ m/^(.*)%TEXT%(.*)$/s ) {
# spent 71µs making 1 call to Foswiki::UI::View::CORE:match
285127µs my @starts = split( /%STARTTEXT%/, $1 );
28614µs if ( $#starts > 0 ) {
287
288 # we know that there is something before %STARTTEXT%
289 $start = $starts[0];
290 $text = $starts[1] . $text;
291 }
292 else {
293110µs $start = $1;
294 }
295121µs my @ends = split( /%ENDTEXT%/, $2 );
29614µs if ( $#ends > 0 ) {
297
298 # we know that there is something after %ENDTEXT%
299 $text .= $ends[0];
300 $end = $ends[1];
301 }
302 else {
30319µs $end = $2;
304 }
305 }
306 else {
307 my @starts = split( /%STARTTEXT%/, $tmpl );
308 if ( $#starts > 0 ) {
309
310 # we know that there is something before %STARTTEXT%
311 $start = $starts[0];
312 $text = $starts[1];
313 }
314 else {
315 $start = $tmpl;
316 $text = '';
317 }
318 $end = '';
319 }
320
321 # If minimalist is set, images and anchors will be stripped from text
32213µs my $minimalist = 0;
323137µs4867µs if ($contentType) {
# spent 861µs making 2 calls to Foswiki::getSkin, avg 430µs/call # spent 6µs making 2 calls to Foswiki::UI::View::CORE:match, avg 3µs/call
324 $minimalist = ( $session->getSkin() =~ /\brss/ );
325 }
326 elsif ( $session->getSkin() =~ /\brss/ ) {
327 $contentType = 'text/xml';
328 $minimalist = 1;
329 }
330 elsif ( $session->getSkin() =~ /\bxml/ ) {
331 $contentType = 'text/xml';
332 $minimalist = 1;
333 }
334 elsif ( $raw eq 'text' || $raw eq 'all' ) {
335 $contentType = 'text/plain';
336 }
337 else {
33814µs $contentType = 'text/html';
339 }
340111µs1254µs $session->{prefs}->setSessionPreferences(
# spent 254µs making 1 call to Foswiki::Prefs::setSessionPreferences
341 MAXREV => $maxRev,
342 CURRREV => $showRev
343 );
344
345 # Set page generation mode to RSS if using an RSS skin
346112µs2322µs $session->enterContext('rss') if $session->getSkin() =~ /\brss/;
# spent 320µs making 1 call to Foswiki::getSkin # spent 2µs making 1 call to Foswiki::UI::View::CORE:match
347
34812µs my $page;
349
350 # Legacy: If the _only_ skin is 'text' it is used like this:
351 # http://.../view/Codev/MyTopic?skin=text&contenttype=text/plain&raw=on
352 # which shows the topic as plain text; useful for those who want
353 # to download plain text for the topic. So when the skin is 'text'
354 # we do _not_ want to create a textarea.
355 # raw=on&skin=text is deprecated; use raw=text instead.
356113µs111µs Monitor::MARK('Ready to render');
35714µs if ( $raw eq 'text'
358 || $raw eq 'all'
359 || ( $raw && $session->getSkin() eq 'text' ) )
360 {
361
362 # use raw text
363 $page = $text;
364 }
365 else {
36614µs my @args = ( $topicObject, $minimalist );
367
368112µs122µs $session->enterContext('header_text');
# spent 22µs making 1 call to Foswiki::enterContext
369110µs193.4s $page = _prepare( $start, @args );
# spent 93.4s making 1 call to Foswiki::UI::View::_prepare
370112µs122µs $session->leaveContext('header_text');
# spent 22µs making 1 call to Foswiki::leaveContext
371111µs110µs Monitor::MARK('Rendered header');
372
37313µs if ($raw) {
374 if ($text) {
375 my $p = $session->{prefs};
376 $page .= CGI::textarea(
377 -readonly => 'readonly',
378 -rows => $p->getPreference('EDITBOXHEIGHT'),
379 -cols => $p->getPreference('EDITBOXWIDTH'),
380 -style => $p->getPreference('EDITBOXSTYLE'),
381 -class => 'foswikiTextarea foswikiTextareaRawView',
382 -id => 'topic',
383 -default => $text
384 );
385 }
386 }
387 else {
38818µs114µs $session->enterContext('body_text');
# spent 14µs making 1 call to Foswiki::enterContext
389137µs1475ms $page .= _prepare( $text, @args );
# spent 475ms making 1 call to Foswiki::UI::View::_prepare
390113µs121µs $session->leaveContext('body_text');
# spent 21µs making 1 call to Foswiki::leaveContext
391 }
392
393112µs110µs Monitor::MARK('Rendered body');
39418µs113µs $session->enterContext('footer_text');
# spent 13µs making 1 call to Foswiki::enterContext
395137µs188.9s $page .= _prepare( $end, @args );
# spent 88.9s making 1 call to Foswiki::UI::View::_prepare
396113µs126µs $session->leaveContext('footer_text');
# spent 26µs making 1 call to Foswiki::leaveContext
397114µs110µs Monitor::MARK('Rendered footer');
398 }
399
400 # Output has to be done in one go, because if we generate the header and
401 # then redirect because of some later constraint, some browsers fall over
402115µs170.7ms $session->writeCompletePage( $page, 'view', $contentType );
# spent 70.7ms making 1 call to Foswiki::writeCompletePage
403151µs15µs Monitor::MARK('Wrote HTML');
404}
405
406
# spent 183s (369µs+183) within Foswiki::UI::View::_prepare which was called 3 times, avg 60.9s/call: # once (109µs+93.4s) by Foswiki::UI::View::view at line 369 # once (188µs+88.9s) by Foswiki::UI::View::view at line 395 # once (73µs+475ms) by Foswiki::UI::View::view at line 389
sub _prepare {
407314µs my ( $text, $topicObject, $minimalist ) = @_;
408
409353µs3183s $text = $topicObject->expandMacros($text);
# spent 183s making 3 calls to Foswiki::Meta::expandMacros, avg 60.9s/call
410346µs3168ms $text = $topicObject->renderTML($text);
# spent 168ms making 3 calls to Foswiki::Meta::renderTML, avg 55.9ms/call
41132.11ms551.93ms $text =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois;
# spent 1.50ms making 52 calls to Foswiki::UI::View::CORE:substcont, avg 29µs/call # spent 429µs making 3 calls to Foswiki::UI::View::CORE:subst, avg 143µs/call
412
41334µs if ($minimalist) {
414 $text =~ s/<img [^>]*>//gi; # remove image tags
415 $text =~ s/<a [^>]*>//gi; # remove anchor tags
416 $text =~ s/<\/a>//gi; # remove anchor tags
417 }
418
419367µs return $text;
420}
421
422=begin TML
423
424---++ StaticMethod revisionsAround($session, $topicObject, $requestedRev, $showRev, $maxRev) -> $output
425
426Calculate the revisions spanning the current one for display in the bottom
427bar.
428
429=cut
430
431
# spent 313ms (117µs+313) within Foswiki::UI::View::revisionsAround which was called: # once (117µs+313ms) by Foswiki::UI::View::view at line 249
sub revisionsAround {
43216µs my ( $session, $topicObject, $requestedRev, $showRev, $maxRev ) = @_;
433
43415µs my $revsToShow = $Foswiki::cfg{NumberOfRevisions} + 1;
435
436 # Soak up the revision iterator
437110µs1312ms my $revIt = $topicObject->getRevisionHistory();
# spent 312ms making 1 call to Foswiki::Meta::getRevisionHistory
438125µs181µs my @revs = $revIt->all();
# spent 81µs making 1 call to Foswiki::Iterator::all
43912µs my $maxRevDisjoint = 0;
440
44114µs if ( $Foswiki::cfg{NumberOfRevisions} ) {
442
443 # Locate the preferred rev in the array
44412µs my $showIndex = $#revs;
44511µs my $left = 0;
44614µs my $right = $Foswiki::cfg{NumberOfRevisions};
44712µs if ($requestedRev) {
448 while ( $showIndex && $revs[$showIndex] != $showRev ) {
449 $showIndex--;
450 }
451 $right = $showIndex + $Foswiki::cfg{NumberOfRevisions} - 1;
452 $right = scalar(@revs) if $right > scalar(@revs);
453 $left = $right - $Foswiki::cfg{NumberOfRevisions};
454 if ( $left < 0 ) {
455 $left = 0;
456 $right = $Foswiki::cfg{NumberOfRevisions};
457 }
458 }
45912µs splice( @revs, $right ) if ( $right < scalar(@revs) );
46012µs splice( @revs, 0, $left );
46112µs if ( $left > 0 ) {
462
463 # Put the max rev back in at the front, and flag
464 # special treatment
465 $maxRevDisjoint = 1;
466 unshift( @revs, $maxRev );
467 }
468 }
469
47012µs my $output = '';
47111µs my $r = 0;
47213µs while ( $r < scalar(@revs) ) {
47313µs if ( $revs[$r] == $showRev ) {
47413µs $output .= 'r' . $showRev;
475 }
476 else {
477 $output .= CGI::a(
478 {
479 href => $session->getScriptUrl(
480 0, 'view',
481 $topicObject->web, $topicObject->topic,
482 rev => $revs[$r]
483 ),
484 rel => 'nofollow'
485 },
486 'r' . $revs[$r]
487 );
488 }
48912µs if ( $r == 0 && $maxRevDisjoint ) {
490 $output .= ' | ';
491 }
492 elsif ( $r < $#revs ) {
493 $output .= '&nbsp;'
494 . CGI::a(
495 {
496 href => $session->getScriptUrl(
497 0, 'rdiff', $topicObject->web, $topicObject->topic,
498 rev1 => $revs[ $r + 1 ],
499 rev2 => $revs[$r]
500 ),
501 rel => 'nofollow'
502 },
503 '&lt;'
504 ) . '&nbsp;';
505 }
50613µs $r++;
507 }
508126µs return $output;
509}
510
51115µs1;
512__END__
 
# spent 91µs within Foswiki::UI::View::CORE:match which was called 6 times, avg 15µs/call: # 2 times (6µs+0s) by Foswiki::UI::View::view at line 323, avg 3µs/call # once (71µs+0s) by Foswiki::UI::View::view at line 284 # once (9µs+0s) by Foswiki::UI::View::view at line 263 # once (4µs+0s) by Foswiki::UI::View::view at line 225 # once (2µs+0s) by Foswiki::UI::View::view at line 346
sub Foswiki::UI::View::CORE:match; # opcode
# spent 526µs within Foswiki::UI::View::CORE:subst which was called 7 times, avg 75µs/call: # 3 times (429µs+0s) by Foswiki::UI::View::_prepare at line 411, avg 143µs/call # once (44µs+0s) by Foswiki::UI::View::view at line 244 # once (19µs+0s) by Foswiki::UI::View::view at line 234 # once (18µs+0s) by Foswiki::UI::View::view at line 235 # once (15µs+0s) by Foswiki::UI::View::view at line 248
sub Foswiki::UI::View::CORE:subst; # opcode
# spent 1.54ms within Foswiki::UI::View::CORE:substcont which was called 54 times, avg 29µs/call: # 52 times (1.50ms+0s) by Foswiki::UI::View::_prepare at line 411, avg 29µs/call # 2 times (43µs+0s) by Foswiki::UI::View::view at line 248, avg 21µs/call
sub Foswiki::UI::View::CORE:substcont; # opcode