← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:10 2015

Filename/var/www/foswiki11/lib/Foswiki/Plugins/RevisionLinkPlugin.pm
StatementsExecuted 13 statements in 584µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11127µs142µsFoswiki::Plugins::RevisionLinkPlugin::::initPluginFoswiki::Plugins::RevisionLinkPlugin::initPlugin
11115µs28µsFoswiki::Plugins::RevisionLinkPlugin::::BEGIN@33Foswiki::Plugins::RevisionLinkPlugin::BEGIN@33
11110µs49µ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
33235µs242µs
# spent 28µs (15+14) within Foswiki::Plugins::RevisionLinkPlugin::BEGIN@33 which was called: # once (15µs+14µs) by Foswiki::Plugin::BEGIN@2.29 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
372518µs288µs
# spent 49µs (10+39) within Foswiki::Plugins::RevisionLinkPlugin::BEGIN@37 which was called: # once (10µs+39µs) by Foswiki::Plugin::BEGIN@2.29 at line 37
use vars qw( $VERSION $RELEASE $debug $pluginName );
# spent 49µs making 1 call to Foswiki::Plugins::RevisionLinkPlugin::BEGIN@37 # spent 39µs making 1 call to vars::import
38#$web $topic $user $installWeb
39
40# This should always be $Rev: 2188 (27 Jan 2009) $ so that Foswiki can determine the checked-in
41# status of the plugin. It is used by the build automation tools, so
42# you should leave it alone.
431600ns$VERSION = '$Rev: 2188 (27 Jan 2009) $';
44
45# This is a free-form string you can use to "name" your own plugin version.
46# It is *not* used by the build automation tools, but is reported as part
47# of the version number in PLUGINDESCRIPTIONS.
481300ns$RELEASE = '2.2 (27 Jan 2009)';
49
50# Name of this Plugin, only used in this module
511200ns$pluginName = 'RevisionLinkPlugin';
52
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
81sub initPlugin
82
# spent 142µs (27+115) within Foswiki::Plugins::RevisionLinkPlugin::initPlugin which was called: # once (27µs+115µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm
{
8312µs my ( $topic, $web, $user, $installWeb ) = @_;
84
85 # check for Plugins.pm versions
86112µs16µs if( $Foswiki::Plugins::VERSION < 1 ) {
# spent 6µs making 1 call to version::vxs::VCMP
87 &Foswiki::Func::writeWarning( "Version mismatch between RevisionLinkPlugin and Plugins.pm" );
88 return 0;
89 }
90
91 # Get plugin debug flag
9213µs182µs $debug = &Foswiki::Func::getPreferencesFlag( "REVISIONLINKPLUGIN_DEBUG" );
# spent 82µs making 1 call to Foswiki::Func::getPreferencesFlag
93
9413µs127µs Foswiki::Func::registerTagHandler( 'REV', \&handleRevision, 'context-free' );
# spent 27µs making 1 call to Foswiki::Func::registerTagHandler
95
96 # Plugin correctly initialized
9717µs return 1;
98}
99
100
101sub handleRevision {
102# my ( $text, $topic, $web ) = @_;
103 my ($session, $params, $topic, $web) = @_;
104
105 my $tmpWeb = $params->{'web'} || $web;
106 my $rev = $params->{'rev'} || '-1';
107 my $format = $params->{'format'} || '';
108 my $emptyAttr = $params->{'_DEFAULT'} || '';
109 my $tmpAttachment = $params->{'attachment'} || '';
110
111 my $tmpTopic = $topic;
112
113 if ( $emptyAttr ne '' ) {
114 if ( $rev eq '' ) {
115 $rev = $emptyAttr;
116 }
117 else {
118 $tmpTopic = $emptyAttr;
119 }
120 }
121
122 my $targetTopic = $params->{'topic'} || $tmpTopic;
123
124 if ( $rev < 0 ) {
125 my $maxRev = (Foswiki::Func::getRevisionInfo( $tmpWeb, $targetTopic, undef, $tmpAttachment ))[2];
126 $rev = $maxRev + $rev;
127 }
128
129 # Remove 1. prefix in case the Foswiki contains old Cairo topics and they
130 # use the plugin the old way
131 $rev =~ s/1\.(.*)/$1/;
132
133 if ( $rev ne '' && $rev < 1 ) {
134 $rev = 1;
135 }
136
137 my ( $revDate, $revUser, $tmpRev, $revComment ) = Foswiki::Func::getRevisionInfo( $tmpWeb, $targetTopic, $rev, $tmpAttachment);
138
139 if ( $format eq "" ) {
140 if ( $tmpAttachment ) {
141 $format = "!$tmpAttachment($rev)!";
142 }
143 else {
144 $format = "!$targetTopic($rev)!";
145 }
146 }
147 else {
148 if ( $format =~ /!(.*?)!/ eq "" ) {
149 $format = "!$format!";
150 }
151 $format =~ s/\$topic/$targetTopic/geo;
152 $format =~ s/\$web/$tmpWeb/geo;
153 $format =~ s/\$attachment/$tmpAttachment/geo;
154 $format =~ s/\$rev/$rev/geo;
155 $format =~ s/\$date/$revDate/geo;
156 $format =~ s/\$user/$revUser/geo;
157 $format =~ s/\$comment/$revComment/geo;
158 }
159
160 if ( $tmpAttachment ) {
161 $format =~ s/!(.*?)!/[[%SCRIPTURLPATH{"viewfile"}%\/$tmpWeb\/$targetTopic\/$tmpAttachment\?rev=$rev][$1]]/g;
162 }
163 else {
164 $format =~ s/!(.*?)!/[[%SCRIPTURLPATH{"view"}%\/$tmpWeb\/$targetTopic\?rev=$rev][$1]]/g;
165 }
166 return $format;
167}
168
16913µs1;