# # TWiki WikiClone ($wikiversion has version info) # # Copyright (C) 2001 Dresdner Kleinwort Wasserstein # # 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 General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html # # ========================= # # This is the plugin is required by the Tiger skin # ========================= package TWiki::Plugins::TigerSkinPlugin; # ========================= use vars qw( $web $topic $user $installWeb $VERSION $debug $renderingWeb $isGuest $revsToShow $skin ); #$web $topic $user $installWeb $VERSION $debug $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 TigerSkinPlugin and Plugins.pm" ); return 0; } $renderingWeb = $web; # Get plugin debug flag $debug = &TWiki::Func::getPreferencesFlag( "TIGERSKINPLUGIN_DEBUG" ); $revsToShow = &TWiki::Func::getPreferencesValue( "TIGERSKINPLUGIN_NUMREVISIONS" ) || 5; $isGuest = &TWiki::Func::isGuest(); # Plugin correctly initialized &TWiki::Func::writeDebug( "- TWiki::Plugins::TigerSkinPlugin::initPlugin( $web.$topic ) is OK" ) if $debug; return 1; } sub notHandle { my $skin = &TWiki::Func::getSkin(); return ( $skin ne "tiger" && $skin ne "cat" ); } # ========================= sub commonTagsHandler { ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead &TWiki::Func::writeDebug( "- TigerSkinPlugin::commonTagsHandler( $_[2].$_[1] )" ) if $debug; return if( notHandle() ); # This is the place to define customized tags and variables # Called by sub handleCommonTags, after %INCLUDE:"..."% $_[0] =~ s/%LOGO%/&getIcon( $web, $topic, "tiger" )/geo; $_[0] =~ s/%TIGERLOGON%/&dispUser()/geo; $_[0] =~ s/%LEFTMENU%/&getMenu()/geo; $_[0] =~ s/%SHOWALL%/&showMenu("all")/geo; $_[0] =~ s/%SHOWVIEW%/&showMenu("view")/geo; } # ========================= sub dispUser # conditional on presence of SessionPlugin { my $dispUser = ""; if( &TWiki::Func::topicExists( &TWiki::Func::getTwikiWebname(), "SessionPlugin" ) && $isGuest ) { $dispUser = "%SESSIONLOGON%"; } else { my $wikiName = &TWiki::Func::getWikiName(); my $mainWeb = &TWiki::Func::getMainWebname(); $dispUser = "$wikiName" } return $dispUser; } # ================================= sub showMenu { my( $scope ) = @_; my $res = "on"; if( $scope eq "view" ) { $res = "none"; } # Only do check if there are permission set on this Web or if user logged on already my $perm = TWiki::Func::permissionsSet( $web ); if( $perm || !$isGuest ) { my $auth = TWiki::Func::checkAccessPermission( "change", &TWiki::Func::getWikiUserName, "", $topic, $web ); if( ! $auth ) { if( $scope eq "all" ) { $res= "none"; } else { $res = "on"; } } } return $res; } # =============================== sub getMenu { my( $menu, $meta ); if( TWiki::Func::topicExists( $web, "WebMenu" ) ) { ( $meta, $menu ) = &TWiki::Func::readTopic( $web, "WebMenu" ); } else { my $twikiWebname = &TWiki::Func::getTwikiWebname(); ( $meta, $menu ) = &TWiki::Func::readTopic( $twikiWebname, "WebMenu" ); } my $res = "\n"; } $firstOuter = ""; $firstWeb = "on"; $res .= "\n"; } $firstWeb = ""; my $visibility = "clsItemsHide"; if( $thisWeb eq $web || $expand eq "always" ) { $visibility = "clsItemsShow"; } my $webType = "clsShowHide"; if( $expand eq "never" ) { $visibility = "clsItemsHide"; $webType = "clsNoExpand"; } $res .= " \n"; return $res; } # ============================ sub getIcon { my( $web, $topic, $skin ) = @_; my $icon = ""; if( ! $skin ) { $skin = "tiger"; } my $file = &TWiki::Func::getPubDir()."/$web/logo.gif"; my $url = &TWiki::Func::getPubUrlPath()."/$web/logo.gif"; if( ! -e $file ) { $url = &TWiki::Func::getPubUrlPath()."/".&TWiki::Func::getTwikiWebname()."/TigerSkin/logo.gif"; } $icon = ""; return $icon; } # ========================= sub startRenderingHandler { ### my ( $text, $newweb, $meta ) = @_; # do not uncomment, use $_[0], $_[1] instead #&TWiki::Func::writeDebug( "- TigerSkinPlugin::startRenderingHandler( $_[1] )" ) if $debug; # This handler is called by getRenderedVersion just before the line loop return if( notHandle() ); $_[0] =~ s/%TIGERREVS%/&tigerRevs( $meta )/geo; } # ========================= sub tigerRevs { my( $meta ) = @_; my( $revdate, $revuser, $maxrev ) = &TWiki::Func::getRevisionInfo( $web, $topic, $meta, "isoFormat" ); my $query = &TWiki::Func::getCgiQuery(); my $rev = $query->param( "rev" ); my $topicExists = &TWiki::Func::topicExists( $web, $topic ); if( $topicExists ) { if( $rev ) { $rev =~ s/1\.//go; # cut major if( $rev < 1 ) { $rev = 1; } if( $rev > $maxrev ) { $rev = $maxrev; } } else { $rev = $maxrev; } } else { $rev = 1; } my $i = $maxrev; my $j = $maxrev; my $revisions = ""; my $breakRev = 0; if( ( $revsToShow > 0 ) && ( $revsToShow < $maxrev ) ) { $breakRev = $maxrev - $revsToShow + 1; } $split = " "; $split1 = ""; $anchor = " 0 ) { if( $i eq $rev) { $revisions = "$revisions$split1 r1.$i"; } else { $revisions = "$revisions$split1$anchor title=\"View revision 1.$i\" href=\"$scriptUrlPath/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%?rev=1.$i\">r1.$i"; } if( $i != 1 ) { if( $i == $breakRev ) { $revisions = "$revisions$split$anchor1 title=\"Diff between specific versions\" href=\"$scriptUrlPath/oops%SCRIPTSUFFIX%/%WEB%/%TOPIC%?template=oopsrev&param1=1.$maxrev\">>..."; $i = 1; } else { $j = $i - 1; $revisions = "$revisions$split$anchor1 title=\"Diff between 1.$i & 1.$j\" href=\"$scriptUrlPath/rdiff%SCRIPTSUFFIX%/%WEB%/%TOPIC%?rev1=1.$i&rev2=1.$j\">>"; } } $i--; } #TWiki::Func::writeDebug( "revisions is $revisions" ); $revisions = &TWiki::Func::expandCommonVariables( $revisions, $topic, $web ); return $revisions; } # ========================= 1;