Filename | /var/www/foswiki11/lib/Foswiki/Plugins/InterwikiPlugin.pm |
Statements | Executed 376 statements in 3.21ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5 | 1 | 1 | 1.36ms | 1.36ms | preRenderingHandler | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 695µs | 3.11ms | initPlugin | Foswiki::Plugins::InterwikiPlugin::
53 | 1 | 1 | 289µs | 289µs | _map | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 13µs | 26µs | BEGIN@23 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 13µs | 19µs | BEGIN@40 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 12µs | 12µs | _trimWhitespace | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 10µs | 15µs | BEGIN@24 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 9µs | 32µs | BEGIN@29 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@26 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 3µs | 3µ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 | 35µs | 2 | 39µs | # spent 26µs (13+13) within Foswiki::Plugins::InterwikiPlugin::BEGIN@23 which was called:
# once (13µs+13µs) by Foswiki::Plugin::BEGIN@2.18 at line 23 # spent 26µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@23
# spent 13µs making 1 call to strict::import |
24 | 2 | 24µs | 2 | 20µs | # spent 15µs (10+5) within Foswiki::Plugins::InterwikiPlugin::BEGIN@24 which was called:
# once (10µs+5µs) by Foswiki::Plugin::BEGIN@2.18 at line 24 # spent 15µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@24
# spent 5µs making 1 call to warnings::import |
25 | |||||
26 | 2 | 19µs | 1 | 4µs | # spent 4µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@26 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.18 at line 26 # spent 4µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@26 |
27 | 2 | 20µs | 1 | 3µs | # spent 3µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@27 which was called:
# once (3µs+0s) by Foswiki::Plugin::BEGIN@2.18 at line 27 # spent 3µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@27 |
28 | |||||
29 | 3 | 115µs | 3 | 63µs | # spent 32µs (9+23) within Foswiki::Plugins::InterwikiPlugin::BEGIN@29 which was called:
# once (9µs+23µs) by Foswiki::Plugin::BEGIN@2.18 at line 29 # spent 32µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@29
# spent 23µs making 1 call to version::import
# spent 7µs making 1 call to version::vxs::declare |
30 | 1 | 300ns | our $RELEASE = '1.1.7'; | ||
31 | 1 | 200ns | our $NO_PREFS_IN_TOPIC = 1; | ||
32 | 1 | 300ns | our $SHORTDESCRIPTION = | ||
33 | 'Link !ExternalSite:Page text to external sites based on aliases defined in a rules topic'; | ||||
34 | |||||
35 | 1 | 200ns | my $interLinkFormat; | ||
36 | 1 | 100ns | my $sitePattern; | ||
37 | 1 | 100ns | my $pagePattern; | ||
38 | 1 | 100ns | my %interSiteTable; | ||
39 | |||||
40 | # spent 19µs (13+6) within Foswiki::Plugins::InterwikiPlugin::BEGIN@40 which was called:
# once (13µs+6µs) by Foswiki::Plugin::BEGIN@2.18 at line 47 | ||||
41 | |||||
42 | # 'Use locale' for internationalisation of Perl sorting and searching - | ||||
43 | 1 | 4µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
44 | 1 | 400ns | require locale; | ||
45 | 1 | 6µs | 1 | 6µs | import locale(); # spent 6µs making 1 call to locale::import |
46 | } | ||||
47 | 1 | 647µs | 1 | 19µs | } # spent 19µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@40 |
48 | |||||
49 | # Read preferences and get all InterWiki Site->URL mappings | ||||
50 | # spent 3.11ms (695µs+2.41) within Foswiki::Plugins::InterwikiPlugin::initPlugin which was called:
# once (695µs+2.41ms) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm | ||||
51 | 1 | 2µs | my ( $topic, $web, $user, $installWeb ) = @_; | ||
52 | |||||
53 | # Regexes for the Site:page format InterWiki reference | ||||
54 | 1 | 2µs | my $man = $Foswiki::regex{mixedAlphaNum}; | ||
55 | 1 | 1µs | my $ua = $Foswiki::regex{upperAlpha}; | ||
56 | 1 | 1µs | %interSiteTable = (); | ||
57 | 1 | 3µs | $sitePattern = "([$ua][$man]+)"; | ||
58 | 1 | 2µs | $pagePattern = "((?:'[^']*')|(?:\"[^\"]*\")|(?:[${man}\_\~\%\/][$man" | ||
59 | . '"\'\.\/\+\_\~\,\&\;\:\=\!\?\%\#\@\-\(\)]*?))'; | ||||
60 | |||||
61 | # Get plugin preferences from InterwikiPlugin topic | ||||
62 | 1 | 3µs | 1 | 36µs | $interLinkFormat = # spent 36µ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 | 2µs | 1 | 55µs | my $rulesTopicPref = # spent 55µ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 | 3µs | foreach my $topic (@rulesTopics) { | ||
71 | 1 | 5µs | 1 | 12µs | $topic = _trimWhitespace($topic); # spent 12µs making 1 call to Foswiki::Plugins::InterwikiPlugin::_trimWhitespace |
72 | |||||
73 | 1 | 5µs | 1 | 134µs | my ( $interWeb, $interTopic ) = # spent 134µs making 1 call to Foswiki::Func::normalizeWebTopicName |
74 | Foswiki::Func::normalizeWebTopicName( $installWeb, $topic ); | ||||
75 | |||||
76 | 1 | 4µs | 1 | 1.07ms | if ( # spent 1.07ms 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 | 5µs | 1 | 814µs | my $text = # spent 814µs 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 | 53 | 73µs | 53 | 289µs | $text =~ # spent 289µs making 53 calls to Foswiki::Plugins::InterwikiPlugin::_map, avg 5µs/call |
92 | 1 | 463µs | s/^\|\s*$sitePattern\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|.*$/_map($1,$2,$3)/meg; | ||
93 | } | ||||
94 | |||||
95 | 1 | 16µs | $sitePattern = "(" . join( "|", keys %interSiteTable ) . ")"; | ||
96 | 1 | 7µs | return 1; | ||
97 | } | ||||
98 | |||||
99 | # spent 289µs within Foswiki::Plugins::InterwikiPlugin::_map which was called 53 times, avg 5µs/call:
# 53 times (289µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 91, avg 5µs/call | ||||
100 | 53 | 71µs | my ( $site, $url, $tooltip ) = @_; | ||
101 | 53 | 15µs | if ($site) { | ||
102 | 53 | 83µs | $interSiteTable{$site}{url} = $url || ''; | ||
103 | 53 | 46µs | $interSiteTable{$site}{tooltip} = $tooltip || ''; | ||
104 | } | ||||
105 | 53 | 156µs | return ''; | ||
106 | } | ||||
107 | |||||
108 | # spent 1.36ms within Foswiki::Plugins::InterwikiPlugin::preRenderingHandler which was called 5 times, avg 271µs/call:
# 5 times (1.36ms+0s) by Foswiki::Plugin::invoke at line 294 of /var/www/foswiki11/lib/Foswiki/Plugin.pm, avg 271µs/call | ||||
109 | |||||
110 | # ref in [[ref]] or [[ref][ | ||||
111 | $_[0] =~ | ||||
112 | 5 | 186µs | s/(\[\[)$sitePattern:$pagePattern(\]\]|\]\[[^\]]+\]\])/_link($1,$2,$3,$4)/ge; | ||
113 | |||||
114 | # ref in text | ||||
115 | $_[0] =~ | ||||
116 | 5 | 1.14ms | s/(^|[\s\-\*\=\_\(])$sitePattern:$pagePattern(?=[\s\.\,\;\:\!\?\)\*\=\_\|]*(\s|$))/_link($1,$2,$3)/ge; | ||
117 | |||||
118 | 5 | 21µ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 12µs within Foswiki::Plugins::InterwikiPlugin::_trimWhitespace which was called:
# once (12µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 71 | ||||
174 | 1 | 800ns | my $string = shift; | ||
175 | 1 | 3µs | $string =~ s/^\s+//; | ||
176 | 1 | 3µs | $string =~ s/\s+$//; | ||
177 | 1 | 6µs | return $string; | ||
178 | } | ||||
179 | |||||
180 | 1 | 6µs | 1; | ||
181 | __END__ |