suffix = $s; $this->lateral = $l; $this->url = $u; } function getURL( $lang ) { return "http://$lang.{$this->url}/wiki/\$1"; } } $row = wfGetArray( "metawiki.cur", array( "cur_text" ), array( "cur_namespace" => 0, "cur_title" => "Interwiki_map" ) ); if ( !$row ) { die( "m:Interwiki_map not found" ); } $lines = explode( "\n", $row->cur_text ); $iwArray = array(); foreach ( $lines as $line ) { if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(.*?)\s*$/', $line, $matches ) ) { $prefix = $matches[1]; $url = $matches[2]; if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks)\.org/', $url ) ) { $local = 1; } else { $local = 0; } $iwArray[] = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local ); } } $langlist = array_map( "trim", file( "/home/wikipedia/common/langlist" ) ); # Insert links into special wikis # No interlanguage links, that's the definition of a special wiki # Just intermap links $specials = array( 'sourceswiki' => 'sources.wikipedia.org', 'quotewiki' => 'wikiquote.org', 'textbookwiki' => 'wikibooks.org', 'sep11wiki' => 'sep11.wikipedia.org', 'metawiki' => 'meta.wikipedia.org', ); $sql = "-- Generated by rebuildInterwiki.php"; foreach ( $specials as $db => $host ) { $sql .= "\nUSE $db;\n" . "TRUNCATE TABLE interwiki;\n" . "INSERT INTO interwiki (iw_prefix, iw_url, iw_local) VALUES \n"; $first = true; foreach ( $iwArray as $iwEntry ) { # Suppress links to self if ( strpos( $iwEntry['iw_url'], $host ) === false ) { # Add comma if ( $first ) { $first = false; } else { $sql .= ",\n"; } $sql .= "(" . Database::makeList( $iwEntry ) . ")"; } } $sql .= ";\n"; } $sql .= "\n"; # Insert links into multilanguage sites $sites = array( new Site( 'wiki', 'w', 'wikipedia.org' ), new Site( 'wiktionary.org', 'wikt', 'wiktionary.org' ) ); foreach ( $sites as $site ) { $sql .= <<suffix} --- EOS; foreach ( $langlist as $lang ) { $db = $lang . $site->suffix; $db = str_replace( "-", "_", $db ); $sql .= "USE $db;\n" . "TRUNCATE TABLE interwiki;\n" . "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES\n"; $first = true; # Intermap links foreach ( $iwArray as $iwEntry ) { # Suppress links to self if ( strpos( $iwEntry['iw_url'], $site->url ) === false ) { # Add comma if ( $first ) { $first = false; } else { $sql .= ",\n"; } $sql .= "(" . Database::makeList( $iwEntry ) . ")"; } } # Lateral links foreach ( $sites as $targetSite ) { # Suppress link to self if ( $targetSite->suffix != $site->suffix ) { if ( $first ) { $first = false; } else { $sql .= ",\n"; } $link = array( $targetSite->lateral, $targetSite->getURL( $lang ), 1 ); $sql .= "(" . Database::makeList( $link ) . ")"; } } # Interlanguage links foreach ( $langlist as $targetLang ) { if ( $first ) { $first = false; } else { $sql .= ",\n"; } $link = array( $targetLang, $site->getURL( $targetLang ), 1 ); $sql .= "(" . Database::makeList( $link ) . ")"; } $sql .= ";\n\n"; } } # Output if ( isset( $options['o'] ) ) { # To file specified with -o chdir( $oldCwd ); $file = fopen( $options['o'], "w" ); fwrite( $file, $sql ); fclose( $file ); } else { # To stdout print $sql; } ?>