I got an e-mail from
JamesYoungman while TWiki.org was out of order. It is a nice little script to find referenced but not defined
WikiWords. I am posting it here, but I have not tested it out.
James Youngman wrote:
>
>
I also wrote a script to find referenced but not defined WikiWords.
>
I'm sure that one already exists but since you temporarily lost your
>
content, I didn't find it on the TWiki website. Anyway, in case it's
>
helpful at all, here it is.
#! /usr/bin/perl -w
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find ();
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
my $datadir = "/home/james/twiki/data";
my @weblist = ( "Know", "Main", "Test", "Trash", "TWiki" );
# Changing the value to 0 seems to make things work -- Main.KevinCounts - 10 Jan 2005
# my $dangle_threshold = 1;
my $dangle_threshold = 0;
my (%got, %dangling);
my $compundRegexp =
qw!([\*\s][\(\-\*\s]*)([A-Z]+[a-z0-9]*)\.([A-Z]+[a-z]+[A-Z]+[a-zA-Z0-9]*)!;
my $simpleRegexp =
qw!([\*\s][\(\-\*\s]*)([A-Z]+[a-z]+[A-Z]+[a-zA-Z0-9]*)!;
foreach my $current_web ( @weblist ) {
my $top = $datadir . "/" . $current_web;
%got = (); File::Find::find({wanted => \&remember_got}, $top);
%dangling = (); File::Find::find({wanted => \&search_it }, $top);
foreach (sort { $dangling{$b} <=> $dangling{$a} } keys %dangling) {
if ($dangling{$_} > $dangle_threshold) {
printf("%3d : %s.%s\n", $dangling{$_}, $current_web, $_);
}
}
print "\n";
}
sub remember_got { if (m/([^\/]+)\.txt\z/s) { $got{$1} = 1; } }
sub compound { } # ToDo: implement me later.
sub simple { if (!$got{$_[0]}) { ++$dangling{$_[0]}; } }
sub search_it {
if (m/([^\/]+)\.txt\z/s) {
open INFILE, "<$_";
while (<INFILE>) {
s/$compundRegexp/&compound($2,$3),""/geo;
s/$simpleRegexp/&simple($2),""/geo;
}
close INFILE;
}
}
--
PeterThoeny - 24 Oct 2001
I tried this on my March 2001 beta installation and it didn't generate any output, despite there being quite a few dangling references. I got a vast number of calls to
compound(), which may be the problem, and a warning that 'Use of implicit split to
@_
is deprecated' on the two assignments to the *Regexp variables.
--
RichardDonkin - 26 Oct 2001
Changing the dangle_threshhold to 0 makes it work more as expected. I'm running it on the 01Feb2003 release under Red Hat 7.3, Perl version 5.6.1.
--
CarlPatten - 17 Feb 2004
I experienced the same results as Carl. I changed the code but left a comment that it was edited.
I'm glad to find this code - I had just read the Wiki Way book and was searching to no avail for the
unreferenced internal links search.
--
KevinCounts - 10 Jan 2005
I just tried this and found that it is returning things that are wiki words, but are explicitly not linked with a
or a
!. I don't know enough perl to fix that.
--
JeffersonCowart - 20 Mar 2005
So suppose I want to try this script, what should I do?
- create a file with the above script in my /twiki/bin/ directory
- change the hardcoded datadir location and save file
- fix the file permissions
- access the script in some way from within TWiki
Who can help this unknowing user? Thanks!
--
JosMaccabiani
Jos - you are right from 1-3. This is however, not a cgi-script, it is command line tool that will give you a list from the console. - so as step 4 - run script from where you created it (you don't even need to have it in the same directory chain as twiki at all
--
SvenDowideit - 02 Jul 2005
Thanks Sven. I discovered
ListingAllUndefinedButUsedWikiWords and find it easier to adept to my needs, so i'll try that first
--
JosMaccabiani - 02 Jul 2005