Filename | /var/www/foswiki11/lib/Foswiki/UI/View.pm |
Statements | Executed 154 statements in 4.09ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 3 | 1 | 1.28ms | 59.2s | _prepare | Foswiki::UI::View::
1 | 1 | 1 | 660µs | 59.6s | view | Foswiki::UI::View::
1 | 1 | 1 | 204µs | 177ms | revisionsAround | Foswiki::UI::View::
1 | 1 | 1 | 172µs | 175µs | BEGIN@15 | Foswiki::UI::View::
1 | 1 | 1 | 13µs | 26µs | BEGIN@13 | Foswiki::UI::View::
1 | 1 | 1 | 9µs | 14µs | BEGIN@14 | Foswiki::UI::View::
1 | 1 | 1 | 8µs | 21µs | BEGIN@17 | Foswiki::UI::View::
1 | 1 | 1 | 4µs | 4µs | BEGIN@16 | Foswiki::UI::View::
1 | 1 | 1 | 3µs | 3µs | BEGIN@19 | Foswiki::UI::View::
1 | 1 | 1 | 3µs | 3µs | BEGIN@21 | Foswiki::UI::View::
1 | 1 | 1 | 3µs | 3µs | BEGIN@20 | Foswiki::UI::View::
1 | 1 | 1 | 3µs | 3µs | BEGIN@22 | Foswiki::UI::View::
1 | 1 | 1 | 3µs | 3µs | BEGIN@23 | Foswiki::UI::View::
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 | |||||
7 | UI delegate for view function | ||||
8 | |||||
9 | =cut | ||||
10 | |||||
11 | package Foswiki::UI::View; | ||||
12 | |||||
13 | 2 | 29µs | 2 | 40µs | # spent 26µs (13+14) within Foswiki::UI::View::BEGIN@13 which was called:
# once (13µs+14µs) by Foswiki::UI::BEGIN@2 at line 13 # spent 26µs making 1 call to Foswiki::UI::View::BEGIN@13
# spent 14µs making 1 call to strict::import |
14 | 2 | 24µs | 2 | 20µs | # spent 14µs (9+5) within Foswiki::UI::View::BEGIN@14 which was called:
# once (9µs+5µs) by Foswiki::UI::BEGIN@2 at line 14 # spent 14µs making 1 call to Foswiki::UI::View::BEGIN@14
# spent 5µs making 1 call to warnings::import |
15 | 2 | 186µs | 2 | 177µs | # spent 175µs (172+2) within Foswiki::UI::View::BEGIN@15 which was called:
# once (172µs+2µs) by Foswiki::UI::BEGIN@2 at line 15 # spent 175µs making 1 call to Foswiki::UI::View::BEGIN@15
# spent 2µs making 1 call to integer::import |
16 | 2 | 21µs | 1 | 4µs | # spent 4µs within Foswiki::UI::View::BEGIN@16 which was called:
# once (4µs+0s) by Foswiki::UI::BEGIN@2 at line 16 # spent 4µs making 1 call to Foswiki::UI::View::BEGIN@16 |
17 | 2 | 23µs | 2 | 34µs | # spent 21µs (8+13) within Foswiki::UI::View::BEGIN@17 which was called:
# once (8µs+13µs) by Foswiki::UI::BEGIN@2 at line 17 # spent 21µs making 1 call to Foswiki::UI::View::BEGIN@17
# spent 13µs making 1 call to Assert::import |
18 | |||||
19 | 2 | 18µs | 1 | 3µs | # spent 3µs within Foswiki::UI::View::BEGIN@19 which was called:
# once (3µs+0s) by Foswiki::UI::BEGIN@2 at line 19 # spent 3µs making 1 call to Foswiki::UI::View::BEGIN@19 |
20 | 2 | 19µs | 1 | 3µs | # spent 3µs within Foswiki::UI::View::BEGIN@20 which was called:
# once (3µs+0s) by Foswiki::UI::BEGIN@2 at line 20 # spent 3µs making 1 call to Foswiki::UI::View::BEGIN@20 |
21 | 2 | 17µs | 1 | 3µs | # spent 3µs within Foswiki::UI::View::BEGIN@21 which was called:
# once (3µs+0s) by Foswiki::UI::BEGIN@2 at line 21 # spent 3µs making 1 call to Foswiki::UI::View::BEGIN@21 |
22 | 2 | 16µs | 1 | 3µs | # spent 3µs within Foswiki::UI::View::BEGIN@22 which was called:
# once (3µs+0s) by Foswiki::UI::BEGIN@2 at line 22 # spent 3µs making 1 call to Foswiki::UI::View::BEGIN@22 |
23 | 2 | 1.72ms | 1 | 3µs | # spent 3µs within Foswiki::UI::View::BEGIN@23 which was called:
# once (3µs+0s) by Foswiki::UI::BEGIN@2 at line 23 # spent 3µs making 1 call to Foswiki::UI::View::BEGIN@23 |
24 | |||||
25 | =begin TML | ||||
26 | |||||
27 | ---++ StaticMethod view( $session ) | ||||
28 | |||||
29 | =view= command handler. | ||||
30 | This method is designed to be | ||||
31 | invoked via the =UI::run= method. | ||||
32 | |||||
33 | Generate a complete HTML page that represents the viewed topics. | ||||
34 | The 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 59.6s (660µs+59.6) within Foswiki::UI::View::view which was called:
# once (660µs+59.6s) by Foswiki::UI::__ANON__[/var/www/foswiki11/lib/Foswiki/UI.pm:318] at line 316 of /var/www/foswiki11/lib/Foswiki/UI.pm | ||||
45 | 1 | 600ns | my $session = shift; | ||
46 | |||||
47 | 1 | 900ns | my $query = $session->{request}; | ||
48 | 1 | 900ns | my $web = $session->{webName}; | ||
49 | 1 | 700ns | my $topic = $session->{topicName}; | ||
50 | |||||
51 | 1 | 700ns | my $cache = $session->{cache}; | ||
52 | 1 | 200ns | my $cachedPage; | ||
53 | 1 | 300ns | $cachedPage = $cache->getPage( $web, $topic ) if $cache; | ||
54 | 1 | 500ns | 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 | |||||
87 | 1 | 1µs | print STDERR "computing page for $web.$topic\n" | ||
88 | if $Foswiki::cfg{Cache}{Debug}; | ||||
89 | |||||
90 | 1 | 4µs | 1 | 23µs | my $raw = $query->param('raw') || ''; # spent 23µs making 1 call to Foswiki::Request::param |
91 | 1 | 3µs | 1 | 16µs | my $contentType = $query->param('contenttype'); # spent 16µs making 1 call to Foswiki::Request::param |
92 | |||||
93 | 1 | 800ns | my $logEntry = ''; | ||
94 | |||||
95 | # is this view indexable by search engines? Default yes. | ||||
96 | 1 | 400ns | my $indexableView = 1; | ||
97 | 1 | 400ns | my $viewTemplate; | ||
98 | |||||
99 | 1 | 5µs | 1 | 90µs | Foswiki::UI::checkWebExists( $session, $web, 'view' ); # spent 90µs making 1 call to Foswiki::UI::checkWebExists |
100 | |||||
101 | 1 | 200ns | my $requestedRev; | ||
102 | 1 | 2µs | 1 | 18µs | if ( defined $query->param('rev') ) { # spent 18µs making 1 call to Foswiki::Request::param |
103 | $requestedRev = Foswiki::Store::cleanUpRevID( $query->param('rev') ); | ||||
104 | unless ($requestedRev) { | ||||
105 | |||||
106 | # Invalid request, remove it from the query. | ||||
107 | $requestedRev = undef; | ||||
108 | $query->delete('rev'); | ||||
109 | } | ||||
110 | } | ||||
111 | |||||
112 | 1 | 1µs | my $showLatest = !$requestedRev; | ||
113 | 1 | 200ns | my $showRev; | ||
114 | |||||
115 | 1 | 100ns | my $topicObject; # the stub of the topic we are to display | ||
116 | 1 | 200ns | my $text; # the text to display, *not* necessarily | ||
117 | # the same as $topicObject->text | ||||
118 | 1 | 200ns | my $revIt; # Iterator over the range of available revs | ||
119 | 1 | 300ns | my $maxRev; | ||
120 | |||||
121 | 1 | 3µs | 1 | 51µs | if ( $session->topicExists( $web, $topic ) ) { # spent 51µs making 1 call to Foswiki::topicExists |
122 | |||||
123 | # Load the most recent rev. This *should* be maxRev, but may | ||||
124 | # not say it is because the TOPICINFO could be up the spout | ||||
125 | 1 | 4µs | 1 | 411µs | $topicObject = Foswiki::Meta->load( $session, $web, $topic ); # spent 411µs making 1 call to Foswiki::Meta::load |
126 | 1 | 5µs | 1 | 946µs | Foswiki::UI::checkAccess( $session, 'VIEW', $topicObject ); # spent 946µs making 1 call to Foswiki::UI::checkAccess |
127 | |||||
128 | 1 | 7µs | 1 | 220ms | $revIt = $topicObject->getRevisionHistory(); # spent 220ms making 1 call to Foswiki::Meta::getRevisionHistory |
129 | |||||
130 | # The topic exists; it must have at least one rev | ||||
131 | 1 | 6µs | 1 | 6µs | ASSERT( $revIt->hasNext() ) if DEBUG; # spent 6µs making 1 call to Assert::ASSERTS_OFF |
132 | 1 | 3µs | 1 | 4µs | $maxRev = $revIt->next(); # spent 4µs making 1 call to Foswiki::Iterator::NumberRangeIterator::next |
133 | |||||
134 | 1 | 1µs | if ( defined $requestedRev ) { | ||
135 | |||||
136 | # Is the requested rev id known? | ||||
137 | $revIt->reset(); | ||||
138 | while ( $revIt->hasNext() ) { | ||||
139 | if ( $requestedRev eq $revIt->next() ) { | ||||
140 | $showRev = $requestedRev; | ||||
141 | last; | ||||
142 | } | ||||
143 | } | ||||
144 | |||||
145 | # if rev was not found; show max rev | ||||
146 | $showRev = $maxRev unless ( defined $showRev ); | ||||
147 | |||||
148 | if ( $showRev ne $maxRev ) { | ||||
149 | |||||
150 | # Load the old revision instead | ||||
151 | $topicObject = | ||||
152 | Foswiki::Meta->load( $session, $web, $topic, $showRev ); | ||||
153 | if ( !$topicObject->haveAccess('VIEW') ) { | ||||
154 | throw Foswiki::AccessControlException( 'VIEW', | ||||
155 | $session->{user}, $web, $topic, | ||||
156 | $Foswiki::Meta::reason ); | ||||
157 | } | ||||
158 | $logEntry .= 'r' . $requestedRev; | ||||
159 | } | ||||
160 | } | ||||
161 | else { | ||||
162 | 1 | 500ns | $showRev = $maxRev; | ||
163 | } | ||||
164 | |||||
165 | 1 | 9µs | 1 | 49µs | if ( my $section = $query->param('section') ) { # spent 49µs making 1 call to Foswiki::Request::param |
166 | |||||
167 | # Apply the 'section' selection (and maybe others in the | ||||
168 | # future as well). $text is cleared unless a named section | ||||
169 | # matching the 'section' URL parameter is found. | ||||
170 | my ( $ntext, $sections ) = | ||||
171 | Foswiki::parseSections( $topicObject->text() ); | ||||
172 | $text = ''; # in the beginning, there was ... NO section | ||||
173 | FINDSECTION: | ||||
174 | for my $s (@$sections) { | ||||
175 | if ( $s->{type} eq 'section' && $s->{name} eq $section ) { | ||||
176 | $text = | ||||
177 | substr( $ntext, $s->{start}, $s->{end} - $s->{start} ); | ||||
178 | last FINDSECTION; | ||||
179 | } | ||||
180 | } | ||||
181 | } | ||||
182 | else { | ||||
183 | |||||
184 | # Otherwise take the full topic text | ||||
185 | 1 | 6µs | 1 | 14µs | $text = $topicObject->text(); # spent 14µs making 1 call to Foswiki::Meta::text |
186 | } | ||||
187 | } | ||||
188 | else { # Topic does not exist yet | ||||
189 | $topicObject = Foswiki::Meta->new( $session, $web, $topic ); | ||||
190 | $indexableView = 0; | ||||
191 | $session->enterContext('new_topic'); | ||||
192 | $session->{response}->status(404); | ||||
193 | $showRev = 1; | ||||
194 | $maxRev = 0; | ||||
195 | $viewTemplate = 'TopicDoesNotExistView'; | ||||
196 | $logEntry .= ' (not exist)'; | ||||
197 | $raw = ''; # There is no raw view of a topic that doesn't exist | ||||
198 | $revIt = new Foswiki::ListIterator( [1] ); | ||||
199 | } | ||||
200 | |||||
201 | 1 | 400ns | if ($raw) { | ||
202 | $indexableView = 0; | ||||
203 | $logEntry .= ' raw=' . $raw; | ||||
204 | if ( $raw eq 'debug' || $raw eq 'all' ) { | ||||
205 | |||||
206 | # We want to see the embedded store form | ||||
207 | $text = $topicObject->getEmbeddedStoreForm(); | ||||
208 | } | ||||
209 | } | ||||
210 | |||||
211 | 1 | 400ns | $text = '' unless defined $text; | ||
212 | |||||
213 | 1 | 16µs | 3 | 460µs | $session->logEvent( 'view', $topicObject->web . '.' . $topicObject->topic, # spent 450µs making 1 call to Foswiki::logEvent
# spent 7µs making 1 call to Foswiki::Meta::web
# spent 4µs making 1 call to Foswiki::Meta::topic |
214 | $logEntry ); | ||||
215 | |||||
216 | # Note; must enter all contexts before the template is read, as | ||||
217 | # TMPL:P is expanded on the fly in the template reader. :-( | ||||
218 | 1 | 2µs | my ( $revTitle, $revArg ) = ( '', '' ); | ||
219 | 1 | 3µs | 1 | 3µs | $revIt->reset(); # spent 3µs making 1 call to Foswiki::Iterator::NumberRangeIterator::reset |
220 | 1 | 3µs | 1 | 3µs | if ( $showRev && $showRev != $revIt->next() ) { # spent 3µs making 1 call to Foswiki::Iterator::NumberRangeIterator::next |
221 | $session->enterContext('inactive'); | ||||
222 | |||||
223 | # disable edit of previous revisions | ||||
224 | $revTitle = '(r' . $showRev . ')'; | ||||
225 | $revArg = '&rev=' . $showRev; | ||||
226 | } | ||||
227 | |||||
228 | 1 | 11µs | 2 | 68µs | my $template = # spent 49µs making 1 call to Foswiki::Prefs::getPreference
# spent 19µs making 1 call to Foswiki::Request::param |
229 | $viewTemplate | ||||
230 | || $query->param('template') | ||||
231 | || $session->{prefs}->getPreference('VIEW_TEMPLATE') | ||||
232 | || 'view'; | ||||
233 | |||||
234 | # Always use default view template for raw=debug, raw=all and raw=on | ||||
235 | 1 | 1µs | if ( $raw =~ /^(debug|all|on)$/ ) { | ||
236 | $template = 'view'; | ||||
237 | } | ||||
238 | |||||
239 | 1 | 5µs | 2 | 21.2ms | my $tmpl = $session->templates->readTemplate( $template, no_oops => 1 ); # spent 18.6ms making 1 call to Foswiki::Templates::readTemplate
# spent 2.66ms making 1 call to Foswiki::templates |
240 | |||||
241 | # If the VIEW_TEMPLATE (or other) doesn't exist, default to view. | ||||
242 | 1 | 200ns | $tmpl = $session->templates->readTemplate('view') unless defined($tmpl); | ||
243 | |||||
244 | 1 | 10µs | $tmpl =~ s/%REVTITLE%/$revTitle/g; | ||
245 | 1 | 8µs | $tmpl =~ s/%REVARG%/$revArg/g; | ||
246 | |||||
247 | 1 | 4µs | 1 | 16µs | if ( $indexableView # spent 16µs making 1 call to Foswiki::Request::param |
248 | && $Foswiki::cfg{AntiSpam}{RobotsAreWelcome} | ||||
249 | && !$query->param() ) | ||||
250 | { | ||||
251 | |||||
252 | # it's an indexable view type, there are no parameters | ||||
253 | # on the url, and robots are welcome. Remove the NOINDEX meta tag | ||||
254 | $tmpl =~ s/<meta name="robots"[^>]*>//goi; | ||||
255 | } | ||||
256 | |||||
257 | # Show revisions around the one being displayed. | ||||
258 | 1 | 39µs | 1 | 177ms | $tmpl =~ s/%REVISIONS%/ # spent 177ms making 1 call to Foswiki::UI::View::revisionsAround |
259 | revisionsAround( | ||||
260 | $session, $topicObject, $requestedRev, $showRev, $maxRev)/e; | ||||
261 | |||||
262 | ## SMELL: This is also used in Foswiki::_TOC. Could insert a tag in | ||||
263 | ## TOC and remove all those here, finding the parameters only once | ||||
264 | 1 | 2µs | my @qparams = (); | ||
265 | 1 | 28µs | 1 | 74µs | foreach my $name ( $query->param ) { # spent 74µs making 1 call to Foswiki::Request::param |
266 | 2 | 900ns | next if ( $name eq 'keywords' ); | ||
267 | 2 | 2µs | next if ( $name eq 'topic' ); | ||
268 | 1 | 7µs | 1 | 49µs | push @qparams, $name => $query->param($name); # spent 49µs making 1 call to Foswiki::Request::param |
269 | } | ||||
270 | 1 | 12µs | $tmpl =~ s/%QUERYPARAMSTRING%/Foswiki::_make_params(1,@qparams)/geo; | ||
271 | |||||
272 | # extract header and footer from the template, if there is a | ||||
273 | # %TEXT% tag marking the split point. The topic text is inserted | ||||
274 | # in place of the %TEXT% tag. The text before this tag is inserted | ||||
275 | # as header, the text after is inserted as footer. If there is a | ||||
276 | # %STARTTEXT% tag present, the header text between %STARTTEXT% and | ||||
277 | # %TEXT is rendered together, as is the footer text between %TEXT% | ||||
278 | # and %ENDTEXT%, if present. This allows correct handling of Foswiki | ||||
279 | # markup in header or footer if those do require examination of the | ||||
280 | # topic text to work correctly (e.g., %TOC%). | ||||
281 | # Note: This feature is experimental and may be replaced by an | ||||
282 | # alternative solution not requiring additional tags. | ||||
283 | 1 | 3µs | my ( $start, $end ); | ||
284 | |||||
285 | # SMELL: unchecked implicit untaint of data that *may* be coming from | ||||
286 | # a topic (topics can be templates) | ||||
287 | 1 | 83µs | if ( $tmpl =~ m/^(.*)%TEXT%(.*)$/s ) { | ||
288 | 1 | 28µs | my @starts = split( /%STARTTEXT%/, $1 ); | ||
289 | 1 | 2µs | if ( $#starts > 0 ) { | ||
290 | |||||
291 | # we know that there is something before %STARTTEXT% | ||||
292 | $start = $starts[0]; | ||||
293 | $text = $starts[1] . $text; | ||||
294 | } | ||||
295 | else { | ||||
296 | 1 | 8µs | $start = $1; | ||
297 | } | ||||
298 | 1 | 29µs | my @ends = split( /%ENDTEXT%/, $2 ); | ||
299 | 1 | 3µs | if ( $#ends > 0 ) { | ||
300 | |||||
301 | # we know that there is something after %ENDTEXT% | ||||
302 | $text .= $ends[0]; | ||||
303 | $end = $ends[1]; | ||||
304 | } | ||||
305 | else { | ||||
306 | 1 | 7µs | $end = $2; | ||
307 | } | ||||
308 | } | ||||
309 | else { | ||||
310 | my @starts = split( /%STARTTEXT%/, $tmpl ); | ||||
311 | if ( $#starts > 0 ) { | ||||
312 | |||||
313 | # we know that there is something before %STARTTEXT% | ||||
314 | $start = $starts[0]; | ||||
315 | $text = $starts[1]; | ||||
316 | } | ||||
317 | else { | ||||
318 | $start = $tmpl; | ||||
319 | $text = ''; | ||||
320 | } | ||||
321 | $end = ''; | ||||
322 | } | ||||
323 | |||||
324 | # If minimalist is set, images and anchors will be stripped from text | ||||
325 | 1 | 2µs | my $minimalist = 0; | ||
326 | 1 | 18µs | 2 | 352µs | if ($contentType) { # spent 352µs making 2 calls to Foswiki::getSkin, avg 176µs/call |
327 | $minimalist = ( $session->getSkin() =~ /\brss/ ); | ||||
328 | } | ||||
329 | elsif ( $session->getSkin() =~ /\brss/ ) { | ||||
330 | $contentType = 'text/xml'; | ||||
331 | $minimalist = 1; | ||||
332 | } | ||||
333 | elsif ( $session->getSkin() =~ /\bxml/ ) { | ||||
334 | $contentType = 'text/xml'; | ||||
335 | $minimalist = 1; | ||||
336 | } | ||||
337 | elsif ( $raw eq 'text' || $raw eq 'all' ) { | ||||
338 | $contentType = 'text/plain'; | ||||
339 | } | ||||
340 | else { | ||||
341 | 1 | 4µs | $contentType = 'text/html'; | ||
342 | } | ||||
343 | 1 | 7µs | 1 | 176µs | $session->{prefs}->setSessionPreferences( # spent 176µs making 1 call to Foswiki::Prefs::setSessionPreferences |
344 | MAXREV => $maxRev, | ||||
345 | CURRREV => $showRev | ||||
346 | ); | ||||
347 | |||||
348 | # Set page generation mode to RSS if using an RSS skin | ||||
349 | 1 | 5µs | 1 | 139µs | $session->enterContext('rss') if $session->getSkin() =~ /\brss/; # spent 139µs making 1 call to Foswiki::getSkin |
350 | |||||
351 | 1 | 500ns | my $page; | ||
352 | |||||
353 | # Legacy: If the _only_ skin is 'text' it is used like this: | ||||
354 | # http://.../view/Codev/MyTopic?skin=text&contenttype=text/plain&raw=on | ||||
355 | # which shows the topic as plain text; useful for those who want | ||||
356 | # to download plain text for the topic. So when the skin is 'text' | ||||
357 | # we do _not_ want to create a textarea. | ||||
358 | # raw=on&skin=text is deprecated; use raw=text instead. | ||||
359 | 1 | 9µs | 1 | 8µs | Monitor::MARK('Ready to render'); # spent 8µs making 1 call to Monitor::__ANON__[/var/www/foswiki11/lib/Monitor.pm:101] |
360 | 1 | 2µs | if ( $raw eq 'text' | ||
361 | || $raw eq 'all' | ||||
362 | || ( $raw && $session->getSkin() eq 'text' ) ) | ||||
363 | { | ||||
364 | |||||
365 | # use raw text | ||||
366 | $page = $text; | ||||
367 | } | ||||
368 | else { | ||||
369 | 1 | 2µs | my @args = ( $topicObject, $minimalist ); | ||
370 | |||||
371 | 1 | 6µs | 1 | 12µs | $session->enterContext('header_text'); # spent 12µs making 1 call to Foswiki::enterContext |
372 | 1 | 4µs | 1 | 148ms | $page = _prepare( $start, @args ); # spent 148ms making 1 call to Foswiki::UI::View::_prepare |
373 | 1 | 3µs | 1 | 6µs | $session->leaveContext('header_text'); # spent 6µs making 1 call to Foswiki::leaveContext |
374 | 1 | 3µs | 1 | 2µs | Monitor::MARK('Rendered header'); # spent 2µs making 1 call to Monitor::__ANON__[/var/www/foswiki11/lib/Monitor.pm:101] |
375 | |||||
376 | 1 | 800ns | if ($raw) { | ||
377 | if ($text) { | ||||
378 | my $p = $session->{prefs}; | ||||
379 | $page .= CGI::textarea( | ||||
380 | -readonly => 'readonly', | ||||
381 | -rows => $p->getPreference('EDITBOXHEIGHT'), | ||||
382 | -cols => $p->getPreference('EDITBOXWIDTH'), | ||||
383 | -style => $p->getPreference('EDITBOXSTYLE'), | ||||
384 | -class => 'foswikiTextarea foswikiTextareaRawView', | ||||
385 | -id => 'topic', | ||||
386 | -default => $text | ||||
387 | ); | ||||
388 | } | ||||
389 | } | ||||
390 | else { | ||||
391 | 1 | 2µs | 1 | 4µs | $session->enterContext('body_text'); # spent 4µs making 1 call to Foswiki::enterContext |
392 | 1 | 15µs | 1 | 49.7s | $page .= _prepare( $text, @args ); # spent 49.7s making 1 call to Foswiki::UI::View::_prepare |
393 | 1 | 5µs | 1 | 9µs | $session->leaveContext('body_text'); # spent 9µs making 1 call to Foswiki::leaveContext |
394 | } | ||||
395 | |||||
396 | 1 | 5µs | 1 | 4µs | Monitor::MARK('Rendered body'); # spent 4µs making 1 call to Monitor::__ANON__[/var/www/foswiki11/lib/Monitor.pm:101] |
397 | 1 | 3µs | 1 | 4µs | $session->enterContext('footer_text'); # spent 4µs making 1 call to Foswiki::enterContext |
398 | 1 | 24µs | 1 | 9.36s | $page .= _prepare( $end, @args ); # spent 9.36s making 1 call to Foswiki::UI::View::_prepare |
399 | 1 | 6µs | 1 | 12µs | $session->leaveContext('footer_text'); # spent 12µs making 1 call to Foswiki::leaveContext |
400 | 1 | 9µs | 1 | 6µs | Monitor::MARK('Rendered footer'); # spent 6µs making 1 call to Monitor::__ANON__[/var/www/foswiki11/lib/Monitor.pm:101] |
401 | } | ||||
402 | |||||
403 | # Output has to be done in one go, because if we generate the header and | ||||
404 | # then redirect because of some later constraint, some browsers fall over | ||||
405 | 1 | 8µs | 1 | 27.8ms | $session->writeCompletePage( $page, 'view', $contentType ); # spent 27.8ms making 1 call to Foswiki::writeCompletePage |
406 | 1 | 28µs | 1 | 2µs | Monitor::MARK('Wrote HTML'); # spent 2µs making 1 call to Monitor::__ANON__[/var/www/foswiki11/lib/Monitor.pm:101] |
407 | } | ||||
408 | |||||
409 | sub _prepare { | ||||
410 | 3 | 12µs | my ( $text, $topicObject, $minimalist ) = @_; | ||
411 | |||||
412 | 3 | 17µs | 3 | 59.1s | $text = $topicObject->expandMacros($text); # spent 59.1s making 3 calls to Foswiki::Meta::expandMacros, avg 19.7s/call |
413 | 3 | 15µs | 3 | 58.1ms | $text = $topicObject->renderTML($text); # spent 58.1ms making 3 calls to Foswiki::Meta::renderTML, avg 19.4ms/call |
414 | 3 | 1.22ms | $text =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois; | ||
415 | |||||
416 | 3 | 1µs | if ($minimalist) { | ||
417 | $text =~ s/<img [^>]*>//gi; # remove image tags | ||||
418 | $text =~ s/<a [^>]*>//gi; # remove anchor tags | ||||
419 | $text =~ s/<\/a>//gi; # remove anchor tags | ||||
420 | } | ||||
421 | |||||
422 | 3 | 32µs | return $text; | ||
423 | } | ||||
424 | |||||
425 | =begin TML | ||||
426 | |||||
427 | ---++ StaticMethod revisionsAround($session, $topicObject, $requestedRev, $showRev, $maxRev) -> $output | ||||
428 | |||||
429 | Calculate the revisions spanning the current one for display in the bottom | ||||
430 | bar. | ||||
431 | |||||
432 | =cut | ||||
433 | |||||
434 | # spent 177ms (204µs+176) within Foswiki::UI::View::revisionsAround which was called:
# once (204µs+176ms) by Foswiki::UI::View::view at line 258 | ||||
435 | 1 | 2µs | my ( $session, $topicObject, $requestedRev, $showRev, $maxRev ) = @_; | ||
436 | |||||
437 | 1 | 3µs | my $revsToShow = $Foswiki::cfg{NumberOfRevisions} + 1; | ||
438 | |||||
439 | # Soak up the revision iterator | ||||
440 | 1 | 3µs | 1 | 175ms | my $revIt = $topicObject->getRevisionHistory(); # spent 175ms making 1 call to Foswiki::Meta::getRevisionHistory |
441 | 1 | 14µs | 1 | 52µs | my @revs = $revIt->all(); # spent 52µs making 1 call to Foswiki::Iterator::all |
442 | 1 | 600ns | my $maxRevDisjoint = 0; | ||
443 | |||||
444 | 1 | 1µs | if ( $Foswiki::cfg{NumberOfRevisions} ) { | ||
445 | |||||
446 | # Locate the preferred rev in the array | ||||
447 | 1 | 800ns | my $showIndex = $#revs; | ||
448 | 1 | 900ns | my $left = 0; | ||
449 | 1 | 1µs | my $right = $Foswiki::cfg{NumberOfRevisions}; | ||
450 | 1 | 500ns | if ($requestedRev) { | ||
451 | while ( $showIndex && $revs[$showIndex] != $showRev ) { | ||||
452 | $showIndex--; | ||||
453 | } | ||||
454 | $right = $showIndex + $Foswiki::cfg{NumberOfRevisions} - 1; | ||||
455 | $right = scalar(@revs) if $right > scalar(@revs); | ||||
456 | $left = $right - $Foswiki::cfg{NumberOfRevisions}; | ||||
457 | if ( $left < 0 ) { | ||||
458 | $left = 0; | ||||
459 | $right = $Foswiki::cfg{NumberOfRevisions}; | ||||
460 | } | ||||
461 | } | ||||
462 | 1 | 500ns | splice( @revs, $right ) if ( $right < scalar(@revs) ); | ||
463 | 1 | 1µs | splice( @revs, 0, $left ); | ||
464 | 1 | 500ns | if ( $left > 0 ) { | ||
465 | |||||
466 | # Put the max rev back in at the front, and flag | ||||
467 | # special treatment | ||||
468 | $maxRevDisjoint = 1; | ||||
469 | unshift( @revs, $maxRev ); | ||||
470 | } | ||||
471 | } | ||||
472 | |||||
473 | 1 | 700ns | my $output = ''; | ||
474 | 1 | 200ns | my $r = 0; | ||
475 | 1 | 1µs | while ( $r < scalar(@revs) ) { | ||
476 | 3 | 9µs | if ( $revs[$r] == $showRev ) { | ||
477 | $output .= 'r' . $showRev; | ||||
478 | } | ||||
479 | else { | ||||
480 | 2 | 30µs | 8 | 342µs | $output .= CGI::a( # spent 170µs making 2 calls to CGI::a, avg 85µs/call
# spent 159µs making 2 calls to Foswiki::getScriptUrl, avg 80µs/call
# spent 7µs making 2 calls to Foswiki::Meta::web, avg 4µs/call
# spent 5µs making 2 calls to Foswiki::Meta::topic, avg 3µs/call |
481 | { | ||||
482 | href => $session->getScriptUrl( | ||||
483 | 0, 'view', | ||||
484 | $topicObject->web, $topicObject->topic, | ||||
485 | rev => $revs[$r] | ||||
486 | ), | ||||
487 | rel => 'nofollow' | ||||
488 | }, | ||||
489 | 'r' . $revs[$r] | ||||
490 | ); | ||||
491 | } | ||||
492 | 3 | 71µs | 8 | 1.08ms | if ( $r == 0 && $maxRevDisjoint ) { # spent 693µs making 1 call to CGI::AUTOLOAD
# spent 280µs making 2 calls to Foswiki::getScriptUrl, avg 140µs/call
# spent 86µs making 1 call to CGI::a
# spent 12µs making 2 calls to Foswiki::Meta::web, avg 6µs/call
# spent 7µs making 2 calls to Foswiki::Meta::topic, avg 4µs/call |
493 | $output .= ' | '; | ||||
494 | } | ||||
495 | elsif ( $r < $#revs ) { | ||||
496 | $output .= ' ' | ||||
497 | . CGI::a( | ||||
498 | { | ||||
499 | href => $session->getScriptUrl( | ||||
500 | 0, 'rdiff', $topicObject->web, $topicObject->topic, | ||||
501 | rev1 => $revs[ $r + 1 ], | ||||
502 | rev2 => $revs[$r] | ||||
503 | ), | ||||
504 | rel => 'nofollow' | ||||
505 | }, | ||||
506 | '<' | ||||
507 | ) . ' '; | ||||
508 | } | ||||
509 | 3 | 4µs | $r++; | ||
510 | } | ||||
511 | 1 | 24µs | return $output; | ||
512 | } | ||||
513 | |||||
514 | 1 | 2µs | 1; | ||
515 | __END__ |