Index: trunk/phase3/maintenance/fetchInterwiki.pl |
— | — | @@ -1,101 +0,0 @@ |
2 | | -#!/usr/bin/env perl |
3 | | -# Copyright (C) 2005 Ævar Arnfjörð Bjarmason |
4 | | -use strict; |
5 | | -use warnings; |
6 | | -use Socket; |
7 | | - |
8 | | -# Conf |
9 | | -my $map = &get(&url('http://usemod.com/intermap.txt')); |
10 | | - |
11 | | -# --- # |
12 | | -my $cont; |
13 | | -my @map = split /\n/, $map; |
14 | | - |
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 | | -open IW, ">Interwiki.php"; |
80 | | -print IW $cont; |
81 | | -close IW; |
82 | | - |
83 | | -sub get { |
84 | | - my ($host, $url) = @_; |
85 | | - my $cont; |
86 | | - my $eat; |
87 | | - |
88 | | - my $proto = getprotobyname('tcp'); |
89 | | - socket(Socket, AF_INET, SOCK_STREAM, $proto); |
90 | | - my $iaddr = inet_aton("$host"); |
91 | | - my $port = getservbyname('http', 'tcp'); |
92 | | - my $sin = sockaddr_in($port, $iaddr); |
93 | | - connect(Socket, $sin); |
94 | | - send Socket, "GET $url HTTP/1.0\r\nHost: $host\r\n\r\n",0; |
95 | | - while (<Socket>) { |
96 | | - $cont .= $_ if $eat; # mmm, food |
97 | | - ++$eat if ($_ =~ /^(\n|\r\n|)$/); |
98 | | - } |
99 | | - return $cont; |
100 | | -} |
101 | | - |
102 | | -sub url {my ($server, $path) = $_[0] =~ m#.*(?=//)//([^/]*)(.*)#g;} |