blob: 2b642bf897f7515a45190f68ec793915988e9a7e (
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
67
68
69
70
71
72
|
#!/usr/bin/perl
use strict;
use warnings;
# remove unlinked pages from a list of pages
# also remove any matching certain keywords
# input: page list, redirect list (from GetPages.pl)
# and page links (from PageLinks.pl)
my $pagelist = $ARGV[0];
my $redirectlist = $ARGV[1];
my $pagelinks = $ARGV[2];
# remove pages starting with these keywords
my @removepages = ("Wikipedia:","Ayuda:","Wikiproyecto:","MediaWiki:","Plantilla:","WP:","Portal:", "CategorÃa");
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) {
my $good = 1;
foreach my $remove (@removepages) {
if ($page =~ /^$remove/) {
$good = 0;
}
}
if (($pagecounts{$page} >= 1) and $good) {
print "$page\n";
}
}
|