Show link to validation on history page (for anons)
[lhc/web/wiklou.git] / maintenance / fetchInterwiki.pl
1 #!/usr/bin/env perl
2 # Copyright (C) 2005 Ævar Arnfjörð Bjarmason
3 use strict;
4 use warnings;
5 use Socket;
6
7 # Conf
8 my $map = &get(&url('http://usemod.com/intermap.txt'));
9
10 # --- #
11 my $cont;
12 my @map = split /\n/, $map;
13
14 open IW, ">Interwiki.php";
15 $cont .= '<?php
16 # Note: this file is generated by maintenance/fetchInterwiki.pl
17 # Edit and rerun that script rather than modifying this directly.
18
19 /* private */ $wgValidInterwikis = array(
20 ';
21
22 $cont .= "\t# The usemod interwiki map\n";
23 for (my $i=0;$i<=$#map;++$i) {
24 my ($name, $url) = $map[$i] =~ m#^([^ ]+) (.+)#i;
25 $cont .= "\t'$name' => '$url\$1',\n";
26 }
27
28 my @iso = qw(
29 aa ab af als am ar as ay az ba be bg bh bi bn bo bs ca chr co cs csb cy da de dk:da dz el en eo
30 es et eu fa fi fj fo fr fy ga gd gl gn gu gv ha he hi hr hu hy ia id ik io is it iu ja jv ka kk
31 kl km kn ko ks ku ky la lo lt lv mg mi mk ml mn mo mr ms my na nah nb nds ne nl no oc om or pa
32 pl ps pt qu rm rn ro ru rw sa sd sg sh si sk sl sm sn so sq sr ss st su sv sw ta te tg th ti tk
33 tl tn to tp tpi tr ts tt tw ug uk ur uz vi vo wa wo xh yi yo za zh zh-cn zh-tw zu);
34
35 $cont .= '
36 # Some custom additions:
37 "ReVo" => "http://purl.org/NET/voko/revo/art/$1.html",
38 # eg [[ReVo:cerami]], [[ReVo:astero]] - note X-sensitive!
39 "EcheI" => "http://www.ikso.net/cgi-bin/wiki.pl?$1",
40 "E\\xc4\\x89eI" => "http://www.ikso.net/cgi-bin/wiki.pl?$1",
41 "UnuMondo" => "http://unumondo.com/cgi-bin/wiki.pl?$1", # X-sensitive!
42 "JEFO" => "http://esperanto.jeunes.free.fr/vikio/index.php?$1",
43 "PMEG" => "http://www.bertilow.com/pmeg/$1.php",
44 # ekz [[PMEG:gramatiko/kunligaj vortetoj/au]]
45 "EnciclopediaLibre" => "http://enciclopedia.us.es/wiki.phtml?title=$1",
46
47 # Wikipedia-specific stuff:
48 # Special cases
49 "w" => "http://www.wikipedia.org/wiki/$1",
50 "m" => "http://meta.wikipedia.org/wiki/$1",
51 "meta" => "http://meta.wikipedia.org/wiki/$1",
52 "sep11" => "http://sep11.wikipedia.org/wiki/$1",
53 "simple"=> "http://simple.wikipedia.com/wiki.cgi?$1",
54 "wiktionary" => "http://wiktionary.wikipedia.org/wiki/$1",
55 "PageHistory" => "http://www.wikipedia.org/w/wiki.phtml?title=$1&action=history",
56 "UserContributions" => "http://www.wikipedia.org/w/wiki.phtml?title=Special:Contributions&target=$1",
57 "BackLinks" => "http://www.wikipedia.org/w/wiki.phtml?title=Special:Whatlinkshere&target=$1",
58
59 # ISO 639 2-letter language codes
60 ';
61
62 for(my $i=0; $i<=$#iso;++$i) {
63 my @arr = split /:/, $iso[$i];
64 $cont .= "\t";
65 $cont .= "'$arr[0]' => 'http://";
66
67 if ($arr[1]) {
68 $cont .= $arr[1];
69 } else {
70 $cont .= $arr[0];
71 }
72 $cont .= ".wikipedia.org/wiki/\$1',\n";
73 }
74
75 $cont .= '
76 );
77 ?>
78 ';
79
80 open IW, ">Interwiki.php";
81 print IW $cont;
82 close IW;
83
84 sub get {
85 my ($host, $url) = @_;
86 my $cont;
87 my $eat;
88
89 my $proto = getprotobyname('tcp');
90 socket(Socket, AF_INET, SOCK_STREAM, $proto);
91 my $iaddr = inet_aton("$host");
92 my $port = getservbyname('http', 'tcp');
93 my $sin = sockaddr_in($port, $iaddr);
94 connect(Socket, $sin);
95 send Socket, "GET $url HTTP/1.0\r\nHost: $host\r\n\r\n",0;
96 while (<Socket>) {
97 $cont .= $_ if $eat; # mmm, food
98 ++$eat if ($_ =~ /^(\n|\r\n|)$/);
99 }
100 return $cont;
101 }
102
103 sub url {my ($server, $path) = $_[0] =~ m#.*(?=//)//([^/]*)(.*)#g;}