Filename | /var/www/foswiki11/lib/Foswiki/Plugins/EditTablePlugin.pm |
Statements | Executed 61 statements in 1.32ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
13 | 1 | 1 | 162µs | 162µs | commonTagsHandler | Foswiki::Plugins::EditTablePlugin::
7 | 1 | 1 | 84µs | 84µs | beforeCommonTagsHandler | Foswiki::Plugins::EditTablePlugin::
5 | 1 | 1 | 53µs | 53µs | postRenderingHandler | Foswiki::Plugins::EditTablePlugin::
1 | 1 | 1 | 41µs | 183µs | initPlugin | Foswiki::Plugins::EditTablePlugin::
1 | 1 | 1 | 14µs | 20µs | BEGIN@8 | Foswiki::Plugins::EditTablePlugin::
1 | 1 | 1 | 14µs | 27µs | BEGIN@7 | Foswiki::Plugins::EditTablePlugin::
0 | 0 | 0 | 0s | 0s | addEditModeHeadersToHead | Foswiki::Plugins::EditTablePlugin::
0 | 0 | 0 | 0s | 0s | addJavaScriptInterfaceDisabledToHead | Foswiki::Plugins::EditTablePlugin::
0 | 0 | 0 | 0s | 0s | addViewModeHeadersToHead | Foswiki::Plugins::EditTablePlugin::
0 | 0 | 0 | 0s | 0s | decodeValue | Foswiki::Plugins::EditTablePlugin::
0 | 0 | 0 | 0s | 0s | encodeValue | Foswiki::Plugins::EditTablePlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | # | ||||
3 | # This is the EditTablePlugin used to edit tables in place. | ||||
4 | |||||
5 | package Foswiki::Plugins::EditTablePlugin; | ||||
6 | |||||
7 | 2 | 29µs | 2 | 41µs | # spent 27µs (14+14) within Foswiki::Plugins::EditTablePlugin::BEGIN@7 which was called:
# once (14µs+14µs) by Foswiki::Plugin::BEGIN@2.12 at line 7 # spent 27µs making 1 call to Foswiki::Plugins::EditTablePlugin::BEGIN@7
# spent 14µs making 1 call to strict::import |
8 | 2 | 983µs | 2 | 26µs | # spent 20µs (14+6) within Foswiki::Plugins::EditTablePlugin::BEGIN@8 which was called:
# once (14µs+6µs) by Foswiki::Plugin::BEGIN@2.12 at line 8 # spent 20µs making 1 call to Foswiki::Plugins::EditTablePlugin::BEGIN@8
# spent 6µs making 1 call to warnings::import |
9 | |||||
10 | 1 | 800ns | our $VERSION = '4.43'; | ||
11 | |||||
12 | # Please note that the second is now two digit. | ||||
13 | # Someone increased 4.22 to 4.3 which is not correct. | ||||
14 | 1 | 200ns | our $RELEASE = '4.43'; | ||
15 | |||||
16 | 1 | 200ns | our $pluginName = 'EditTablePlugin'; | ||
17 | 1 | 200ns | our $ENCODE_START = '--EditTableEncodeStart--'; | ||
18 | 1 | 200ns | our $ENCODE_END = '--EditTableEncodeEnd--'; | ||
19 | 1 | 200ns | our $ASSET_URL = '%PUBURL%/%SYSTEMWEB%/EditTablePlugin'; | ||
20 | 1 | 200ns | our $NO_PREFS_IN_TOPIC = 1; | ||
21 | 1 | 200ns | our $SHORTDESCRIPTION = | ||
22 | 'Edit tables using edit fields, date pickers and drop down boxes'; | ||||
23 | 1 | 0s | our $web; | ||
24 | 1 | 100ns | our $topic; | ||
25 | 1 | 100ns | our $user; | ||
26 | 1 | 100ns | our $debug; | ||
27 | 1 | 0s | our $usesJavascriptInterface; | ||
28 | 1 | 100ns | our $viewModeHeaderDone; | ||
29 | 1 | 100ns | our $editModeHeaderDone; | ||
30 | 1 | 100ns | our $recursionBlock; | ||
31 | |||||
32 | =pod | ||||
33 | |||||
34 | =cut | ||||
35 | |||||
36 | # spent 183µs (41+142) within Foswiki::Plugins::EditTablePlugin::initPlugin which was called:
# once (41µs+142µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm | ||||
37 | 1 | 4µs | ( $topic, $web, $user ) = @_; | ||
38 | |||||
39 | # check for Plugins.pm versions | ||||
40 | 1 | 21µs | 1 | 13µs | if ( $Foswiki::Plugins::VERSION < 1.026 ) { # spent 13µs making 1 call to version::vxs::VCMP |
41 | Foswiki::Func::writeWarning( | ||||
42 | "Version mismatch between EditTablePlugin and Plugins.pm"); | ||||
43 | return 0; | ||||
44 | } | ||||
45 | |||||
46 | 1 | 5µs | 1 | 17µs | my $query = Foswiki::Func::getCgiQuery(); # spent 17µs making 1 call to Foswiki::Func::getCgiQuery |
47 | 1 | 900ns | if ( !$query ) { | ||
48 | return 0; | ||||
49 | } | ||||
50 | |||||
51 | # Get plugin debug flag | ||||
52 | 1 | 3µs | 1 | 49µs | $debug = Foswiki::Func::getPreferencesFlag('EDITTABLEPLUGIN_DEBUG'); # spent 49µs making 1 call to Foswiki::Func::getPreferencesFlag |
53 | 1 | 2µs | 1 | 63µs | $usesJavascriptInterface = # spent 63µs making 1 call to Foswiki::Func::getPreferencesFlag |
54 | Foswiki::Func::getPreferencesFlag('EDITTABLEPLUGIN_JAVASCRIPTINTERFACE') | ||||
55 | || 1; | ||||
56 | 1 | 500ns | $viewModeHeaderDone = 0; | ||
57 | 1 | 800ns | $editModeHeaderDone = 0; | ||
58 | |||||
59 | # Plugin correctly initialized | ||||
60 | 1 | 300ns | Foswiki::Func::writeDebug( | ||
61 | "- Foswiki::Plugins::EditTablePlugin::initPlugin( $web.$topic ) is OK") | ||||
62 | if $debug; | ||||
63 | |||||
64 | 1 | 7µs | return 1; | ||
65 | } | ||||
66 | |||||
67 | =pod | ||||
68 | |||||
69 | Calls EditTablePlugin::Core::parseTables to lift out tables and put them back later. | ||||
70 | But because tables inside INCLUDEd topics won't expand - beforeCommonTagsHandler is called only once for the parent topic - parseTables needs to get called for included topics separatedly in commonTagsHandler. | ||||
71 | |||||
72 | We cannot do table parsing in commonTagsHandler because by then the TML has been rendered, and tags like %ICON{pdf}% rendered to their <img ... /> equivalent. | ||||
73 | |||||
74 | =cut | ||||
75 | |||||
76 | # spent 84µs within Foswiki::Plugins::EditTablePlugin::beforeCommonTagsHandler which was called 7 times, avg 12µs/call:
# 7 times (84µs+0s) by Foswiki::Plugin::invoke at line 294 of /var/www/foswiki11/lib/Foswiki/Plugin.pm, avg 12µs/call | ||||
77 | 7 | 74µs | return unless $_[0] =~ /%EDIT(?:TABLE|CELL){.*}%/; | ||
78 | Foswiki::Func::writeDebug( | ||||
79 | "EditTablePlugin::beforeCommonTagsHandler( $web.$topic )") | ||||
80 | if $debug; | ||||
81 | |||||
82 | my $query = Foswiki::Func::getCgiQuery(); | ||||
83 | my $tableNr = $query->param('ettablenr'); | ||||
84 | my $isEditing = defined $query->param('etedit') | ||||
85 | && defined $tableNr; | ||||
86 | |||||
87 | require Foswiki::Plugins::EditTablePlugin::Core; | ||||
88 | Foswiki::Plugins::EditTablePlugin::Core::init(); | ||||
89 | if ($isEditing) { | ||||
90 | Foswiki::Plugins::EditTablePlugin::Core::parseTables( $_[0], $_[1], | ||||
91 | $_[2] ); | ||||
92 | } | ||||
93 | } | ||||
94 | |||||
95 | =pod | ||||
96 | |||||
97 | Calls EditTablePlugin::Core::parseTables for INCLUDEd topics. | ||||
98 | |||||
99 | =cut | ||||
100 | |||||
101 | # spent 162µs within Foswiki::Plugins::EditTablePlugin::commonTagsHandler which was called 13 times, avg 12µs/call:
# 13 times (162µs+0s) by Foswiki::Plugin::invoke at line 294 of /var/www/foswiki11/lib/Foswiki/Plugin.pm, avg 12µs/call | ||||
102 | 13 | 137µs | return unless $_[0] =~ /%EDIT(?:TABLE|CELL|TABLESTUB){.*}%/; | ||
103 | |||||
104 | Foswiki::Func::writeDebug( | ||||
105 | "EditTablePlugin::commonTagsHandler( $web.$topic )") | ||||
106 | if $debug; | ||||
107 | |||||
108 | return if $recursionBlock; | ||||
109 | $recursionBlock = 1; | ||||
110 | addViewModeHeadersToHead(); | ||||
111 | require Foswiki::Plugins::EditTablePlugin::Core; | ||||
112 | |||||
113 | Foswiki::Plugins::EditTablePlugin::Core::initIncludedTopic(); | ||||
114 | Foswiki::Plugins::EditTablePlugin::Core::parseTables( $_[0], $_[1], $_[2] ); | ||||
115 | Foswiki::Plugins::EditTablePlugin::Core::process( $_[0], $_[1], $_[2], | ||||
116 | $topic, $web ); | ||||
117 | $recursionBlock = 0; | ||||
118 | } | ||||
119 | |||||
120 | =pod | ||||
121 | |||||
122 | =cut | ||||
123 | |||||
124 | # spent 53µs within Foswiki::Plugins::EditTablePlugin::postRenderingHandler which was called 5 times, avg 11µs/call:
# 5 times (53µs+0s) by Foswiki::Plugin::invoke at line 294 of /var/www/foswiki11/lib/Foswiki/Plugin.pm, avg 11µs/call | ||||
125 | 5 | 2µs | Foswiki::Func::writeDebug( | ||
126 | "EditTablePlugin::postRenderingHandler( $web.$topic )") | ||||
127 | if $debug; | ||||
128 | 5 | 43µs | $_[0] =~ s/$ENCODE_START(.*?)$ENCODE_END/decodeValue($1)/ges; | ||
129 | } | ||||
130 | |||||
131 | =pod | ||||
132 | |||||
133 | =cut | ||||
134 | |||||
135 | sub encodeValue { | ||||
136 | |||||
137 | # FIXME: *very* crude encoding to escape Wiki rendering inside form fields | ||||
138 | # also prevents urls to get expanded to links | ||||
139 | $_[0] =~ s/\./%dot%/gs; | ||||
140 | $_[0] =~ s/(.)/\.$1/gs; | ||||
141 | |||||
142 | # convert <br /> markup to unicode linebreak character for text areas | ||||
143 | $_[0] =~ s/.<.b.r. .\/.>/ /gs; | ||||
144 | $_[0] = $ENCODE_START . $_[0] . $ENCODE_END; | ||||
145 | } | ||||
146 | |||||
147 | =pod | ||||
148 | |||||
149 | =cut | ||||
150 | |||||
151 | sub decodeValue { | ||||
152 | my ($theText) = @_; | ||||
153 | |||||
154 | $theText =~ s/\.(.)/$1/gs; | ||||
155 | $theText =~ s/%dot%/\./gs; | ||||
156 | $theText =~ s/\&([^#a-z])/&$1/g; # escape non-entities | ||||
157 | $theText =~ s/</\</g; # change < to entity | ||||
158 | $theText =~ s/>/\>/g; # change > to entity | ||||
159 | $theText =~ s/\"/\"/g; # change " to entity | ||||
160 | return $theText; | ||||
161 | } | ||||
162 | |||||
163 | =begin TML | ||||
164 | |||||
165 | Style sheet for table in view mode | ||||
166 | |||||
167 | =cut | ||||
168 | |||||
169 | sub addViewModeHeadersToHead { | ||||
170 | return if $viewModeHeaderDone; | ||||
171 | |||||
172 | $viewModeHeaderDone = 1; | ||||
173 | |||||
174 | my $header = <<'EOF'; | ||||
175 | <style type="text/css" media="all"> | ||||
176 | @import url("%PUBURL%/%SYSTEMWEB%/EditTablePlugin/edittable.css"); | ||||
177 | </style> | ||||
178 | EOF | ||||
179 | Foswiki::Func::addToZone( 'head', 'EditTablePlugin/edittable.css', | ||||
180 | $header ); | ||||
181 | } | ||||
182 | |||||
183 | =begin TML | ||||
184 | |||||
185 | Style sheet and javascript for table in edit mode | ||||
186 | |||||
187 | =cut | ||||
188 | |||||
189 | sub addEditModeHeadersToHead { | ||||
190 | my ( $tableNr, $paramJavascriptInterface ) = @_; | ||||
191 | return if $editModeHeaderDone; | ||||
192 | return | ||||
193 | if !$usesJavascriptInterface && ( $paramJavascriptInterface ne 'on' ); | ||||
194 | |||||
195 | $editModeHeaderDone = 1; | ||||
196 | |||||
197 | my $formName = "edittable$tableNr"; | ||||
198 | my $header = ""; | ||||
199 | $header .= | ||||
200 | '<meta name="EDITTABLEPLUGIN_FormName" content="' . $formName . '" />'; | ||||
201 | $header .= "\n" | ||||
202 | . '<meta name="EDITTABLEPLUGIN_EditTableUrl" content="' | ||||
203 | . $ASSET_URL . '" />'; | ||||
204 | |||||
205 | Foswiki::Func::addToZone( 'head', 'EditTablePlugin/Meta', $header ); | ||||
206 | addViewModeHeadersToHead(); | ||||
207 | Foswiki::Func::addToZone( 'script', 'EditTablePlugin/edittable.js', <<JS); | ||||
208 | <script type="text/javascript" src="%PUBURL%/%SYSTEMWEB%/EditTablePlugin/edittable.js"></script> | ||||
209 | JS | ||||
210 | } | ||||
211 | |||||
212 | =begin TML | ||||
213 | |||||
214 | If param javscriptinterface="off", adds field to html meta. | ||||
215 | |||||
216 | =cut | ||||
217 | |||||
218 | sub addJavaScriptInterfaceDisabledToHead { | ||||
219 | my ($tableNr) = @_; | ||||
220 | |||||
221 | my $tableId = "edittable$tableNr"; | ||||
222 | my $header = ""; | ||||
223 | $header .= | ||||
224 | '<meta name="EDITTABLEPLUGIN_NO_JAVASCRIPTINTERFACE_EditTableId" content="' | ||||
225 | . $tableId . '" />'; | ||||
226 | $header .= "\n"; | ||||
227 | Foswiki::Func::addToZone( 'head', 'EDITTABLEPLUGIN_NO_JAVASCRIPTINTERFACE', | ||||
228 | $header ); | ||||
229 | } | ||||
230 | |||||
231 | 1 | 6µs | 1; | ||
232 | __END__ |