Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/InterwikiPlugin.pm |
Statements | Executed 282 statements in 4.66ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 761µs | 60.9s | initPlugin | Foswiki::Plugins::InterwikiPlugin::
38 | 1 | 1 | 757µs | 757µs | _map | Foswiki::Plugins::InterwikiPlugin::
39 | 1 | 1 | 544µs | 544µs | CORE:substcont (opcode) | Foswiki::Plugins::InterwikiPlugin::
13 | 5 | 1 | 454µs | 454µs | CORE:subst (opcode) | Foswiki::Plugins::InterwikiPlugin::
11 | 3 | 1 | 449µs | 449µs | CORE:regcomp (opcode) | Foswiki::Plugins::InterwikiPlugin::
5 | 1 | 1 | 202µs | 1.02ms | preRenderingHandler | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 30µs | 36µs | _trimWhitespace | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 28µs | 40µs | BEGIN@23 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 17µs | 36µs | BEGIN@24 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 9µs | 9µs | BEGIN@26 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 9µs | 9µs | BEGIN@40 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 9µs | 9µs | BEGIN@27 | Foswiki::Plugins::InterwikiPlugin::
0 | 0 | 0 | 0s | 0s | _link | Foswiki::Plugins::InterwikiPlugin::
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::Plugins::InterwikiPlugin | ||||
6 | |||||
7 | Recognises and processes special links to other sites defined | ||||
8 | using "inter-site syntax". | ||||
9 | |||||
10 | The recognized syntax is: | ||||
11 | <pre> | ||||
12 | InterSiteName:TopicName | ||||
13 | </pre> | ||||
14 | |||||
15 | Sites must start with upper case and must be preceded by white | ||||
16 | space, '-', '*' or '(', or be part of the link expression | ||||
17 | in a [[link]] or [[link][text]] expression. | ||||
18 | |||||
19 | =cut | ||||
20 | |||||
21 | package Foswiki::Plugins::InterwikiPlugin; | ||||
22 | |||||
23 | 2 | 52µs | 2 | 52µs | # spent 40µs (28+12) within Foswiki::Plugins::InterwikiPlugin::BEGIN@23 which was called:
# once (28µs+12µs) by Foswiki::Plugin::BEGIN@2.9 at line 23 # spent 40µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@23
# spent 12µs making 1 call to strict::import |
24 | 2 | 44µs | 2 | 55µs | # spent 36µs (17+19) within Foswiki::Plugins::InterwikiPlugin::BEGIN@24 which was called:
# once (17µs+19µs) by Foswiki::Plugin::BEGIN@2.9 at line 24 # spent 36µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@24
# spent 19µs making 1 call to warnings::import |
25 | |||||
26 | 2 | 39µs | 1 | 9µs | # spent 9µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@26 which was called:
# once (9µs+0s) by Foswiki::Plugin::BEGIN@2.9 at line 26 # spent 9µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@26 |
27 | 2 | 161µs | 1 | 9µs | # spent 9µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@27 which was called:
# once (9µs+0s) by Foswiki::Plugin::BEGIN@2.9 at line 27 # spent 9µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@27 |
28 | |||||
29 | 1 | 2µs | our $VERSION = '$Rev$'; | ||
30 | 1 | 1µs | our $RELEASE = '1.1.2'; | ||
31 | 1 | 1µs | our $NO_PREFS_IN_TOPIC = 1; | ||
32 | 1 | 1µs | our $SHORTDESCRIPTION = | ||
33 | 'Link !ExternalSite:Page text to external sites based on aliases defined in a rules topic'; | ||||
34 | |||||
35 | 1 | 1µs | my $interLinkFormat; | ||
36 | 1 | 800ns | my $sitePattern; | ||
37 | 1 | 900ns | my $pagePattern; | ||
38 | 1 | 1µs | my %interSiteTable; | ||
39 | |||||
40 | # spent 9µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@40 which was called:
# once (9µs+0s) by Foswiki::Plugin::BEGIN@2.9 at line 47 | ||||
41 | |||||
42 | # 'Use locale' for internationalisation of Perl sorting and searching - | ||||
43 | 1 | 10µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
44 | require locale; | ||||
45 | import locale(); | ||||
46 | } | ||||
47 | 1 | 1.16ms | 1 | 9µs | } # spent 9µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@40 |
48 | |||||
49 | # Read preferences and get all InterWiki Site->URL mappings | ||||
50 | # spent 60.9s (761µs+60.9) within Foswiki::Plugins::InterwikiPlugin::initPlugin which was called:
# once (761µs+60.9s) 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 | ||||
51 | 1 | 3µs | my ( $topic, $web, $user, $installWeb ) = @_; | ||
52 | |||||
53 | # Regexes for the Site:page format InterWiki reference | ||||
54 | 1 | 3µs | my $man = $Foswiki::regex{mixedAlphaNum}; | ||
55 | 1 | 2µs | my $ua = $Foswiki::regex{upperAlpha}; | ||
56 | 1 | 2µs | %interSiteTable = (); | ||
57 | 1 | 4µs | $sitePattern = "([$ua][$man]+)"; | ||
58 | 1 | 3µs | $pagePattern = "((?:'[^']*')|(?:\"[^\"]*\")|(?:[${man}\_\~\%\/][$man" | ||
59 | . '"\'\.\/\+\_\~\,\&\;\:\=\!\?\%\#\@\-\(\)]*?))'; | ||||
60 | |||||
61 | # Get plugin preferences from InterwikiPlugin topic | ||||
62 | 1 | 7µs | 1 | 102µs | $interLinkFormat = # spent 102µs making 1 call to Foswiki::Func::getPreferencesValue |
63 | Foswiki::Func::getPreferencesValue('INTERWIKIPLUGIN_INTERLINKFORMAT') | ||||
64 | || '<a class="interwikiLink" href="$url" title="$tooltip"><noautolink>$label</noautolink></a>'; | ||||
65 | |||||
66 | 1 | 6µs | 1 | 151µs | my $rulesTopicPref = # spent 151µs making 1 call to Foswiki::Func::getPreferencesValue |
67 | Foswiki::Func::getPreferencesValue('INTERWIKIPLUGIN_RULESTOPIC') | ||||
68 | || 'InterWikis'; | ||||
69 | 1 | 4µs | my @rulesTopics = split( ',', $rulesTopicPref ); | ||
70 | 1 | 4µs | foreach my $topic (@rulesTopics) { | ||
71 | 1 | 6µs | 1 | 36µs | $topic = _trimWhitespace($topic); # spent 36µs making 1 call to Foswiki::Plugins::InterwikiPlugin::_trimWhitespace |
72 | |||||
73 | 1 | 13µs | 1 | 100µs | my ( $interWeb, $interTopic ) = # spent 100µs making 1 call to Foswiki::Func::normalizeWebTopicName |
74 | Foswiki::Func::normalizeWebTopicName( $installWeb, $topic ); | ||||
75 | |||||
76 | 1 | 12µs | 1 | 60.8s | if ( # spent 60.8s making 1 call to Foswiki::Func::checkAccessPermission |
77 | !Foswiki::Func::checkAccessPermission( | ||||
78 | 'VIEW', $user, undef, $interTopic, $interWeb | ||||
79 | ) | ||||
80 | ) | ||||
81 | { | ||||
82 | Foswiki::Func::writeWarning( | ||||
83 | "InterwikiPlugin: user '$user' did not have permission to read the rules topic at '$interWeb.$interTopic'" | ||||
84 | ); | ||||
85 | return 1; | ||||
86 | } | ||||
87 | 1 | 19µs | 1 | 5.75ms | my $text = # spent 5.75ms making 1 call to Foswiki::Func::readTopicText |
88 | Foswiki::Func::readTopicText( $interWeb, $interTopic, undef, 1 ); | ||||
89 | |||||
90 | # '| alias | URL | ...' table and extract into 'alias', "URL" list | ||||
91 | 38 | 248µs | 38 | 757µs | $text =~ # spent 757µs making 38 calls to Foswiki::Plugins::InterwikiPlugin::_map, avg 20µs/call |
92 | 1 | 909µs | 41 | 627µs | s/^\|\s*$sitePattern\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|.*$/_map($1,$2,$3)/meg; # spent 544µs making 39 calls to Foswiki::Plugins::InterwikiPlugin::CORE:substcont, avg 14µs/call
# spent 45µs making 1 call to Foswiki::Plugins::InterwikiPlugin::CORE:regcomp
# spent 38µs making 1 call to Foswiki::Plugins::InterwikiPlugin::CORE:subst |
93 | } | ||||
94 | |||||
95 | 1 | 28µs | $sitePattern = "(" . join( "|", keys %interSiteTable ) . ")"; | ||
96 | 1 | 23µs | return 1; | ||
97 | } | ||||
98 | |||||
99 | # spent 757µs within Foswiki::Plugins::InterwikiPlugin::_map which was called 38 times, avg 20µs/call:
# 38 times (757µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 91, avg 20µs/call | ||||
100 | 38 | 155µs | my ( $site, $url, $tooltip ) = @_; | ||
101 | 38 | 102µs | if ($site) { | ||
102 | 38 | 190µs | $interSiteTable{$site}{url} = $url || ''; | ||
103 | 38 | 105µs | $interSiteTable{$site}{tooltip} = $tooltip || ''; | ||
104 | } | ||||
105 | 38 | 294µs | return ''; | ||
106 | } | ||||
107 | |||||
108 | # spent 1.02ms (202µs+813µs) within Foswiki::Plugins::InterwikiPlugin::preRenderingHandler which was called 5 times, avg 203µs/call:
# 5 times (202µs+813µs) by Foswiki::Plugin::invoke at line 287 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm, avg 203µs/call | ||||
109 | |||||
110 | # ref in [[ref]] or [[ref][ | ||||
111 | $_[0] =~ | ||||
112 | 5 | 371µs | 10 | 302µs | s/(\[\[)$sitePattern:$pagePattern(\]\]|\]\[[^\]]+\]\])/_link($1,$2,$3,$4)/ge; # spent 243µs making 5 calls to Foswiki::Plugins::InterwikiPlugin::CORE:regcomp, avg 49µs/call
# spent 59µs making 5 calls to Foswiki::Plugins::InterwikiPlugin::CORE:subst, avg 12µs/call |
113 | |||||
114 | # ref in text | ||||
115 | $_[0] =~ | ||||
116 | 5 | 573µs | 10 | 511µs | s/(^|[\s\-\*\=\_\(])$sitePattern:$pagePattern(?=[\s\.\,\;\:\!\?\)\*\=\_\|]*(\s|$))/_link($1,$2,$3)/ge; # spent 351µs making 5 calls to Foswiki::Plugins::InterwikiPlugin::CORE:subst, avg 70µs/call
# spent 160µs making 5 calls to Foswiki::Plugins::InterwikiPlugin::CORE:regcomp, avg 32µs/call |
117 | |||||
118 | 5 | 45µs | return; | ||
119 | } | ||||
120 | |||||
121 | sub _link { | ||||
122 | my ( $prefix, $site, $page, $postfix ) = @_; | ||||
123 | |||||
124 | $prefix ||= ''; | ||||
125 | $site ||= ''; | ||||
126 | $page ||= ''; | ||||
127 | $postfix ||= ''; | ||||
128 | |||||
129 | my $upage = $page; | ||||
130 | if ( $page =~ /^['"](.*)["']$/ ) { | ||||
131 | $page = $1; | ||||
132 | $upage = Foswiki::urlEncode($1); | ||||
133 | } | ||||
134 | |||||
135 | my $text = $prefix; | ||||
136 | if ( defined( $interSiteTable{$site} ) ) { | ||||
137 | my $tooltip = $interSiteTable{$site}{tooltip}; | ||||
138 | my $url = $interSiteTable{$site}{url}; | ||||
139 | |||||
140 | #$url .= $page unless ( $url =~ /\$page/ ); | ||||
141 | |||||
142 | if ( $url =~ /\$page/ ) { | ||||
143 | $url =~ s/\$page/$upage/g; | ||||
144 | } | ||||
145 | else { | ||||
146 | $url .= $upage; | ||||
147 | } | ||||
148 | my $label = '$site:$page'; | ||||
149 | |||||
150 | if ($postfix) { | ||||
151 | |||||
152 | # [[...]] or [[...][...]] interwiki link | ||||
153 | $text = ''; | ||||
154 | if ( $postfix =~ /^\]\[([^\]]+)/ ) { | ||||
155 | $label = $1; | ||||
156 | } | ||||
157 | } | ||||
158 | |||||
159 | my $format = $interLinkFormat; | ||||
160 | $format =~ s/\$url/$url/g; | ||||
161 | $format =~ s/\$tooltip/$tooltip/g; | ||||
162 | $format =~ s/\$label/$label/g; | ||||
163 | $format =~ s/\$site/$site/g; | ||||
164 | $format =~ s/\$page/$page/g; | ||||
165 | $text .= $format; | ||||
166 | } | ||||
167 | else { | ||||
168 | $text .= "$site\:$page$postfix"; | ||||
169 | } | ||||
170 | return $text; | ||||
171 | } | ||||
172 | |||||
173 | # spent 36µs (30+7) within Foswiki::Plugins::InterwikiPlugin::_trimWhitespace which was called:
# once (30µs+7µs) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 71 | ||||
174 | 1 | 2µs | my $string = shift; | ||
175 | 1 | 14µs | 1 | 4µs | $string =~ s/^\s+//; # spent 4µs making 1 call to Foswiki::Plugins::InterwikiPlugin::CORE:subst |
176 | 1 | 16µs | 1 | 3µs | $string =~ s/\s+$//; # spent 3µs making 1 call to Foswiki::Plugins::InterwikiPlugin::CORE:subst |
177 | 1 | 8µs | return $string; | ||
178 | } | ||||
179 | |||||
180 | 1 | 8µs | 1; | ||
181 | __END__ | ||||
# spent 449µs within Foswiki::Plugins::InterwikiPlugin::CORE:regcomp which was called 11 times, avg 41µs/call:
# 5 times (243µs+0s) by Foswiki::Plugins::InterwikiPlugin::preRenderingHandler at line 112, avg 49µs/call
# 5 times (160µs+0s) by Foswiki::Plugins::InterwikiPlugin::preRenderingHandler at line 116, avg 32µs/call
# once (45µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 92 | |||||
# spent 454µs within Foswiki::Plugins::InterwikiPlugin::CORE:subst which was called 13 times, avg 35µs/call:
# 5 times (351µs+0s) by Foswiki::Plugins::InterwikiPlugin::preRenderingHandler at line 116, avg 70µs/call
# 5 times (59µs+0s) by Foswiki::Plugins::InterwikiPlugin::preRenderingHandler at line 112, avg 12µs/call
# once (38µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 92
# once (4µs+0s) by Foswiki::Plugins::InterwikiPlugin::_trimWhitespace at line 175
# once (3µs+0s) by Foswiki::Plugins::InterwikiPlugin::_trimWhitespace at line 176 | |||||
# spent 544µs within Foswiki::Plugins::InterwikiPlugin::CORE:substcont which was called 39 times, avg 14µs/call:
# 39 times (544µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 92, avg 14µs/call |