Filename | /var/www/foswikidev/core/lib/Foswiki/Plugins/InterwikiPlugin.pm |
Statements | Executed 243 statements in 2.13ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 676µs | 10.7ms | initPlugin | Foswiki::Plugins::InterwikiPlugin::
5 | 1 | 1 | 497µs | 497µs | preRenderingHandler | Foswiki::Plugins::InterwikiPlugin::
27 | 1 | 1 | 130µs | 130µs | _map | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 14µs | 26µs | BEGIN@23 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 9µs | 13µs | BEGIN@24 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 6µs | 6µs | _trimWhitespace | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@27 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@40 | Foswiki::Plugins::InterwikiPlugin::
1 | 1 | 1 | 3µs | 3µs | BEGIN@26 | 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 | 27µs | 2 | 39µs | # spent 26µs (14+13) within Foswiki::Plugins::InterwikiPlugin::BEGIN@23 which was called:
# once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.20 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 | 23µs | 2 | 17µs | # spent 13µs (9+4) within Foswiki::Plugins::InterwikiPlugin::BEGIN@24 which was called:
# once (9µs+4µs) by Foswiki::Plugin::BEGIN@2.20 at line 24 # spent 13µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@24
# spent 4µs making 1 call to warnings::import |
25 | |||||
26 | 2 | 19µs | 1 | 3µs | # spent 3µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@26 which was called:
# once (3µs+0s) by Foswiki::Plugin::BEGIN@2.20 at line 26 # spent 3µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@26 |
27 | 2 | 89µs | 1 | 4µs | # spent 4µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@27 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.20 at line 27 # spent 4µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@27 |
28 | |||||
29 | 1 | 700ns | our $VERSION = '1.22'; | ||
30 | 1 | 100ns | our $RELEASE = '1.22'; | ||
31 | 1 | 100ns | our $NO_PREFS_IN_TOPIC = 1; | ||
32 | 1 | 200ns | 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 4µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@40 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.20 at line 47 | ||||
41 | |||||
42 | # 'Use locale' for internationalisation of Perl sorting and searching - | ||||
43 | 1 | 5µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
44 | require locale; | ||||
45 | import locale(); | ||||
46 | } | ||||
47 | 1 | 672µs | 1 | 4µs | } # spent 4µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@40 |
48 | |||||
49 | # Read preferences and get all InterWiki Site->URL mappings | ||||
50 | # spent 10.7ms (676µs+10.0) within Foswiki::Plugins::InterwikiPlugin::initPlugin which was called:
# once (676µs+10.0ms) by Foswiki::Plugin::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Plugin.pm:257] at line 250 of /var/www/foswikidev/core/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 | 1µs | %interSiteTable = (); | ||
55 | 1 | 600ns | $sitePattern = "([[:upper:]][[:alnum:]]+)"; | ||
56 | 1 | 800ns | $pagePattern = | ||
57 | "((?:'[^']*')|(?:\"[^\"]*\")|(?:[[:alnum:]\_\~\%\/][[:alnum:]" | ||||
58 | . '"\'\.\/\+\_\~\,\&\;\:\=\!\?\%\#\@\-\(\)]*?))'; | ||||
59 | |||||
60 | # Get plugin preferences from InterwikiPlugin topic | ||||
61 | 1 | 2µs | 1 | 23µs | $interLinkFormat = # spent 23µs making 1 call to Foswiki::Func::getPreferencesValue |
62 | Foswiki::Func::getPreferencesValue('INTERWIKIPLUGIN_INTERLINKFORMAT') | ||||
63 | || '<a class="interwikiLink" href="$url" title="$tooltip"><noautolink>$label</noautolink></a>'; | ||||
64 | |||||
65 | 1 | 3µs | 1 | 18µs | my $rulesTopicPref = # spent 18µs making 1 call to Foswiki::Func::getPreferencesValue |
66 | Foswiki::Func::getPreferencesValue('INTERWIKIPLUGIN_RULESTOPIC') | ||||
67 | || 'InterWikis'; | ||||
68 | 1 | 3µs | my @rulesTopics = split( ',', $rulesTopicPref ); | ||
69 | 1 | 2µs | foreach my $topic (@rulesTopics) { | ||
70 | 1 | 3µs | 1 | 6µs | $topic = _trimWhitespace($topic); # spent 6µs making 1 call to Foswiki::Plugins::InterwikiPlugin::_trimWhitespace |
71 | |||||
72 | 1 | 4µs | 1 | 12µs | my ( $interWeb, $interTopic ) = # spent 12µs making 1 call to Foswiki::Func::normalizeWebTopicName |
73 | Foswiki::Func::normalizeWebTopicName( $installWeb, $topic ); | ||||
74 | |||||
75 | 1 | 3µs | 1 | 8.42ms | if ( # spent 8.42ms making 1 call to Foswiki::Func::checkAccessPermission |
76 | !Foswiki::Func::checkAccessPermission( | ||||
77 | 'VIEW', $user, undef, $interTopic, $interWeb | ||||
78 | ) | ||||
79 | ) | ||||
80 | { | ||||
81 | Foswiki::Func::writeWarning( | ||||
82 | "InterwikiPlugin: user '$user' did not have permission to read the rules topic at '$interWeb.$interTopic'" | ||||
83 | ); | ||||
84 | return 1; | ||||
85 | } | ||||
86 | 1 | 3µs | 1 | 580µs | my ( $meta, $text ) = # spent 580µs making 1 call to Foswiki::Func::readTopic |
87 | Foswiki::Func::readTopic( $interWeb, $interTopic ); | ||||
88 | |||||
89 | # '| alias | URL | ...' table and extract into 'alias', "URL" list | ||||
90 | 28 | 587µs | 29 | 959µs | $text =~ s/ # spent 829µs making 2 calls to utf8::SWASHNEW, avg 414µs/call
# spent 130µs making 27 calls to Foswiki::Plugins::InterwikiPlugin::_map, avg 5µs/call |
91 | ^\|\s* # Start of table | ||||
92 | $sitePattern | ||||
93 | \s*\|\s* # Column separator | ||||
94 | (.*?) # URL | ||||
95 | \s*\|\s* # Column separator | ||||
96 | (.*?) # tooltip | ||||
97 | (?: | ||||
98 | \s*\|\s* # Colunmn separator | ||||
99 | ([^\|\n]+) # Not a separator or end of line | ||||
100 | )? | ||||
101 | \s*\|.*? # Last column separator | ||||
102 | /_map($1,$2,$3,$4)/megx; | ||||
103 | |||||
104 | } | ||||
105 | |||||
106 | 1 | 10µs | $sitePattern = "(" . join( "|", keys %interSiteTable ) . ")"; | ||
107 | |||||
108 | 1 | 5µs | return 1; | ||
109 | } | ||||
110 | |||||
111 | # spent 130µs within Foswiki::Plugins::InterwikiPlugin::_map which was called 27 times, avg 5µs/call:
# 27 times (130µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 90, avg 5µs/call | ||||
112 | 27 | 33µs | my ( $site, $url, $tooltip, $format ) = @_; | ||
113 | 27 | 7µs | if ($site) { | ||
114 | 27 | 34µs | $interSiteTable{$site}{url} = $url || ''; | ||
115 | 27 | 15µs | $interSiteTable{$site}{tooltip} = $tooltip || ''; | ||
116 | 27 | 6µs | if ( defined $format ) { | ||
117 | 1 | 5µs | $format =~ s/\s*$//g; # remove trailing spaces | ||
118 | 1 | 900ns | $interSiteTable{$site}{format} = $format; | ||
119 | } | ||||
120 | } | ||||
121 | 27 | 62µs | return ''; | ||
122 | } | ||||
123 | |||||
124 | # spent 497µs within Foswiki::Plugins::InterwikiPlugin::preRenderingHandler which was called 5 times, avg 99µs/call:
# 5 times (497µs+0s) by Foswiki::Plugin::invoke at line 310 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm, avg 99µs/call | ||||
125 | |||||
126 | # ref in [[ref]] or [[ref][ | ||||
127 | $_[0] =~ | ||||
128 | 5 | 198µs | s/(\[\[)$sitePattern:$pagePattern(\]\]|\]\[[^\]]+\]\])/_link($1,$2,$3,$4)/ge; | ||
129 | |||||
130 | # ref in text | ||||
131 | $_[0] =~ | ||||
132 | 5 | 277µs | s/(^|[\s\-\*\=\_\(])$sitePattern:$pagePattern(?=[\s\.\,\;\:\!\?\)\*\=\_\|]*(\s|$))/_link($1,$2,$3)/ge; | ||
133 | |||||
134 | 5 | 16µs | return; | ||
135 | } | ||||
136 | |||||
137 | sub _link { | ||||
138 | my ( $prefix, $site, $page, $postfix ) = @_; | ||||
139 | |||||
140 | $prefix ||= ''; | ||||
141 | $site ||= ''; | ||||
142 | $page ||= ''; | ||||
143 | $postfix ||= ''; | ||||
144 | |||||
145 | my $upage = $page; | ||||
146 | if ( $page =~ m/^['"](.*)["']$/ ) { | ||||
147 | $page = $1; | ||||
148 | $upage = Foswiki::urlEncode($1); | ||||
149 | } | ||||
150 | |||||
151 | my $text = $prefix; | ||||
152 | if ( defined( $interSiteTable{$site} ) ) { | ||||
153 | my $tooltip = $interSiteTable{$site}{tooltip}; | ||||
154 | my $url = $interSiteTable{$site}{url}; | ||||
155 | |||||
156 | #$url .= $page unless ( $url =~ m/\$page/ ); | ||||
157 | |||||
158 | if ( $url =~ m/\$page/ ) { | ||||
159 | $url =~ s/\$page/$upage/g; | ||||
160 | } | ||||
161 | else { | ||||
162 | $url .= $upage; | ||||
163 | } | ||||
164 | my $label = '$site:$page'; | ||||
165 | |||||
166 | if ($postfix) { | ||||
167 | |||||
168 | # [[...]] or [[...][...]] interwiki link | ||||
169 | $text = ''; | ||||
170 | if ( $postfix =~ m/^\]\[([^\]]+)/ ) { | ||||
171 | $label = $1; | ||||
172 | } | ||||
173 | } | ||||
174 | |||||
175 | my $format = $interSiteTable{$site}{format} || $interLinkFormat; | ||||
176 | $format =~ s/\$url/$url/g; | ||||
177 | $format =~ s/\$tooltip/$tooltip/g; | ||||
178 | $format =~ s/\$label/$label/g; | ||||
179 | $format =~ s/\$site/$site/g; | ||||
180 | $format =~ s/\$page/$page/g; | ||||
181 | $text .= $format; | ||||
182 | } | ||||
183 | else { | ||||
184 | $text .= "$site\:$page$postfix"; | ||||
185 | } | ||||
186 | $text = Foswiki::Func::expandCommonVariables($text); | ||||
187 | return $text; | ||||
188 | } | ||||
189 | |||||
190 | # spent 6µs within Foswiki::Plugins::InterwikiPlugin::_trimWhitespace which was called:
# once (6µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 70 | ||||
191 | 1 | 800ns | my $string = shift; | ||
192 | 1 | 2µs | $string =~ s/^\s+//; | ||
193 | 1 | 1µs | $string =~ s/\s+$//; | ||
194 | 1 | 4µs | return $string; | ||
195 | } | ||||
196 | |||||
197 | 1 | 4µs | 1; | ||
198 | __END__ |