# perl -w # TWiki WikiClone ($wikiversion has version info) # # Copyright (C) 2000-2001 Andrea Sterbini, a.sterbini@flashnet.it # Copyright (C) 2001 Peter Thoeny, Peter@Thoeny.com # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Gener al Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html # # ========================= # # # Each plugin is a package that contains the subs: # # initPlugin ( $topic, $web, $user, $installWeb ) # commonTagsHandler ( $text, $topic, $web ) # startRenderingHandler( $text, $web ) # outsidePREHandler ( $text ) # insidePREHandler ( $text ) # endRenderingHandler ( $text ) # # initPlugin is required, all other are optional. # For increased performance, all handlers except initPlugin are # disabled. To enable a handler remove the leading DISABLE_ from # the function name. # # NOTE: To interact with TWiki use the official TWiki functions # in the &TWiki::Func module. Do not reference any functions or # variables elsewhere in TWiki!! # ========================= package TWiki::Plugins::CompareWebsPlugin; # ========================= use vars qw( $web $topic $user $installWeb $VERSION $debug $exampleCfgVar @allWebs %topics ); $VERSION = '1.000'; # ========================= sub initPlugin { ( $topic, $web, $user, $installWeb ) = @_; # check for Plugins.pm versions if( $TWiki::Plugins::VERSION < 1 ) { &TWiki::Func::writeWarning( "Version mismatch between CompareWebsPlugin and Plugins.pm" ); return 0; } # Get plugin preferences, the variable defined by: $exampleCfgVar = &TWiki::Prefs::getPreferencesValue( "EMPTYPLUGIN_EXAMPLE" ) || "default"; # Get plugin debug flag $debug = &TWiki::Func::getPreferencesFlag( "COMPAREWEBS_DEBUG" ); # Plugin correctly initialized &TWiki::Func::writeDebug( "- TWiki::Plugins::CompareWebsPlugin::initPlugin( $web.$topic ) is OK" ) if 1; return 1; } # ========================= sub DISABLE_commonTagsHandler { ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead &TWiki::Func::writeDebug( "- CompareWebsPlugin::commonTagsHandler( $_[2].$_[1] )" ) if 1; # This is the place to define customized tags and variables # Called by sub handleCommonTags, after %INCLUDE:"..."% # do custom extension rule, like for example: # $_[0] =~ s/%XYZ%/&handleXyz()/geo; # $_[0] =~ s/%XYZ{(.*?)}%/&handleXyz($1)/geo; } # ========================= sub startRenderingHandler { ### my ( $text, $web ) = @_; # do not uncomment, use $_[0], $_[1] instead writeDebug( "- CompareWebsPlugin::startRenderingHandler( $_[1].$topic )" ); # This handler is called by getRenderedVersion just before the line loop $_[0] =~ s/%COMPAREWEBS{(.*?)}%/&compareWebs($1)/geo; # do custom extension rule, like for example: # $_[0] =~ s/old/new/go; } # ========================= sub DISABLE_outsidePREHandler { ### my ( $text ) = @_; # do not uncomment, use $_[0] instead # &TWiki::Func::writeDebug( "- XSLXMLPlugin::outsidePREHandler( $web.$topic )" ) if $debug; # This handler is called by getRenderedVersion, in loop outside of
tag.
# This is the place to define customized rendering rules.
# Note: This is an expensive function to comment out.
# Consider startRenderingHandler instead
}
# =========================
sub DISABLE_insidePREHandler
{
### my ( $text ) = @_; # do not uncomment, use $_[0] instead
# &TWiki::Func::writeDebug( "- CompareWebsPlugin::insidePREHandler( $web.$topic )" ) if $debug;
# This handler is called by getRenderedVersion, in loop inside of tag.
# This is the place to define customized rendering rules.
# Note: This is an expensive function to comment out.
# Consider startRenderingHandler instead
}
# =========================
sub endRenderingHandler
{
### my ( $text ) = @_; # do not uncomment, use $_[0] instead
&TWiki::Func::writeDebug( "- CompareWebsPlugin::endRenderingHandler( $web.$topic )" ) if $debug;
# This handler is called by getRenderedVersion just after the line loop
}
sub writeDebug
{
&TWiki::Func::writeDebug(@_) if $debug;
}
sub trimSpaces
{
my $string = $_[0];
$string =~ s/^\s*(.*?)\s*$/$1/;
return $string;
}
sub trimQuotes
{
my $string = $_[0];
if ( ($string =~ /^'(.*?)'$/) || ($string =~ /^"(.*?)"$/) ) {
$string =~ s/^[',"](.*?)[',"]$/$1/;
}
return $string;
}
sub setDefaults {
my ($args) = @_;
my @nameValuePairs= split /,/, $args;
foreach my $pair (@nameValuePairs) {
my ($name, $value) = split /=/, $pair;
$name = &trimQuotes(&trimSpaces($name));
$value = &trimQuotes(&trimSpaces($value));
$args{$name} = $value;
}
if ($args{webs}) {
$args{webs} =~ s/\s+/ /g; # remove excess spaces
my @asArray = (split / /, $args{webs});
$args{webs} = \@asArray;
} else {
my @asArray = &TWiki::Func::getPublicWebList();
$args{webs} = \@asArray;
}
foreach (@{$args{webs}}) {
$_ = trimQuotes($_);
}
my @allWebs = @{$args{webs}};
# print "WEBS= ".join(",", @allWebs);
my %argsAndDefaults = ( webs => \@allWebs,
startTable=> "| WikiWord | ".join(" | ",@{$args{webs}})." | ", endTable=> "