Skip to content

Commit

Permalink
Item593: fixed minor bugs, added delimiter / globalformat, cosmetic t…
Browse files Browse the repository at this point in the history
…hings, new defaults

git-svn-id: http://svn.foswiki.org/trunk/TopicListPlugin@1637 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
EugenMayer authored and EugenMayer committed Dec 28, 2008
1 parent 4e44ec7 commit 6dd1b53
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 23 deletions.
14 changes: 9 additions & 5 deletions data/System/TopicListPlugin.txt
Expand Up @@ -20,7 +20,8 @@ The goal is, to make this plugin efficient even if you have a great number of to
| _max_ | 50 | maximum number of results. Use 0 for infinite |
| _order_ | < | literal order, _<_ for increasing, _>_ for decreasing |
| _format_ | " * ![[%WEB.%TOPIC][%TOPIC]]" | format for each resulting row, %WEB gets replaced by the web, %TOPIC by the topic name |

| _delimiter | "\n" | what delimiter should be used to seperated the topics |
| _globalformat | "%TOPICS" | the whole topic list will replace the %TOPICS varibale in this string. This string will be return as the result of the rest handler |
*Examples:*
* List maximum 20 topics of this web starting with "S", decreasing order: !%GETTOPICLIST{pattern="^S.*$" max="40" order=">"}%
%GETTOPICLIST{searchwebs="-all-" pattern="^S.*$" max="40" order=">"}%
Expand All @@ -35,19 +36,22 @@ The goal is, to make this plugin efficient even if you have a great number of to
| _negate_ | 0 | negate the pattern. So all topics which do match the pattern, are *not* shown |
| _max_ | 50 | maximum number of results. Use 0 for infinite |
| _order_ | < | literal order, _<_ for increasing, _>_ for decreasing |
| _format_ | "%WEB.%TOPIC" | format for each resulting row, %WEB gets replaced by the web, %TOPIC by the topic name |
| _format_ | "'%TOPIC'" | format for each resulting row, %WEB gets replaced by the web, %TOPIC by the topic name. The result is by default formated as JSON array item|
| _delimiter | "," | what delimiter should be used to seperated the topics |
| _globalformat | "[%TOPICS]" | the whole topic list will replace the %TOPICS varibale in this string. This string will be return as the result of the rest handler, by default a JSON array |

---++ Installation instructions
* just use the installer attached to the topic or even easier, use the configure-system/Extension to easy install it trough an user-interface
* just use the installer attached to the topic or even easier, use the configure-system/Extension to easy install it through an user-interface
__Note:__ You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the Plugin on the server where Foswiki is running.

* Set SHORTDESCRIPTION = Gives you the possibility to generate a list of topics by macro or rest handler. Should be also optimized for a great number of topics

| Plugin Author: | Foswiki:Main.EugenMayer |
| Copyright: | © Impressive.media |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Plugin Version: | 26 Dez 2008 (V0.2) |
| Plugin Version: | 28 Dez 2008 (V0.3) |
| Change History: | <!-- versions below in reverse order --> |
| 28 Dez 2008: | fixed minor bugs, added delimiter / globalformat, cosmetic things, new defaults |
| 26 Dez 2008: | implemented all methods. Yet no index or cache is implemented, so maybe not working to good on many topics |
| 22 Dez 2008: | initial release |
| Foswiki Dependency: | |
Expand All @@ -59,7 +63,7 @@ __Note:__ You do not need to install anything on the browser to use this plugin.
| Appraisal: | http://foswiki.org/Extensions/%TOPIC%Appraisal |
__Related Topic:__

-- Foswiki:Main/EugenMayer - 22 Dez 2008
-- Foswiki:Main/EugenMayer - 28 Dez 2008

%META:FORM{name="PackageForm"}%
%META:FIELD{name="TopicClassification" attributes="" title="TopicClassification" value="PluginPackage"}%
Expand Down
86 changes: 68 additions & 18 deletions lib/Foswiki/Plugins/TopicListPlugin.pm
Expand Up @@ -36,7 +36,7 @@ $VERSION = '$Rev: 12445$';
# This is a free-form string you can use to "name" your own plugin version.
# It is *not* used by the build automation tools, but is reported as part
# of the version number in PLUGINDESCRIPTIONS.
$RELEASE = '0.2';
$RELEASE = '0.3';

# Short description of this plugin
# One line description, is shown in the %FoswikiWEB%.TextFormattingRules topic:
Expand All @@ -53,42 +53,54 @@ sub initPlugin {
my ( $topic, $web, $user, $installWeb ) = @_;

Foswiki::Func::registerRESTHandler('topiclist', \&_topicList);
Foswiki::Func::registerRESTHandler('weblist', \&_webList);
Foswiki::Func::registerTagHandler( 'GETTOPICLIST',\&_macrotopicList );

return 1;
}

sub _macrotopicList{
my ( $this, $params, $topic, $web ) = @_;
my $searchWebs = $params->{"SEARCHWEBS"} || $web;
my $searchWebs = $params->{"searchwebs"} || $web;
my $pattern = $params->{"pattern"} || '*';
my $casesensitive = $params->{"casesens"};
$casesensitive = 1 if !defined $casesensitive;
my $negate = $params->{"negate"} || 0;
my $max = $params->{"max"} || 50;
my $max = $params->{"max"};
$max = 50 if !defined $max;
my $order = $params->{"order"} || '<';
my $format = $params->{"format"} || " * %WEB.%TOPIC\n";
my $format = _expandString($params->{"format"}) || " * %WEB.%TOPIC";
my $delimiter = $params->{"delimiter"};
$delimiter = "\n" if !defined $delimiter;
$delimiter = _expandString($delimiter);

return _getTopicList($searchWebs,$pattern,$casesensitive,$negate,$max,$order,$format);
my $globalFormat = _expandString($params->{"globalformat"}) || '%TOPICS';

return _getTopicList($searchWebs,$pattern,$casesensitive,$negate,$max,$order,$format,,$delimiter,$globalFormat);
}
sub _topicList{
my $session = shift;
my $web = $session->{webName};
my $topic = $session->{topicName};
my $query = $session->{cgiQuery};
my $searchWebs = $query->param("SEARCHWEBS") || $web;
my $searchWebs = $query->param("searchwebs") || $web;
my $pattern = $query->param("pattern") || '*';
my $casesensitive = $query->param("casesens") || 1;
my $negate = $query->param("negate") || 0;
my $max = $query->param("max") || 50;
my $max = $query->param("max");
$max = 50 if !defined $max;
my $order = $query->param("order") || '<';
my $format = $query->param("format") || "%WEB.%TOPIC\n";

return _getTopicList($searchWebs,$pattern,$casesensitive,$negate,$max,$order,$format);
my $format = _expandString($query->param("format")) || "'%WEB.%TOPIC'";
my $delimiter = $query->param("delimiter");
$delimiter = "," if !defined $delimiter;
$delimiter = _expandString($delimiter);
my $globalFormat = _expandString($query->param("globalformat")) || '[%TOPICS]';

return _getTopicList($searchWebs,$pattern,$casesensitive,$negate,$max,$order,$format,$delimiter,$globalFormat);
}

sub _getTopicList {
my ($searchWebs,$pattern,$casesensitive,$negate,$max,$order,$format) = @_;
my ($searchWebs,$pattern,$casesensitive,$negate,$max,$order,$format,$delimiter,$globalFormat) = @_;

my @webs = [];
if($searchWebs eq "-all-") {
Expand All @@ -108,7 +120,7 @@ sub _getTopicList {
$topics{$web} = _getTopicsOfWebByFunc($web,$pattern, $order, $max, $casesensitive, $negate);
}

return _getOutput($format,\%topics);
return _getOutput($format,$delimiter,$globalFormat,\%topics);
}

sub _getTopicsOfWebByFunc {
Expand All @@ -122,8 +134,16 @@ sub _getTopicsOfWebByFunc {
_debug("max : $max");
$refTopics = _filterTopicList($pattern,$casesensitive,$negate,$refTopics);

my @topcis = splice @{$refTopics}, 0, $max;
_debug("Topics spliced",@topcis);

my @topcis;
if($max > 0) {
splice @{$refTopics}, 0, $max;
_debug("Topics spliced",@topcis);
}
else {
@topcis = @{$refTopics};
}


# as topics are read of from the FS, they normaly are in < order ( literally ), so if we sort > , flip the array
@topcis = reverse @topcis if($order eq ">");
Expand Down Expand Up @@ -162,21 +182,26 @@ sub _filterTopicList {
}

sub _getOutput {
my ($format, $refWebTopicPairs) = @_;
my ($format,$delimiter,$globalFormat, $refWebTopicPairs) = @_;
my $output = "";

foreach my $web ( keys %{$refWebTopicPairs}) {
foreach my $topicName (@{$refWebTopicPairs->{$web}}) {
my $tmp = $format;
$tmp =~ s/%WEB/$web/g;
$tmp =~ s/%TOPIC/$topicName/g;
$output .= $tmp;
$output .= $tmp.$delimiter;
}
}
return $output;
# remove the laste delimiter
$output = substr($output,0,-length($delimiter));
$globalFormat =~ s/%TOPICS/$output/g;

return $globalFormat;
}

sub _debug {
return if 1; #!$Foswiki::cfg{Plugins}{TopicListPlugin}{Debug};
return if !0; #!$Foswiki::cfg{Plugins}{TopicListPlugin}{Debug};
my ( $message, @param ) = @_;

Foswiki::Func::writeDebug( "[TopicListPlugin]:" . $message );
Expand All @@ -195,4 +220,29 @@ sub _warn {
}
1;

sub _webList {
my $session = shift;
my $web = $session->{webName};
my $topic = $session->{topicName};
my $query = $session->{cgiQuery};
my $exculdeWebs = $query->param("excludewebs") || "";

my $output = '';
my @webs = Foswiki::Func::getListOfWebs();

foreach my $web (@webs) {
next if($exculdeWebs =~ /$web/);
$output .= "\"$web\",";
}
# remove the laste ,
$output = substr($output,0,-1) if $output ne '';

return "[$output]";
}

sub _expandString {
my $string = shift;
$string =~ s/%NL/\n/g;
return $string;
}
# vim: ft=perl foldmethod=marker

0 comments on commit 6dd1b53

Please sign in to comment.