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