blob: 571abc0ffdf2ce3ec36d708371c1947dd3b5a7e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/usr/bin/perl
use strict;
use warnings;
my $pagelist = $ARGV[0];
my $redirectlist = $ARGV[1];
my $pagelinks = $ARGV[2];
my %pagecounts = ();
open(PAGE,$pagelist) or die;
while(<PAGE>) {
chomp;
$pagecounts{$_} = 0;
}
close(PAGE);
my %redirects = ();
open(REDIR,$redirectlist) or die;
while (<REDIR>) {
if (/\[\[(.*?)\]\]\s*\[\[(.*?)\]\]/) {
$redirects{$1} = $2;
} else {
die "redirects line is weird:\n$_\n";
}
}
close(REDIR);
open(LINKS,$pagelinks);
while (<LINKS>) {
my @data = split;
my $currpage = shift(@data);
$currpage =~ s/_/ /g;
unless (exists ($pagecounts{$currpage})) {
next;
}
foreach my $link (@data) {
$link =~ s/_/ /g;
if (exists ($redirects{$link})) {
if (exists ($pagecounts{$redirects{$link}})) {
$pagecounts{$redirects{$link}}++;
} else {
#print "Weird: $link redirects to $redirects{$link}, but this one isn't on the pagelist?\n";
}
}
if (exists $pagecounts{$link}) {
$pagecounts{$link}++;
} else {
#print "$link does not exist on pagelist\n";
}
}
}
foreach my $page (keys %pagecounts) {
if (exists $redirects{$page}) {
if (exists $pagecounts{$redirects{$page}} and exists $pagecounts{$page}) {
if ($pagecounts{$page} >= 1) {
print "$pagecounts{$redirects{$page}}\t[[$page]]\n";
} else {
print "$pagecounts{$page}\t[[$page]]\n";
}
}
} else {
print "$pagecounts{$page}\t[[$page]]\n";
}
}
|