Filename | /var/www/foswiki11/lib/Foswiki/Plugins/ExtendedWebListPlugin.pm |
Statements | Executed 675 statements in 1.90ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.19ms | 8.35s | _EXTENDEDWEBLIST | Foswiki::Plugins::ExtendedWebListPlugin::
1 | 1 | 1 | 29µs | 70µs | initPlugin | Foswiki::Plugins::ExtendedWebListPlugin::
1 | 1 | 1 | 14µs | 27µs | BEGIN@32 | Foswiki::Plugins::ExtendedWebListPlugin::
1 | 1 | 1 | 10µs | 56µs | BEGIN@36 | Foswiki::Plugins::ExtendedWebListPlugin::
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) 2008 Kenneth Lavrsen, kenneth@lavrsen.dk | ||||
4 | # | ||||
5 | # This program is free software; you can redistribute it and/or | ||||
6 | # modify it under the terms of the GNU General Public License | ||||
7 | # as published by the Free Software Foundation; either version 2 | ||||
8 | # of the License, or (at your option) any later version. For | ||||
9 | # more details read LICENSE in the root of this distribution. | ||||
10 | # | ||||
11 | # This program is distributed in the hope that it will be useful, | ||||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||
14 | # | ||||
15 | # For licensing info read LICENSE file in the Foswiki root. | ||||
16 | |||||
17 | =pod | ||||
18 | |||||
19 | ---+ package ExtendedWebListPlugin | ||||
20 | |||||
21 | __NOTE:__ When writing handlers, keep in mind that these may be invoked | ||||
22 | on included topics. For example, if a plugin generates links to the current | ||||
23 | topic, these need to be generated before the afterCommonTagsHandler is run, | ||||
24 | as at that point in the rendering loop we have lost the information that we | ||||
25 | the text had been included from another topic. | ||||
26 | |||||
27 | =cut | ||||
28 | |||||
29 | package Foswiki::Plugins::ExtendedWebListPlugin; | ||||
30 | |||||
31 | # Always use strict to enforce variable scoping | ||||
32 | 2 | 42µs | 2 | 40µs | # spent 27µs (14+13) within Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@32 which was called:
# once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.14 at line 32 # spent 27µs making 1 call to Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@32
# spent 13µs making 1 call to strict::import |
33 | |||||
34 | # $VERSION is referred to by Foswiki, and is the only global variable that | ||||
35 | # *must* exist in this package. | ||||
36 | 1 | 7µs | 1 | 46µs | # spent 56µs (10+46) within Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@36 which was called:
# once (10µs+46µs) by Foswiki::Plugin::BEGIN@2.14 at line 38 # spent 46µs making 1 call to vars::import |
37 | $pluginName $NO_PREFS_IN_TOPIC | ||||
38 | 1 | 630µs | 1 | 56µs | ); # spent 56µs making 1 call to Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@36 |
39 | |||||
40 | # This should always be $Rev: 1243 (10 Dec 2008) $ so that TWiki 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. | ||||
43 | 1 | 600ns | $VERSION = '$Rev: 1243 (10 Dec 2008) $'; | ||
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. | ||||
48 | 1 | 200ns | $RELEASE = '1.0'; | ||
49 | |||||
50 | # Short description of this plugin | ||||
51 | # One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: | ||||
52 | 1 | 300ns | $SHORTDESCRIPTION = 'Extended Web List Plugin provides the ability to only show subwebs within current top web.'; | ||
53 | |||||
54 | # You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use preferences | ||||
55 | # stored in the plugin topic. This default is required for compatibility with | ||||
56 | # older plugins, but imposes a significant performance penalty, and | ||||
57 | # is not recommended. Instead, use $Foswiki::cfg entries set in LocalSite.cfg, or | ||||
58 | # if you want the users to be able to change settings, then use standard TWiki | ||||
59 | # preferences that can be defined in your %USERSWEB%.SitePreferences and overridden | ||||
60 | # at the web and topic level. | ||||
61 | 1 | 200ns | $NO_PREFS_IN_TOPIC = 0; | ||
62 | |||||
63 | # Name of this Plugin, only used in this module | ||||
64 | 1 | 200ns | $pluginName = 'ExtendedWebListPlugin'; | ||
65 | |||||
66 | =pod | ||||
67 | |||||
68 | ---++ initPlugin($topic, $web, $user, $installWeb) -> $boolean | ||||
69 | * =$topic= - the name of the topic in the current CGI query | ||||
70 | * =$web= - the name of the web in the current CGI query | ||||
71 | * =$user= - the login name of the user | ||||
72 | * =$installWeb= - the name of the web the plugin is installed in | ||||
73 | |||||
74 | REQUIRED | ||||
75 | |||||
76 | Called to initialise the plugin. If everything is OK, should return | ||||
77 | a non-zero value. On non-fatal failure, should write a message | ||||
78 | using Foswiki::Func::writeWarning and return 0. In this case | ||||
79 | %FAILEDPLUGINS% will indicate which plugins failed. | ||||
80 | |||||
81 | In the case of a catastrophic failure that will prevent the whole | ||||
82 | installation from working safely, this handler may use 'die', which | ||||
83 | will be trapped and reported in the browser. | ||||
84 | |||||
85 | You may also call =Foswiki::Func::registerTagHandler= here to register | ||||
86 | a function to handle variables that have standard TWiki syntax - for example, | ||||
87 | =%MYTAG{"my param" myarg="My Arg"}%. You can also override internal | ||||
88 | TWiki variable handling functions this way, though this practice is unsupported | ||||
89 | and highly dangerous! | ||||
90 | |||||
91 | __Note:__ Please align variables names with the Plugin name, e.g. if | ||||
92 | your Plugin is called FooBarPlugin, name variables FOOBAR and/or | ||||
93 | FOOBARSOMETHING. This avoids namespace issues. | ||||
94 | |||||
95 | |||||
96 | =cut | ||||
97 | |||||
98 | # spent 70µs (29+41) within Foswiki::Plugins::ExtendedWebListPlugin::initPlugin which was called:
# once (29µs+41µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm | ||||
99 | 1 | 2µs | my( $topic, $web, $user, $installWeb ) = @_; | ||
100 | |||||
101 | # check for Plugins.pm versions | ||||
102 | 1 | 18µs | 1 | 10µs | if( $Foswiki::Plugins::VERSION < 1.026 ) { # spent 10µs making 1 call to version::vxs::VCMP |
103 | Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" ); | ||||
104 | return 0; | ||||
105 | } | ||||
106 | |||||
107 | # Set plugin preferences in LocalSite.cfg | ||||
108 | 1 | 4µs | $debug = $Foswiki::cfg{Plugins}{ExtendedWebListPlugin}{Debug} || 0; | ||
109 | |||||
110 | 1 | 3µs | 1 | 31µs | Foswiki::Func::registerTagHandler( 'EXTENDEDWEBLIST', \&_EXTENDEDWEBLIST ); # spent 31µs making 1 call to Foswiki::Func::registerTagHandler |
111 | |||||
112 | # Plugin correctly initialized | ||||
113 | 1 | 6µs | return 1; | ||
114 | } | ||||
115 | |||||
116 | # spent 8.35s (1.19ms+8.35) within Foswiki::Plugins::ExtendedWebListPlugin::_EXTENDEDWEBLIST which was called:
# once (1.19ms+8.35s) by Foswiki::Func::__ANON__[/var/www/foswiki11/lib/Foswiki/Func.pm:611] at line 609 of /var/www/foswiki11/lib/Foswiki/Func.pm | ||||
117 | 1 | 2µs | my($session, $params, $theTopic, $theWeb) = @_; | ||
118 | # $session - a reference to the TWiki session object (if you don't know | ||||
119 | # what this is, just ignore it) | ||||
120 | # $params= - a reference to a Foswiki::Attrs object containing parameters. | ||||
121 | # This can be used as a simple hash that maps parameter names | ||||
122 | # to values, with _DEFAULT being the name for the default | ||||
123 | # parameter. | ||||
124 | # $theTopic - name of the topic in the query | ||||
125 | # $theWeb - name of the web in the query | ||||
126 | # Return: the result of processing the variable | ||||
127 | |||||
128 | # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}% | ||||
129 | # $params->{_DEFAULT} will be 'hamburger' | ||||
130 | # $params->{sideorder} will be 'onions' | ||||
131 | |||||
132 | 1 | 3µs | my $format = $params->{_DEFAULT} || $params->{'format'} || '$name'; | ||
133 | 1 | 600ns | $format ||= '$name'; | ||
134 | 1 | 2µs | my $separator = $params->{separator} || "\n"; | ||
135 | 1 | 2µs | $separator =~ s/\$n/\n/; | ||
136 | 1 | 800ns | my $web = $params->{web} || ''; | ||
137 | 1 | 800ns | my $webs = $params->{webs} || 'public'; | ||
138 | 1 | 1µs | my $rootwebs = $params->{rootwebs} || 'on'; | ||
139 | 1 | 900ns | my $selection = $params->{selection} || ''; | ||
140 | 1 | 600ns | my $showWeb = $params->{subwebs} || ''; | ||
141 | 1 | 300ns | $selection =~ s/\,/ /g; | ||
142 | 1 | 2µs | $selection = " $selection "; | ||
143 | 1 | 1µs | my $marker = $params->{marker} || 'selected="selected"'; | ||
144 | 1 | 400ns | $web =~ s#\.#/#go; | ||
145 | |||||
146 | 1 | 2µs | my @list = (); | ||
147 | 1 | 5µs | my @webslist = split( /,\s*/, $webs ); | ||
148 | |||||
149 | 1 | 2µs | foreach my $aweb (@webslist) { | ||
150 | 1 | 3µs | if ( $aweb eq 'public' ) { | ||
151 | 1 | 900ns | if ( $rootwebs eq 'on' ) { | ||
152 | 1 | 800ns | my @sublist = (); | ||
153 | 1 | 500ns | my @templist = (); | ||
154 | 1 | 4µs | my @currentRootWeb = split(/\//, $showWeb); | ||
155 | 1 | 55µs | 1 | 8.33s | push( @templist, Foswiki::Func::getListOfWebs( 'user,public,allowed', '' ) ); # spent 8.33s making 1 call to Foswiki::Func::getListOfWebs |
156 | 1 | 8µs | 1 | 19.8ms | push( @sublist, Foswiki::Func::getListOfWebs( 'user,public,allowed', $currentRootWeb[0] ) ); # spent 19.8ms making 1 call to Foswiki::Func::getListOfWebs |
157 | |||||
158 | 1 | 12µs | foreach my $listitem (@templist) { | ||
159 | 89 | 62µs | if ( $listitem !~ /\// ) { | ||
160 | 39 | 21µs | push( @list, $listitem ); | ||
161 | 39 | 182µs | if ( $showWeb =~ /\b$listitem\b/ ) { | ||
162 | 1 | 2µs | push (@list, @sublist); | ||
163 | 1 | 1µs | Foswiki::Func::writeDebug("@list") if $debug; | ||
164 | } | ||||
165 | } | ||||
166 | } | ||||
167 | |||||
168 | } | ||||
169 | else { | ||||
170 | push( @list, Foswiki::Func::getListOfWebs( 'user,public,allowed', $showWeb ) ); | ||||
171 | } | ||||
172 | } | ||||
173 | elsif ( $aweb eq 'webtemplate' ) { | ||||
174 | push( @list, Foswiki::Func::getListOfWebs( 'template,allowed', $showWeb ) ); | ||||
175 | } | ||||
176 | else { | ||||
177 | push( @list, $aweb ) if ( Foswiki::Func::webExists( $aweb ) ); | ||||
178 | } | ||||
179 | } | ||||
180 | |||||
181 | 1 | 500ns | my @items; | ||
182 | 1 | 14µs | 1 | 127µs | my $indent = CGI::span( { class => 'foswikiWebIndent' }, '' ); # spent 127µs making 1 call to CGI::span |
183 | 1 | 2µs | foreach my $item (@list) { | ||
184 | 42 | 12µs | my $line = $format; | ||
185 | 42 | 38µs | $line =~ s/\$web\b/$web/g; | ||
186 | 42 | 127µs | $line =~ s/\$name\b/$item/g; | ||
187 | 42 | 97µs | $line =~ s/\$qname/"$item"/g; | ||
188 | 42 | 12µs | my $indenteditem = $item; | ||
189 | 42 | 10µs | $indenteditem =~ s#/$##g; | ||
190 | 42 | 28µs | $indenteditem =~ s#\w+/#$indent#g; | ||
191 | 42 | 56µs | $line =~ s/\$indentedname/$indenteditem/g; | ||
192 | 42 | 209µs | my $mark = ( $selection =~ / \Q$item\E / ) ? $marker : ''; | ||
193 | 42 | 101µs | $line =~ s/\$marker/$mark/g; | ||
194 | 42 | 55µs | push( @items, $line ); | ||
195 | } | ||||
196 | 1 | 41µs | return join( $separator, @items ); | ||
197 | } | ||||
198 | |||||
199 | 1 | 4µs | 1; |