#!/usr/bin/perl -w #!/usr/bin/perl -d:ptkdb # # TWiki WikiClone (see wiki.pm for $wikiversion and other info) # # Based on parts of Ward Cunninghams original Wiki and JosWiki. # Copyright (C) 1998 Markus Peter - SPiN GmbH (warpi@spin.de) # Some changes by Dave Harris (drh@bhresearch.co.uk) incorporated # Copyright (C) 1999 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 General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html # # this script is based on the 'bin/view' script # and can be used to make a offline copy of all TWikiTopics # # 1. converts all *.txt,v files into static HTML and # 2. copies the pub/ directory tree for all attachments # # you may create a templates/twiki2html.tmpl file, but an internal # default could also be used. use Cwd; use Getopt::Long; use File::Find; use File::Basename; use File::Path; GetOptions ( "twikidir=s" => \$twikidir, "outdir=s" => \$outdir, "h" => \$help, "help" => \$help ); if (defined $help) { print "usage: $0 [--twikidir=dir] [--outdir=dir]\n"; print " --twikidir : default \"/usr/local/httpd/twiki\"\n"; print " --outdir : default \"temp\"\n\n"; print "example: $0 --outdir=temp\n"; exit (1); } if (not defined $twikidir) { # default TWiki installation directory $twikidir = "/usr/local/httpd/twiki"; } if (not defined $outdir) { # default output directory $outdir = "temp"; } # remember where we came from $currentdir = cwd(); # now require TWiki .pm's from the installation push @INC, "$twikidir/bin"; require wiki; # overwrite some configs from wikicfg.pm $wiki::wikiHomeUrl = ""; $wiki::defaultUrlHost = ""; $wiki::scriptUrlPath = ".."; $wiki::pubUrlPath = "../pub"; my @files; my $reldir; my $pos; sub dofind { if (not defined $reldir) { $reldir = cwd(); $pos = length $reldir; } if (/(.*)\.txt,v$/) { my $file; $file = cwd() . "/$1"; # make abs. path $file = substr ($file, $pos+1); # make rel. path push @files, "$file"; } } print "searching in $twikidir/data\n"; &find (\&dofind, "$twikidir/data"); # now create the HTML's foreach $file (@files) { my $outfile = $outdir . "/$file"; my $dir = dirname ($outfile); print "generating $outfile\n"; chdir $currentdir; if (! -e $dir) { mkpath ($dir); } &printhtml("/$file", $outfile); } # now copy the pub directory tree chdir $currentdir; chdir $outdir; my $target = cwd(); # XXX: this works only on UNIX system "(cd $twikidir ; tar cvf - pub) | (cd $target ; tar xf - )"; exit 0; sub printhtml { my ($thePathInfo, $outfile) = @_; my $theRemoteUser; my $theTopic; my $theUrl = ""; ( $topic, $webName, $scriptUrlPath, $userName ) = &wiki::initialize( $thePathInfo, $theRemoteUser, $theTopic, $theUrl ); my $tmpl = ""; my $text = ""; my $rev; my $maxrev = 1; my $extra = ""; my $wikiUserName = &wiki::userToWikiName( $userName ); if( ! &wiki::webExists( $webName ) ) { $tmpl= &wiki::readTemplate( "noweb" ); $tmpl = &wiki::handleCommonTags( $tmpl, $topic ); open OUT, ">$outfile" or do { print "can't open $outfile!\n"; return; }; print OUT $tmpl; close OUT; return; } $tmpl= &wiki::readTemplate( "twiki2html", $topic ); if( ! $tmpl ) { $tmpl = < Offline %WIKITOOLNAME% . %WEB% . %TOPIC% %REVTITLE%
Offline %WIKITOOLNAME% . %WEB% . %TOPIC% %REVTITLE% %WIKIWEBLIST%
%WEBTOPICLIST%
%TEXT%

Revision %REVINFO%
%WEBCOPYRIGHT%
EOL } my $topicExists = &wiki::topicExists( $webName, $topic ); if( $topicExists ) { $maxrev = &wiki::getRevisionNumber( $topic ); $maxrev =~ s/1\.//go; # cut major if( $rev ) { $rev =~ s/1\.//go; # cut major if( $rev < 1 ) { $rev = 1; } if( $rev > $maxrev ) { $rev = $maxrev; } $text= &wiki::readVersion( $topic, "1.$rev" ); $extra .= "r1.$rev"; } else { $text= &wiki::readTopic( $topic ); $rev= $maxrev; } } else { $rev = 1; if( &wiki::isWikiName( $topic ) ) { $text= &wiki::readTemplate( "notext" ); } else { $text= &wiki::readTemplate( "notwiki" ); } $extra .= " (not exist)"; } # commented out because not tested and not finished (protect also %INCLUDE% and search) # # check access permission # if( ! &wiki::checkAccessPermission( "view", $wikiUserName, $text, $topic, $webName ) ) { # my $url = &wiki::getOopsUrl( $webName, $topic, "oopsaccessview" ); # print $query->redirect( $url ); # return; # } $text = &wiki::handleCommonTags( $text, $topic ); $text = &wiki::getRenderedVersion( $text ); if( $rev < $maxrev ) { # disable edit of previous revisions $tmpl =~ s/%EDITTOPIC%/Edit/go; $tmpl =~ s/%REVTITLE%/\(r1.$rev\)/go; } else { if( $topicExists ) { $tmpl =~ s/%EDITTOPIC%/Edit<\/B><\/A>/go; # remove the NOINDEX meta tag $tmpl =~ s/]*>//goi; } else { $tmpl =~ s/%EDITTOPIC%/Create<\/B><\/A>/go; } $tmpl =~ s/%REVTITLE%//go; } my $i = $maxrev; my $j = $maxrev; my $revisions = ""; my $breakRev = 0; if( ( $wiki::numberOfRevisions > 0 ) && ( $wiki::numberOfRevisions < $maxrev ) ) { $breakRev = $maxrev - $wiki::numberOfRevisions + 1; } while( $i > 0 ) { if( $i eq $rev) { $revisions = "$revisions | r1.$i"; } else { $revisions = "$revisions | r1.$i"; } if( $i != 1 ) { if( $i == $breakRev ) { $revisions = "$revisions | >..."; $i = 1; } else { $j = $i - 1; $revisions = "$revisions | >"; } } $i = $i - 1; } $tmpl =~ s/%REVISIONS%/$revisions/go; if( $topicExists ) { my( $date, $user ) = &wiki::getRevisionInfo( $topic, "1.$rev", 1 ); $user = &wiki::userToWikiName( $user ); my $temp = &wiki::getRenderedVersion( "r1.$rev - $date by $user" ); $tmpl =~ s/%REVINFO%/$temp/go; } else { $tmpl =~ s/%REVINFO%//go; } $tmpl = &wiki::handleCommonTags( $tmpl, $topic ); $tmpl =~ s/%TEXT%/$text/go; $tmpl =~ s|||goi; # remove tags (PTh 06 Nov 2000) $tmpl =~ s/\.\.\/view/../go; # SS remove ../view chdir $currentdir; open OUT, ">$outfile" or do { print "can't open $outfile!\n"; return; }; print OUT $tmpl; close OUT; }