3 # Rebuild interwiki table using the file on meta and the language list
7 $optionsWithArgs = array( "o" );
8 include( "commandLine.inc" );
11 var $suffix, $lateral, $url;
13 function Site( $s, $l, $u ) {
19 function getURL( $lang ) {
20 return "http://$lang.{$this->url}/wiki/\$1";
24 $row = wfGetArray( "metawiki.cur", array( "cur_text" ), array( "cur_namespace" => 0, "cur_title" => "Interwiki_map" ) );
27 die( "m:Interwiki_map not found" );
30 $lines = explode( "\n", $row->cur_text
);
33 foreach ( $lines as $line ) {
34 if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(.*?)\s*$/', $line, $matches ) ) {
35 $prefix = $matches[1];
37 if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks)\.org/', $url ) ) {
43 $iwArray[] = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local );
47 $langlist = array_map( "trim", file( "/home/wikipedia/common/langlist" ) );
49 # Insert links into special wikis
50 # No interlanguage links, that's the definition of a special wiki
54 'sourceswiki' => 'sources.wikipedia.org',
55 'quotewiki' => 'wikiquote.org',
56 'textbookwiki' => 'wikibooks.org',
57 'sep11wiki' => 'sep11.wikipedia.org',
58 'metawiki' => 'meta.wikipedia.org',
61 $sql = "-- Generated by rebuildInterwiki.php";
63 foreach ( $specials as $db => $host ) {
64 $sql .= "\nUSE $db;\n" .
65 "TRUNCATE TABLE interwiki;\n" .
66 "INSERT INTO interwiki (iw_prefix, iw_url, iw_local) VALUES \n";
69 foreach ( $iwArray as $iwEntry ) {
70 # Suppress links to self
71 if ( strpos( $iwEntry['iw_url'], $host ) === false ) {
78 $sql .= "(" . Database
::makeList( $iwEntry ) . ")";
85 # Insert links into multilanguage sites
88 new Site( 'wiki', 'w', 'wikipedia.org' ),
89 new Site( 'wiktionary.org', 'wikt', 'wiktionary.org' )
92 foreach ( $sites as $site ) {
100 foreach ( $langlist as $lang ) {
101 $db = $lang . $site->suffix
;
102 $db = str_replace( "-", "_", $db );
104 $sql .= "USE $db;\n" .
105 "TRUNCATE TABLE interwiki;\n" .
106 "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES\n";
110 foreach ( $iwArray as $iwEntry ) {
111 # Suppress links to self
112 if ( strpos( $iwEntry['iw_url'], $site->url
) === false ) {
119 $sql .= "(" . Database
::makeList( $iwEntry ) . ")";
124 foreach ( $sites as $targetSite ) {
125 # Suppress link to self
126 if ( $targetSite->suffix
!= $site->suffix
) {
132 $link = array( $targetSite->lateral
, $targetSite->getURL( $lang ), 1 );
133 $sql .= "(" . Database
::makeList( $link ) . ")";
137 # Interlanguage links
138 foreach ( $langlist as $targetLang ) {
144 $link = array( $targetLang, $site->getURL( $targetLang ), 1 );
145 $sql .= "(" . Database
::makeList( $link ) . ")";
152 if ( isset( $options['o'] ) ) {
153 # To file specified with -o
155 $file = fopen( $options['o'], "w" );
156 fwrite( $file, $sql );