From: Tim Starling Date: Sat, 19 Jun 2004 06:05:20 +0000 (+0000) Subject: various improvements and bug fixes X-Git-Tag: 1.5.0alpha1~2817 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=fb7f95766933b3787031006307c23e5c03c3efdb;p=lhc%2Fweb%2Fwiklou.git various improvements and bug fixes --- diff --git a/maintenance/rebuildInterwiki.php b/maintenance/rebuildInterwiki.php index da00155604..dd1a66a902 100644 --- a/maintenance/rebuildInterwiki.php +++ b/maintenance/rebuildInterwiki.php @@ -21,6 +21,34 @@ class Site { } } +# Initialise lists of wikis +$sites = array( + 'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ), + 'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ) +); +$langlist = array_map( "trim", file( "/home/wikipedia/common/langlist" ) ); + +$specials = array( + 'sourceswiki' => 'sources.wikipedia.org', + 'quotewiki' => 'wikiquote.org', + 'textbookwiki' => 'wikibooks.org', + 'sep11wiki' => 'sep11.wikipedia.org', + 'metawiki' => 'meta.wikipedia.org', +); + +$extraLinks = array( + array( 'm', 'http://meta.wikipedia.org/wiki/$1', 1 ), + array( 'meta', 'http://meta.wikipedia.org/wiki/$1', 1 ), + array( 'sep11', 'http://sep11.wikipedia.org/wiki/$1', 1 ), +); + +$languageAliases = array( + 'zh-cn' => 'zh', + 'zh-tw' => 'zh', +); + +# Extract the intermap from meta + $row = wfGetArray( "metawiki.cur", array( "cur_text" ), array( "cur_namespace" => 0, "cur_title" => "Interwiki_map" ) ); if ( !$row ) { @@ -44,19 +72,9 @@ foreach ( $lines as $line ) { } } -$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', -); +# These have intermap links and interlanguage links pointing to wikipedia $sql = "-- Generated by rebuildInterwiki.php"; @@ -66,29 +84,30 @@ foreach ( $specials as $db => $host ) { "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'], $host ) === false ) { - # Add comma - if ( $first ) { - $first = false; - } else { - $sql .= ",\n"; - } - $sql .= "(" . Database::makeList( $iwEntry ) . ")"; + $sql .= makeLink( $iwEntry, $first ); } } + # w link + $sql .= makeLink( array("w", "http://en.wikipedia.org/wiki/$1", 1 ), $first ); + + # Interlanguage links to wikipedia + $sql .= makeLanguageLinks( $sites['wiki'], $first ); + + # Extra links + foreach ( $extraLinks as $link ) { + $sql .= makeLink( $link, $first ); + } + $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 .= <<url ) === false ) { - # Add comma - if ( $first ) { - $first = false; - } else { - $sql .= ",\n"; - } - $sql .= "(" . Database::makeList( $iwEntry ) . ")"; + if ( strpos( $iwEntry['iw_url'], $site->url ) === false || + strpos( $iwEntry['iw_url'], 'meta.wikipedia.org' ) !== false ) { + $sql .= makeLink( $iwEntry, $first ); } } @@ -124,25 +138,22 @@ EOS; 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 ) . ")"; + $sql .= makeLink( array( $targetSite->lateral, $targetSite->getURL( $lang ), 1 ), $first ); } } # 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 .= makeLanguageLinks( $site, $first ); + + # w link within wikipedias + # Other sites already have it as a lateral link + if ( $site->suffix == "wiki" ) { + $sql .= makeLink( array("w", "http://en.wikipedia.org/wiki/$1", 1), $first ); + } + + # Extra links + foreach ( $extraLinks as $link ){ + $sql .= makeLink( $link, $first ); } $sql .= ";\n\n"; } @@ -159,4 +170,38 @@ if ( isset( $options['o'] ) ) { # To stdout print $sql; } + +# ------------------------------------------------------------------------------------------ + +# Returns part of an INSERT statement, corresponding to all interlanguage links to a particular site +function makeLanguageLinks( &$site, &$first ) { + global $langlist, $languageAliases; + + $sql = ""; + + # Actual languages with their own databases + foreach ( $langlist as $targetLang ) { + $sql .= makeLink( array( $targetLang, $site->getURL( $targetLang ), 1 ), $first ); + } + + # Language aliases + foreach ( $languageAliases as $alias => $lang ) { + $sql .= makeLink( array( $alias, $site->getURL( $lang ), 1 ), $first ); + } + return $sql; +} + +# Make SQL for a single link from an array +function makeLink( $entry, &$first ) { + $sql = ""; + # Add comma + if ( $first ) { + $first = false; + } else { + $sql .= ",\n"; + } + $sql .= "(" . Database::makeList( $entry ) . ")"; + return $sql; +} + ?>