3 # Rebuild interwiki table using the file on meta and the language list
6 $optionsWithArgs = array( "o" );
7 include( "commandLine.inc" );
10 var $suffix, $lateral, $url;
12 function Site( $s, $l, $u ) {
18 function getURL( $lang ) {
19 return "$lang.{$this->url}/wiki/\$1";
23 $row = wfGetArray( "metawiki.cur", array( "cur_text" ), array( "cur_namespace" => 0, "cur_title" => "Interwiki_map" ) );
26 die( "m:Interwiki_map not found" );
29 $lines = explode( "\n", $row->cur_text
);
32 foreach ( $lines as $line ) {
33 if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(.*?)\s*$/', $line, $matches ) ) {
34 $prefix = $matches[1];
36 if ( preg_match( '/^http:\/\/(a-z)*\.(wikipedia|wiktionary|wikisource|wikiquote|wikibooks)/', $url ) ) {
42 $iwArray[] = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local );
46 $langlist = array_map( "trim", file( "/home/wikipedia/langlist" ) );
48 # Insert links into special wikis
49 # No interlanguage links, that's the definition of a special wiki
53 'sourceswiki' => 'sources.wikipedia.org',
54 'quotewiki' => 'wikiquote.org',
55 'textbookwiki' => 'wikibooks.org',
56 'sep11wiki' => 'sep11.wikipedia.org',
57 'metawiki' => 'meta.wikipedia.org',
60 $sql = "-- Generated by rebuildInterwiki.php";
62 foreach ( $specials as $db => $host ) {
63 $sql .= "\nUSE $db;\n" .
64 "TRUNCATE TABLE interwiki;\n" .
65 "INSERT INTO interwiki (iw_prefix, iw_url, iw_local) VALUES \n";
68 foreach ( $iwArray as $iwEntry ) {
75 # Suppress links to self
76 if ( strpos( $host, $iwEntry['iw_url'] ) === false ) {
77 $sql .= "(" . Database
::makeList( $iwEntry ) . ")";
84 # Insert links into multilanguage sites
87 new Site( 'wiki', 'w', 'wikipedia.org' ),
88 new Site( 'wiktionary.org', 'wiktionary.org' );
91 foreach ( $sites as $site ) {
98 foreach ( $langlist as $lang ) {
99 $db = $lang . $site->suffix
;
100 $db = str_replace( "-", "_", $db );
102 $sql .= "USE $db;\n" .
103 "TRUNCATE TABLE interwiki\n" .
104 "INSERT INTO interwiki (iw_prefix,iw_url,iw_local\n";
108 foreach ( $iwArray as $iwEntry ) {
115 # Suppress links to self
116 if ( strpos( $host, $iwEntry['iw_url'] ) === false ) {
117 $sql .= "(" . Database
::makeList( $iwEntry ) . ")";
122 foreach ( $sites as $targetSite ) {
128 $link = array( $targetSite->lateral
, $targetSite->getURL( $lang ), 1 );
129 $sql .= "(" . Database
::makeList( $link ) . ")";
132 # Interlanguage links
133 foreach ( $langlist as $targetLang ) {
139 $link = array( $targetLang, $site->getURL( $targetLang ), 1 );
140 $sql .= "(" . Database
::makeList( $link ) . ")";
147 if ( isset( $options['o'] ) ) {
148 # To file specified with -o
149 $file = fopen( $options['o'], "w" );
150 fwrite( $file, $sql );