← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 18:42:36 2015
Reported on Fri Jul 31 18:48:14 2015

Filename/var/www/foswikidev/core/lib/Foswiki/Plugins/RevisionLinkPlugin.pm
StatementsExecuted 13 statements in 572µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11121µs106µsFoswiki::Plugins::RevisionLinkPlugin::::initPluginFoswiki::Plugins::RevisionLinkPlugin::initPlugin
11114µs28µsFoswiki::Plugins::RevisionLinkPlugin::::BEGIN@33Foswiki::Plugins::RevisionLinkPlugin::BEGIN@33
11111µs50µsFoswiki::Plugins::RevisionLinkPlugin::::BEGIN@37Foswiki::Plugins::RevisionLinkPlugin::BEGIN@37
0000s0sFoswiki::Plugins::RevisionLinkPlugin::::handleRevisionFoswiki::Plugins::RevisionLinkPlugin::handleRevision
Call graph for these subroutines as a Graphviz dot language file.
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
24RevisionLinkPlugin makes links to specified revisions and revisions
25relative to current revision.
26
27=cut
28
29# =========================
30package Foswiki::Plugins::RevisionLinkPlugin;
31
32# Always use strict to enforce variable scoping
33246µs242µ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
use strict;
# 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
372497µs289µ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
use vars qw( $VERSION $RELEASE $debug $pluginName );
# 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.
441600ns$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.
491200ns$RELEASE = '2.2 (27 Jan 2009)';
50
51# Name of this Plugin, only used in this module
521200ns$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
62REQUIRED
63
64Called to initialise the plugin. If everything is OK, should return
65a non-zero value. On non-fatal failure, should write a message
66using Foswiki::Func::writeWarning and return 0. In this case
67%FAILEDPLUGINS% will indicate which plugins failed.
68
69In the case of a catastrophic failure that will prevent the whole
70installation from working safely, this handler may use 'die', which
71will be trapped and reported in the browser.
72
73You may also call =Foswiki::Func::registerTagHandler= here to register
74a function to handle variables that have standard Foswiki syntax - for example,
75=%MYTAG{"my param" myarg="My Arg"}%. You can also override internal
76Foswiki variable handling functions this way, though this practice is unsupported
77and 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
sub initPlugin {
8212µs my ( $topic, $web, $user, $installWeb ) = @_;
83
84 # check for Plugins.pm versions
85110µs15µ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
9212µs164µs $debug = &Foswiki::Func::getPreferencesFlag("REVISIONLINKPLUGIN_DEBUG");
# spent 64µs making 1 call to Foswiki::Func::getPreferencesFlag
93
9413µs116µs Foswiki::Func::registerTagHandler( 'REV', \&handleRevision,
# spent 16µs making 1 call to Foswiki::Func::registerTagHandler
95 'context-free' );
96
97 # Plugin correctly initialized
9817µs return 1;
99}
100
101sub 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 =~
169s/!(.*?)!/[[%SCRIPTURLPATH{"viewfile"}%\/$tmpWeb\/$targetTopic\/$tmpAttachment\?rev=$rev][$1]]/g;
170 }
171 else {
172 $format =~
173s/!(.*?)!/[[%SCRIPTURLPATH{"view"}%\/$tmpWeb\/$targetTopic\?rev=$rev][$1]]/g;
174 }
175 return $format;
176}
177
17813µs1;