Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/CommentPlugin.pm |
Statements | Executed 31 statements in 1.51ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 3.23ms | 442ms | _COMMENT | Foswiki::Plugins::CommentPlugin::
1 | 1 | 1 | 46µs | 3.23ms | initPlugin | Foswiki::Plugins::CommentPlugin::
1 | 1 | 1 | 32µs | 619µs | BEGIN@10 | Foswiki::Plugins::CommentPlugin::
1 | 1 | 1 | 27µs | 35µs | BEGIN@7 | Foswiki::Plugins::CommentPlugin::
1 | 1 | 1 | 22µs | 39µs | BEGIN@8 | Foswiki::Plugins::CommentPlugin::
1 | 1 | 1 | 19µs | 93µs | BEGIN@9 | Foswiki::Plugins::CommentPlugin::
1 | 1 | 1 | 10µs | 10µs | BEGIN@13 | Foswiki::Plugins::CommentPlugin::
1 | 1 | 1 | 10µs | 10µs | BEGIN@12 | Foswiki::Plugins::CommentPlugin::
0 | 0 | 0 | 0s | 0s | __ANON__[:113] | Foswiki::Plugins::CommentPlugin::
0 | 0 | 0 | 0s | 0s | __ANON__[:122] | Foswiki::Plugins::CommentPlugin::
0 | 0 | 0 | 0s | 0s | __ANON__[:131] | Foswiki::Plugins::CommentPlugin::
0 | 0 | 0 | 0s | 0s | _restSave | Foswiki::Plugins::CommentPlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | # | ||||
3 | # See Plugin topic for history and plugin information | ||||
4 | |||||
5 | package Foswiki::Plugins::CommentPlugin; | ||||
6 | |||||
7 | 2 | 47µs | 2 | 43µs | # spent 35µs (27+8) within Foswiki::Plugins::CommentPlugin::BEGIN@7 which was called:
# once (27µs+8µs) by Foswiki::Plugin::BEGIN@2.5 at line 7 # spent 35µs making 1 call to Foswiki::Plugins::CommentPlugin::BEGIN@7
# spent 8µs making 1 call to strict::import |
8 | 2 | 45µs | 2 | 57µs | # spent 39µs (22+18) within Foswiki::Plugins::CommentPlugin::BEGIN@8 which was called:
# once (22µs+18µs) by Foswiki::Plugin::BEGIN@2.5 at line 8 # spent 39µs making 1 call to Foswiki::Plugins::CommentPlugin::BEGIN@8
# spent 18µs making 1 call to warnings::import |
9 | 2 | 57µs | 2 | 167µs | # spent 93µs (19+74) within Foswiki::Plugins::CommentPlugin::BEGIN@9 which was called:
# once (19µs+74µs) by Foswiki::Plugin::BEGIN@2.5 at line 9 # spent 93µs making 1 call to Foswiki::Plugins::CommentPlugin::BEGIN@9
# spent 74µs making 1 call to Assert::import |
10 | 2 | 77µs | 2 | 1.21ms | # spent 619µs (32+587) within Foswiki::Plugins::CommentPlugin::BEGIN@10 which was called:
# once (32µs+587µs) by Foswiki::Plugin::BEGIN@2.5 at line 10 # spent 619µs making 1 call to Foswiki::Plugins::CommentPlugin::BEGIN@10
# spent 587µs making 1 call to Error::import |
11 | |||||
12 | 2 | 40µs | 1 | 10µs | # spent 10µs within Foswiki::Plugins::CommentPlugin::BEGIN@12 which was called:
# once (10µs+0s) by Foswiki::Plugin::BEGIN@2.5 at line 12 # spent 10µs making 1 call to Foswiki::Plugins::CommentPlugin::BEGIN@12 |
13 | 2 | 990µs | 1 | 10µs | # spent 10µs within Foswiki::Plugins::CommentPlugin::BEGIN@13 which was called:
# once (10µs+0s) by Foswiki::Plugin::BEGIN@2.5 at line 13 # spent 10µs making 1 call to Foswiki::Plugins::CommentPlugin::BEGIN@13 |
14 | |||||
15 | 1 | 2µs | our $VERSION = '$Rev$'; | ||
16 | 1 | 1µs | our $RELEASE = '26 Oct 2011'; | ||
17 | 1 | 1µs | our $SHORTDESCRIPTION = | ||
18 | 'Quickly post comments to a page without an edit/save cycle'; | ||||
19 | 1 | 1µs | our $NO_PREFS_IN_TOPIC = 1; | ||
20 | |||||
21 | # Reset when the plugin is reset, this counter counts the instances of the | ||||
22 | # %COMMENT macro and indexes them. | ||||
23 | 1 | 1µs | our $commentIndex; | ||
24 | |||||
25 | # spent 3.23ms (46µs+3.18) within Foswiki::Plugins::CommentPlugin::initPlugin which was called:
# once (46µs+3.18ms) by Foswiki::Plugin::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm:235] at line 228 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm | ||||
26 | |||||
27 | 6 | 43µs | my ( $topic, $web, $user, $installWeb ) = @_; | ||
28 | $commentIndex = 0; | ||||
29 | |||||
30 | 1 | 87µs | Foswiki::Func::registerTagHandler( 'COMMENT', \&_COMMENT ); # spent 87µs making 1 call to Foswiki::Func::registerTagHandler | ||
31 | 1 | 3.09ms | Foswiki::Func::registerRESTHandler( # spent 3.09ms making 1 call to Foswiki::Func::registerRESTHandler | ||
32 | 'comment', \&_restSave, | ||||
33 | |||||
34 | # validate => 1, # TODO: needs javascript work | ||||
35 | http_allow => 'POST' | ||||
36 | ); | ||||
37 | |||||
38 | 1 | 5µs | if ( (DEBUG) # spent 5µs making 1 call to Assert::ASSERTS_OFF | ||
39 | && $web eq $Foswiki::cfg{SystemWebName} | ||||
40 | && $topic eq 'InstalledPlugins' ) | ||||
41 | { | ||||
42 | |||||
43 | # Compilation check | ||||
44 | require Foswiki::Plugins::CommentPlugin::Comment; | ||||
45 | } | ||||
46 | return 1; | ||||
47 | } | ||||
48 | |||||
49 | # spent 442ms (3.23+438) within Foswiki::Plugins::CommentPlugin::_COMMENT which was called:
# once (3.23ms+438ms) by Foswiki::Func::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Func.pm:573] at line 568 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Func.pm | ||||
50 | 7 | 202µs | my ( $session, $params, $topic, $web ) = @_; | ||
51 | |||||
52 | # Indexing each macro instance | ||||
53 | $params->{comment_index} = $commentIndex++; | ||||
54 | |||||
55 | # Check the context has 'view' script | ||||
56 | 1 | 13µs | my $context = Foswiki::Func::getContext(); # spent 13µs making 1 call to Foswiki::Func::getContext | ||
57 | my $disabled = ''; | ||||
58 | if ( $context->{command_line} ) { | ||||
59 | $disabled = Foswiki::Func::expandCommonVariables( | ||||
60 | '%MAKETEXT{"Commenting is disabled while running from the command line"}%' | ||||
61 | ); | ||||
62 | } | ||||
63 | elsif ( !$context->{view} ) { | ||||
64 | $disabled = Foswiki::Func::expandCommonVariables( | ||||
65 | '%MAKETEXT{"Commenting is disabled when not in view context"}%'); | ||||
66 | } | ||||
67 | elsif ( | ||||
68 | !( | ||||
69 | $Foswiki::cfg{Plugins}{CommentPlugin}{GuestCanComment} | ||||
70 | || $context->{authenticated} | ||||
71 | ) | ||||
72 | ) | ||||
73 | { | ||||
74 | $disabled = Foswiki::Func::expandCommonVariables( | ||||
75 | '%MAKETEXT{"Commenting is disabled while not logged in"}%'); | ||||
76 | } | ||||
77 | |||||
78 | require Foswiki::Plugins::CommentPlugin::Comment; | ||||
79 | |||||
80 | 1 | 437ms | Foswiki::Plugins::CommentPlugin::Comment::prompt( $params, $web, $topic, # spent 437ms making 1 call to Foswiki::Plugins::CommentPlugin::Comment::prompt | ||
81 | $disabled ); | ||||
82 | } | ||||
83 | |||||
84 | # REST handler for save operator. We use a REST handler because we need | ||||
85 | # to be able to bypass the permissions checking that the save script | ||||
86 | # would do. We handle the return in several different ways; first, if | ||||
87 | # everything is OK, we set a 200 status and drop back to allow any | ||||
88 | # endPoint to be handled. Second, if we get an exception, and the | ||||
89 | # 'comment_ajax' parameter is set, we return a 500 status. If the | ||||
90 | # parameter is not set, we pass the exception on to the UI package. | ||||
91 | |||||
92 | sub _restSave { | ||||
93 | my $session = shift; | ||||
94 | my $response = $session->{response}; | ||||
95 | my $query = Foswiki::Func::getCgiQuery(); | ||||
96 | my ( $web, $topic ) = | ||||
97 | Foswiki::Func::normalizeWebTopicName( undef, $query->param('topic') ); | ||||
98 | |||||
99 | try { | ||||
100 | require Foswiki::Plugins::CommentPlugin::Comment; | ||||
101 | |||||
102 | my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic ); | ||||
103 | |||||
104 | # The save function does access control checking | ||||
105 | $text = | ||||
106 | Foswiki::Plugins::CommentPlugin::Comment::save( $text, $web, $topic ); | ||||
107 | |||||
108 | Foswiki::Func::saveTopic( $web, $topic, $meta, $text, | ||||
109 | { ignorepermissions => 1 } ); | ||||
110 | |||||
111 | $response->header( -status => 200 ); | ||||
112 | $response->body("$web.$topic"); | ||||
113 | } | ||||
114 | catch Foswiki::AccessControlException with { | ||||
115 | if ( $query->param('comment_ajax') ) { | ||||
116 | $response->header( -status => 404 ); | ||||
117 | $response->body(shift); | ||||
118 | } | ||||
119 | else { | ||||
120 | shift->throw; | ||||
121 | } | ||||
122 | } | ||||
123 | otherwise { | ||||
124 | if ( $query->param('comment_ajax') ) { | ||||
125 | $response->header( -status => 500 ); | ||||
126 | $response->body(shift); | ||||
127 | } | ||||
128 | else { | ||||
129 | shift->throw; | ||||
130 | } | ||||
131 | }; | ||||
132 | return undef; | ||||
133 | } | ||||
134 | |||||
135 | 1 | 6µs | 1; | ||
136 | __END__ |