← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:26:49 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/TinyMCEPlugin.pm
StatementsExecuted 36 statements in 1.93ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111200µs491µsFoswiki::Plugins::TinyMCEPlugin::::initPluginFoswiki::Plugins::TinyMCEPlugin::initPlugin
88133µs33µsFoswiki::Plugins::TinyMCEPlugin::::CORE:matchFoswiki::Plugins::TinyMCEPlugin::CORE:match (opcode)
11125µs33µsFoswiki::Plugins::TinyMCEPlugin::::BEGIN@5Foswiki::Plugins::TinyMCEPlugin::BEGIN@5
11117µs62µsFoswiki::Plugins::TinyMCEPlugin::::BEGIN@8Foswiki::Plugins::TinyMCEPlugin::BEGIN@8
11116µs34µsFoswiki::Plugins::TinyMCEPlugin::::BEGIN@6Foswiki::Plugins::TinyMCEPlugin::BEGIN@6
11110µs10µsFoswiki::Plugins::TinyMCEPlugin::::BEGIN@15Foswiki::Plugins::TinyMCEPlugin::BEGIN@15
0000s0sFoswiki::Plugins::TinyMCEPlugin::::_notAvailableFoswiki::Plugins::TinyMCEPlugin::_notAvailable
0000s0sFoswiki::Plugins::TinyMCEPlugin::::beforeEditHandlerFoswiki::Plugins::TinyMCEPlugin::beforeEditHandler
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2
3package Foswiki::Plugins::TinyMCEPlugin;
4
5246µs240µs
# spent 33µs (25+7) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@5 which was called: # once (25µs+7µs) by Foswiki::Plugin::BEGIN@2.18 at line 5
use strict;
# spent 33µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@5 # spent 7µs making 1 call to strict::import
6244µs252µs
# spent 34µs (16+18) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@6 which was called: # once (16µs+18µs) by Foswiki::Plugin::BEGIN@2.18 at line 6
use warnings;
# spent 34µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@6 # spent 18µs making 1 call to warnings::import
7
8298µs2108µs
# spent 62µs (17+46) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@8 which was called: # once (17µs+46µs) by Foswiki::Plugin::BEGIN@2.18 at line 8
use Assert;
# spent 62µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@8 # spent 45µs making 1 call to Assert::import
9
1012µsour $VERSION = '$Rev$';
1111µsour $RELEASE = '1.2.3';
1211µsour $SHORTDESCRIPTION = 'Integration of the Tiny MCE WYSIWYG Editor';
1311µsour $NO_PREFS_IN_TOPIC = 1;
14
1521.50ms110µs
# spent 10µs within Foswiki::Plugins::TinyMCEPlugin::BEGIN@15 which was called: # once (10µs+0s) by Foswiki::Plugin::BEGIN@2.18 at line 15
use Foswiki::Func ();
# spent 10µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@15
16
1717µsour %defaultINIT_BROWSER = (
18 MSIE => '',
19 OPERA => '',
20 GECKO => '"gecko_spellcheck" : true',
21 SAFARI => '',
22 CHROME => '',
23);
2411µsmy $query;
25
26# Info about browser type
2711µsmy %browserInfo;
28
29
# spent 491µs (200+292) within Foswiki::Plugins::TinyMCEPlugin::initPlugin which was called: # once (200µs+292µs) 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
sub initPlugin {
30762µs134µs $query = Foswiki::Func::getCgiQuery();
# spent 34µs making 1 call to Foswiki::Func::getCgiQuery
31 return 0 unless $query;
32 unless ( $Foswiki::cfg{Plugins}{WysiwygPlugin}{Enabled} ) {
33 Foswiki::Func::writeWarning(
34"TinyMCEPlugin is enabled but WysiwygPlugin is not. Both must be installed and enabled for TinyMCE."
35 );
36 return 0;
37 }
38 unless ( $Foswiki::cfg{Plugins}{JQueryPlugin}{Enabled} ) {
39 Foswiki::Func::writeWarning(
40"TinyMCEPlugin is enabled but JQueryPlugin is not. Both must be installed and enabled for TinyMCE."
41 );
42 return 0;
43 }
44
45 # Identify the browser from the user agent string
461225µs my $ua = $query->user_agent();
# spent 225µs making 1 call to Foswiki::Request::userAgent
4713156µs if ($ua) {
4819µs $browserInfo{isMSIE} = $ua =~ /MSIE/;
# spent 9µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::CORE:match
49 $browserInfo{isMSIE5} = $browserInfo{isMSIE} && ( $ua =~ /MSIE 5/ );
50 $browserInfo{isMSIE5_0} = $browserInfo{isMSIE} && ( $ua =~ /MSIE 5.0/ );
51 $browserInfo{isMSIE6} = $browserInfo{isMSIE} && $ua =~ /MSIE 6/;
52 $browserInfo{isMSIE7} = $browserInfo{isMSIE} && $ua =~ /MSIE 7/;
53 $browserInfo{isMSIE8} = $browserInfo{isMSIE} && $ua =~ /MSIE 8/;
5418µs $browserInfo{isGecko} = $ua =~ /Gecko/; # Will also be true on Safari
# spent 8µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::CORE:match
5513µs $browserInfo{isSafari} = $ua =~ /Safari/; # Will also be true on Chrome
# spent 3µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::CORE:match
5613µs $browserInfo{isOpera} = $ua =~ /Opera/;
# spent 3µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::CORE:match
5713µs $browserInfo{isChrome} = $ua =~ /Chrome/;
# spent 3µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::CORE:match
5813µs $browserInfo{isMac} = $ua =~ /Mac/;
# spent 3µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::CORE:match
5912µs $browserInfo{isNS7} = $ua =~ /Netscape\/7/;
# spent 2µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::CORE:match
6013µs $browserInfo{isNS71} = $ua =~ /Netscape\/7.1/;
# spent 3µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::CORE:match
61 }
62
63 return 1;
64}
65
66sub _notAvailable {
67 for my $c (qw(TINYMCEPLUGIN_DISABLE NOWYSIWYG)) {
68 return "Disabled by * Set $c = "
69 . Foswiki::Func::getPreferencesValue($c)
70 if Foswiki::Func::getPreferencesFlag($c);
71 }
72
73 # Disable TinyMCE if we are on a specialised edit skin
74 my $skin = Foswiki::Func::getPreferencesValue('WYSIWYGPLUGIN_WYSIWYGSKIN');
75 return "$skin is active"
76 if ( $skin && Foswiki::Func::getSkin() =~ /\b$skin\b/o );
77
78 return "No browser" unless $query;
79
80 return "Disabled by URL parameter" if $query->param('nowysiwyg');
81
82 # Check the client browser to see if it is blacklisted
83 my $ua = Foswiki::Func::getPreferencesValue('TINYMCEPLUGIN_BAD_BROWSERS')
84 || '(?i-xsm:Konqueror)';
85 return 'Unsupported browser: ' . $query->user_agent()
86 if $ua && $query->user_agent() && $query->user_agent() =~ /$ua/;
87
88 # This should only ever happen on Foswiki 1.0.9 and earlier
89 return 'TinyMCEPlugin requires ZonePlugin to be installed and enabled'
90 unless ( defined &Foswiki::Func::addToZone );
91
92 return 0;
93}
94
95sub beforeEditHandler {
96 my ( $text, $topic, $web ) = @_;
97
98 my $mess = _notAvailable();
99 if ($mess) {
100 if ( ( $mess !~ /^Disabled/ || DEBUG )
101 && defined &Foswiki::Func::setPreferencesValue )
102 {
103 Foswiki::Func::setPreferencesValue( 'EDITOR_MESSAGE',
104 'WYSIWYG could not be started: ' . $mess );
105 }
106 return;
107 }
108 if ( defined &Foswiki::Func::setPreferencesValue ) {
109 Foswiki::Func::setPreferencesValue( 'EDITOR_HELP', 'TinyMCEQuickHelp' );
110 }
111
112 my $initTopic =
113 Foswiki::Func::getPreferencesValue('TINYMCEPLUGIN_INIT_TOPIC')
114 || $Foswiki::cfg{SystemWebName} . '.TinyMCEPlugin';
115 my $init = Foswiki::Func::getPreferencesValue('TINYMCEPLUGIN_INIT')
116 || Foswiki::Func::expandCommonVariables(
117 '%INCLUDE{"'
118 . $initTopic
119 . '" section="TINYMCEPLUGIN_INIT" warn="off"}%',
120 $topic, $web
121 );
122 my $browser = '';
123
124 # The order of these conditions is important, because browsers
125 # spoof eachother
126 if ( $browserInfo{isChrome} ) {
127 $browser = 'CHROME';
128 }
129 elsif ( $browserInfo{isSafari} ) {
130 $browser = 'SAFARI';
131 }
132 elsif ( $browserInfo{isOpera} ) {
133 $browser = 'OPERA';
134 }
135 elsif ( $browserInfo{isGecko} ) {
136 $browser = 'GECKO';
137 }
138 elsif ( $browserInfo{isMSIE} ) {
139 $browser = 'MSIE';
140 }
141 if ($browser) {
142 my $settings =
143 Foswiki::Func::getPreferencesValue( 'TINYMCEPLUGIN_INIT_' . $browser )
144 || $defaultINIT_BROWSER{$browser};
145 if ($settings) {
146 $init =
147 join( ',', ( split( ',', $init ), split( ',', $settings ) ) );
148 }
149 }
150
151 require Foswiki::Plugins::WysiwygPlugin;
152
153 $mess = Foswiki::Plugins::WysiwygPlugin::notWysiwygEditable($text);
154 if ($mess) {
155 if ( defined &Foswiki::Func::setPreferencesValue ) {
156 Foswiki::Func::setPreferencesValue( 'EDITOR_MESSAGE',
157 'WYSIWYG could not be started: ' . $mess );
158 Foswiki::Func::setPreferencesValue( 'EDITOR_HELP', undef );
159 }
160 return;
161 }
162
163 my $USE_SRC = '';
164 if ( Foswiki::Func::getPreferencesValue('TINYMCEPLUGIN_DEBUG') ) {
165 $USE_SRC = '_src';
166 }
167
168 # Add the Javascript for the editor. When it starts up the editor will
169 # use a REST call to the WysiwygPlugin tml2html REST handler to convert
170 # the textarea content from TML to HTML.
171 my $pluginURL = '%PUBURLPATH%/%SYSTEMWEB%/TinyMCEPlugin';
172 my $tmceURL = $pluginURL . '/tinymce/jscripts/tiny_mce';
173
174 # URL-encode the version number to include in the .js URLs, so that
175 # the browser re-fetches the .js when this plugin is upgraded.
176 my $encodedVersion = $VERSION;
177
178 # SMELL: This regex (and the one applied to $metainit, above)
179 # duplicates Foswiki::urlEncode(), but Foswiki::Func.pm does not
180 # expose that function, so plugins may not use it
181 $encodedVersion =~
182 s/([^0-9a-zA-Z-_.:~!*'\/%])/'%'.sprintf('%02x',ord($1))/ge;
183
184 # Inline JS to set config? Heresy! Well, we were encoding into <meta tags
185 # but this caused problems with non-8bit encodings (See Item9973). Given
186 # that we blindly eval'd the unescaped TINYMCEPLUGIN_INIT anyway, PaulHarvey
187 # doesn't think it was any more secure anyway. Alternative is to use
188 # https://github.com/douglascrockford/JSON-js lib
189 my $scripts = <<"SCRIPT";
190<script type="text/javascript" src="$tmceURL/tiny_mce$USE_SRC.js?v=$encodedVersion"></script>
191<script type="text/javascript" src="$pluginURL/foswiki_tiny$USE_SRC.js?v=$encodedVersion"></script>
192<script type="text/javascript">
193FoswikiTiny.init = {
194 $init
195};</script>
196<script type="text/javascript" src="$pluginURL/foswiki$USE_SRC.js?v=$encodedVersion"></script>
197SCRIPT
198
199 Foswiki::Func::addToZone( 'script', 'TinyMCEPlugin', $scripts,
200 'JQUERYPLUGIN::FOSWIKI' );
201
202 # See %SYSTEMWEB%.IfStatements for a description of this context id.
203 Foswiki::Func::getContext()->{textareas_hijacked} = 1;
204
205 return;
206}
207
20819µs1;
209
210__END__
 
# spent 33µs within Foswiki::Plugins::TinyMCEPlugin::CORE:match which was called 8 times, avg 4µs/call: # once (9µs+0s) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 48 # once (8µs+0s) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 54 # once (3µs+0s) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 56 # once (3µs+0s) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 55 # once (3µs+0s) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 58 # once (3µs+0s) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 60 # once (3µs+0s) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 57 # once (2µs+0s) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 59
sub Foswiki::Plugins::TinyMCEPlugin::CORE:match; # opcode