Filename | /var/www/foswikidev/core/lib/Foswiki/Plugins/RevisionLinkPlugin.pm |
Statements | Executed 13 statements in 572µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 21µs | 106µs | initPlugin | Foswiki::Plugins::RevisionLinkPlugin::
1 | 1 | 1 | 14µs | 28µs | BEGIN@33 | Foswiki::Plugins::RevisionLinkPlugin::
1 | 1 | 1 | 11µs | 50µs | BEGIN@37 | Foswiki::Plugins::RevisionLinkPlugin::
0 | 0 | 0 | 0s | 0s | handleRevision | Foswiki::Plugins::RevisionLinkPlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ | ||||
2 | # | ||||
3 | # Copyright (C) 2001-2006 Peter Thoeny, peter@thoeny.org | ||||
4 | # Copyright (C) 2003 Richard Baar, richard.baar@centrum.cz | ||||
5 | # Copyright (C) 2009 Kenneth Lavrsen, kenneth@lavrsen.dk | ||||
6 | # and Foswiki Contributors. | ||||
7 | # | ||||
8 | # This program is free software; you can redistribute it and/or | ||||
9 | # modify it under the terms of the GNU General Public License | ||||
10 | # as published by the Free Software Foundation; either version 2 | ||||
11 | # of the License, or (at your option) any later version. For | ||||
12 | # more details read LICENSE in the root of this distribution. | ||||
13 | # | ||||
14 | # This program is distributed in the hope that it will be useful, | ||||
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||
17 | # | ||||
18 | # For licensing info read LICENSE file in the Foswiki root. | ||||
19 | |||||
20 | =pod | ||||
21 | |||||
22 | ---+ package RevisionLinkPlugin | ||||
23 | |||||
24 | RevisionLinkPlugin makes links to specified revisions and revisions | ||||
25 | relative to current revision. | ||||
26 | |||||
27 | =cut | ||||
28 | |||||
29 | # ========================= | ||||
30 | package Foswiki::Plugins::RevisionLinkPlugin; | ||||
31 | |||||
32 | # Always use strict to enforce variable scoping | ||||
33 | 2 | 46µs | 2 | 42µs | # spent 28µs (14+14) within Foswiki::Plugins::RevisionLinkPlugin::BEGIN@33 which was called:
# once (14µs+14µs) by Foswiki::Plugin::BEGIN@2.33 at line 33 # spent 28µs making 1 call to Foswiki::Plugins::RevisionLinkPlugin::BEGIN@33
# spent 14µs making 1 call to strict::import |
34 | |||||
35 | # $VERSION is referred to by Foswiki, and is the only global variable that | ||||
36 | # *must* exist in this package | ||||
37 | 2 | 497µs | 2 | 89µs | # spent 50µs (11+39) within Foswiki::Plugins::RevisionLinkPlugin::BEGIN@37 which was called:
# once (11µs+39µs) by Foswiki::Plugin::BEGIN@2.33 at line 37 # spent 50µs making 1 call to Foswiki::Plugins::RevisionLinkPlugin::BEGIN@37
# spent 39µs making 1 call to vars::import |
38 | |||||
39 | #$web $topic $user $installWeb | ||||
40 | |||||
41 | # This should always be $Rev$ so that Foswiki can determine the checked-in | ||||
42 | # status of the plugin. It is used by the build automation tools, so | ||||
43 | # you should leave it alone. | ||||
44 | 1 | 600ns | $VERSION = '$Rev$'; | ||
45 | |||||
46 | # This is a free-form string you can use to "name" your own plugin version. | ||||
47 | # It is *not* used by the build automation tools, but is reported as part | ||||
48 | # of the version number in PLUGINDESCRIPTIONS. | ||||
49 | 1 | 200ns | $RELEASE = '2.2 (27 Jan 2009)'; | ||
50 | |||||
51 | # Name of this Plugin, only used in this module | ||||
52 | 1 | 200ns | $pluginName = 'RevisionLinkPlugin'; | ||
53 | |||||
54 | =pod | ||||
55 | |||||
56 | ---++ initPlugin($topic, $web, $user, $installWeb) -> $boolean | ||||
57 | * =$topic= - the name of the topic in the current CGI query | ||||
58 | * =$web= - the name of the web in the current CGI query | ||||
59 | * =$user= - the login name of the user | ||||
60 | * =$installWeb= - the name of the web the plugin is installed in | ||||
61 | |||||
62 | REQUIRED | ||||
63 | |||||
64 | Called to initialise the plugin. If everything is OK, should return | ||||
65 | a non-zero value. On non-fatal failure, should write a message | ||||
66 | using Foswiki::Func::writeWarning and return 0. In this case | ||||
67 | %FAILEDPLUGINS% will indicate which plugins failed. | ||||
68 | |||||
69 | In the case of a catastrophic failure that will prevent the whole | ||||
70 | installation from working safely, this handler may use 'die', which | ||||
71 | will be trapped and reported in the browser. | ||||
72 | |||||
73 | You may also call =Foswiki::Func::registerTagHandler= here to register | ||||
74 | a function to handle variables that have standard Foswiki syntax - for example, | ||||
75 | =%MYTAG{"my param" myarg="My Arg"}%. You can also override internal | ||||
76 | Foswiki variable handling functions this way, though this practice is unsupported | ||||
77 | and highly dangerous! | ||||
78 | |||||
79 | =cut | ||||
80 | |||||
81 | # spent 106µs (21+85) within Foswiki::Plugins::RevisionLinkPlugin::initPlugin which was called:
# once (21µs+85µs) 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 | ||||
82 | 1 | 2µs | my ( $topic, $web, $user, $installWeb ) = @_; | ||
83 | |||||
84 | # check for Plugins.pm versions | ||||
85 | 1 | 10µs | 1 | 5µs | if ( $Foswiki::Plugins::VERSION < 1 ) { # spent 5µs making 1 call to version::vxs::VCMP |
86 | &Foswiki::Func::writeWarning( | ||||
87 | "Version mismatch between RevisionLinkPlugin and Plugins.pm"); | ||||
88 | return 0; | ||||
89 | } | ||||
90 | |||||
91 | # Get plugin debug flag | ||||
92 | 1 | 2µs | 1 | 64µs | $debug = &Foswiki::Func::getPreferencesFlag("REVISIONLINKPLUGIN_DEBUG"); # spent 64µs making 1 call to Foswiki::Func::getPreferencesFlag |
93 | |||||
94 | 1 | 3µs | 1 | 16µs | Foswiki::Func::registerTagHandler( 'REV', \&handleRevision, # spent 16µs making 1 call to Foswiki::Func::registerTagHandler |
95 | 'context-free' ); | ||||
96 | |||||
97 | # Plugin correctly initialized | ||||
98 | 1 | 7µs | return 1; | ||
99 | } | ||||
100 | |||||
101 | sub handleRevision { | ||||
102 | |||||
103 | # my ( $text, $topic, $web ) = @_; | ||||
104 | my ( $session, $params, $topic, $web ) = @_; | ||||
105 | |||||
106 | my $tmpWeb = $params->{'web'} || $web; | ||||
107 | my $rev = $params->{'rev'} || ''; | ||||
108 | my $format = $params->{'format'} || ''; | ||||
109 | my $emptyAttr = $params->{'_DEFAULT'} || ''; | ||||
110 | my $tmpAttachment = $params->{'attachment'} || ''; | ||||
111 | |||||
112 | my $tmpTopic = $topic; | ||||
113 | |||||
114 | if ( $emptyAttr ne '' ) { | ||||
115 | if ( $rev eq '' ) { | ||||
116 | $rev = $emptyAttr; | ||||
117 | } | ||||
118 | else { | ||||
119 | $tmpTopic = $emptyAttr; | ||||
120 | } | ||||
121 | } | ||||
122 | |||||
123 | my $targetTopic = $params->{'topic'} || $tmpTopic; | ||||
124 | |||||
125 | if ( $rev < 0 ) { | ||||
126 | my $maxRev = ( | ||||
127 | Foswiki::Func::getRevisionInfo( | ||||
128 | $tmpWeb, $targetTopic, undef, $tmpAttachment | ||||
129 | ) | ||||
130 | )[2]; | ||||
131 | $rev = $maxRev + $rev; | ||||
132 | } | ||||
133 | |||||
134 | # Remove 1. prefix in case the Foswiki contains old Cairo topics and they | ||||
135 | # use the plugin the old way | ||||
136 | $rev =~ s/1\.(.*)/$1/; | ||||
137 | |||||
138 | if ( $rev ne '' && $rev < 1 ) { | ||||
139 | $rev = 1; | ||||
140 | } | ||||
141 | |||||
142 | my ( $revDate, $revUser, $tmpRev, $revComment ) = | ||||
143 | Foswiki::Func::getRevisionInfo( $tmpWeb, $targetTopic, $rev, | ||||
144 | $tmpAttachment ); | ||||
145 | |||||
146 | if ( $format eq "" ) { | ||||
147 | if ($tmpAttachment) { | ||||
148 | $format = "!$tmpAttachment($rev)!"; | ||||
149 | } | ||||
150 | else { | ||||
151 | $format = "!$targetTopic($rev)!"; | ||||
152 | } | ||||
153 | } | ||||
154 | else { | ||||
155 | if ( $format =~ /!(.*?)!/ eq "" ) { | ||||
156 | $format = "!$format!"; | ||||
157 | } | ||||
158 | $format =~ s/\$topic/$targetTopic/geo; | ||||
159 | $format =~ s/\$web/$tmpWeb/geo; | ||||
160 | $format =~ s/\$attachment/$tmpAttachment/geo; | ||||
161 | $format =~ s/\$rev/$rev/geo; | ||||
162 | $format =~ s/\$date/$revDate/geo; | ||||
163 | $format =~ s/\$user/$revUser/geo; | ||||
164 | $format =~ s/\$comment/$revComment/geo; | ||||
165 | } | ||||
166 | |||||
167 | if ($tmpAttachment) { | ||||
168 | $format =~ | ||||
169 | s/!(.*?)!/[[%SCRIPTURLPATH{"viewfile"}%\/$tmpWeb\/$targetTopic\/$tmpAttachment\?rev=$rev][$1]]/g; | ||||
170 | } | ||||
171 | else { | ||||
172 | $format =~ | ||||
173 | s/!(.*?)!/[[%SCRIPTURLPATH{"view"}%\/$tmpWeb\/$targetTopic\?rev=$rev][$1]]/g; | ||||
174 | } | ||||
175 | return $format; | ||||
176 | } | ||||
177 | |||||
178 | 1 | 3µs | 1; |