← 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/TinyMCEPlugin.pm
StatementsExecuted 25 statements in 1.02ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11126µs74µsFoswiki::Plugins::TinyMCEPlugin::::initPluginFoswiki::Plugins::TinyMCEPlugin::initPlugin
11114µs27µsFoswiki::Plugins::TinyMCEPlugin::::BEGIN@5Foswiki::Plugins::TinyMCEPlugin::BEGIN@5
11110µs26µsFoswiki::Plugins::TinyMCEPlugin::::BEGIN@8Foswiki::Plugins::TinyMCEPlugin::BEGIN@8
11110µs16µsFoswiki::Plugins::TinyMCEPlugin::::BEGIN@6Foswiki::Plugins::TinyMCEPlugin::BEGIN@6
1119µs28µsFoswiki::Plugins::TinyMCEPlugin::::BEGIN@10Foswiki::Plugins::TinyMCEPlugin::BEGIN@10
1115µs5µ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
5234µs240µs
# spent 27µs (14+13) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@5 which was called: # once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.35 at line 5
use strict;
# spent 27µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@5 # spent 13µs making 1 call to strict::import
6225µs222µs
# spent 16µs (10+6) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@6 which was called: # once (10µs+6µs) by Foswiki::Plugin::BEGIN@2.35 at line 6
use warnings;
# spent 16µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@6 # spent 6µs making 1 call to warnings::import
7
8226µs243µs
# spent 26µs (10+16) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@8 which was called: # once (10µs+16µs) by Foswiki::Plugin::BEGIN@2.35 at line 8
use Assert;
# spent 26µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@8 # spent 16µs making 1 call to Assert::import
9
10383µs352µs
# spent 28µs (9+19) within Foswiki::Plugins::TinyMCEPlugin::BEGIN@10 which was called: # once (9µs+19µs) by Foswiki::Plugin::BEGIN@2.35 at line 10
use version; our $VERSION = version->declare("v1.2.9");
# spent 28µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@10 # spent 19µs making 1 call to version::import # spent 5µs making 1 call to version::vxs::declare
111300nsour $RELEASE = '1.2.9';
121200nsour $SHORTDESCRIPTION = 'Integration of the Tiny MCE WYSIWYG Editor';
131200nsour $NO_PREFS_IN_TOPIC = 1;
14
152820µs15µs
# spent 5µs within Foswiki::Plugins::TinyMCEPlugin::BEGIN@15 which was called: # once (5µs+0s) by Foswiki::Plugin::BEGIN@2.35 at line 15
use Foswiki::Func ();
# spent 5µs making 1 call to Foswiki::Plugins::TinyMCEPlugin::BEGIN@15
16
1714µsour %defaultINIT_BROWSER = (
18 MSIE => '',
19 OPERA => '',
20 GECKO => '"gecko_spellcheck" : true',
21 SAFARI => '',
22 CHROME => '',
23);
241200nsmy $query;
25
26# Info about browser type
271200nsmy %browserInfo;
28
29
# spent 74µs (26+48) within Foswiki::Plugins::TinyMCEPlugin::initPlugin which was called: # once (26µs+48µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm
sub initPlugin {
3012µs17µs $query = Foswiki::Func::getCgiQuery();
# spent 7µs making 1 call to Foswiki::Func::getCgiQuery
311500ns return 0 unless $query;
3217µs 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 }
3812µs 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
4615µs141µs my $ua = $query->user_agent();
# spent 41µs making 1 call to Foswiki::Request::userAgent
471300ns if ($ua) {
48 $browserInfo{isMSIE} = $ua =~ /MSIE/;
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/;
54 $browserInfo{isGecko} = $ua =~ /Gecko/; # Will also be true on Safari
55 $browserInfo{isSafari} = $ua =~ /Safari/; # Will also be true on Chrome
56 $browserInfo{isOpera} = $ua =~ /Opera/;
57 $browserInfo{isChrome} = $ua =~ /Chrome/;
58 $browserInfo{isMac} = $ua =~ /Mac/;
59 $browserInfo{isNS7} = $ua =~ /Netscape\/7/;
60 $browserInfo{isNS71} = $ua =~ /Netscape\/7.1/;
61 }
62
6315µs 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
20816µs1;
209
210__END__