#!/usr/bin/perl -w # # TWiki WikiClone (see wiki.pm for $wikiversion and other info) # # Copyright (C) 1999-2000 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 # customize $touchgraph = "touchgraph.txt"; $viewprefix = "$TWiki::defaultUrlHost$TWiki::scriptUrlPath/view$TWiki::scriptSuffix"; use lib ( '.' ); use lib ( '../lib' ); use TWiki; use TWiki::Net; my $debug = ! ( @ARGV && $ARGV[0] eq "-q" ); &main(); sub main { $debug && print "TWiki $touchgraph list generation\n"; $debug && print "- to suppress all normal output: $0 -q\n"; my $dataDir = &TWiki::getDataDir(); opendir( DIR, "$dataDir" ) or die "could not open $dataDir"; @weblist = grep !/^\.\.?$/, readdir DIR; closedir DIR; ##@weblist = ( "Mondis"); foreach $web ( @weblist ) { processWeb( $web ) if ( -d "$dataDir/$web" ); } $debug && print "End create $touchgraph\n"; } sub processWeb { my( $web) = @_; my $file = ""; my @filelist = (); my ( $topic, $webName, $dummy, $userName, $dataDir) = &TWiki::initialize( "/$web", "nobody" ); $dummy = ""; # to suppress warning my $pubDir = TWiki::getPubDir(); $debug && print "Checking TWiki.$webName\n"; if( ! &TWiki::Store::webExists( $webName ) ) { print STDERR "* ERROR: TWiki $0 does not find web $webName\n"; return; } opendir( DIR, "$dataDir/$web" ) or die "$dataDir/$web: $!"; @filelist = grep /^.*\.txt$/, readdir DIR; closedir DIR; open LIST, ">$pubDir/$web/$touchgraph" or die "$web/$touchgraph: $!"; foreach $file ( sort @filelist ) { $file =~ s/.txt$//; processTopic( $dataDir, $web, $file ) if ( -d "$dataDir/$web" ); } close LIST or die "close $web/$touchgraph: $!"; $debug && print "- End Twiki.$webName, $touchgraph written.\n"; } sub xrf { print LIST "$_[0] "; } sub processTopic { my ($dataDir, $web, $topic) = @_; $debug && print "$topic... "; print LIST "$topic "; open TOPIC, "$dataDir/$web/$topic.txt" or die "$web/$topic: $!"; while () { s/%TWIKIWEB%/TWiki/go; s/%MAINWEB%/Main/go; # meta stuff if (/^%META:TOPICPARENT.name="(.*)"/o) { print LIST "$1\n$1 $topic\n$topic "; next; } if (/^%META:FORM.name="(.*)"/o) { print LIST "\n$1 $topic\n$topic "; next; } if (/^%META:TOPICINFO.author="([^"]*)/o) { xrf "$viewprefix/Main/$1"; next; } s/[#>][A-Za-z0-9]+//go; # discard internal labels # links with web if (s/([A-Z][A-Za-z]+)\.([A-Z]+[a-z]+[A-Z][A-Za-z0-9_-]*)//go) { xrf "$viewprefix/$1/$2"; } if (s/\[\[([A-Z][A-Za-z]+)\.([^]]+)\]\]//go) { xrf "$viewprefix/$1/$2"; } # other links if (s/[A-Z]+[a-z]+[A-Z][A-Za-z0-9_-]*//go) { xrf $&; } if (s/\[\[([^]]+)\]\]//go) { xrf $1; } if (s/http:\/\/[^] "\n ]+//go) { xrf $1; } } print LIST "\n"; }