Using a test for template namespace initialisation that's more likely to return true...
[lhc/web/wiklou.git] / maintenance / rebuildInterwiki.inc
index 22c0f7f..e102bb0 100644 (file)
@@ -1,12 +1,24 @@
-<?
-
-# Rebuild interwiki table using the file on meta and the language list
-# Wikimedia specific!
+<?php
+/**
+ * Rebuild interwiki table using the file on meta and the language list
+ * Wikimedia specific!
+ *
+ * @todo document
+ * @package MediaWiki
+ * @subpackage Maintenance
+ */
+
+/** */
 $oldCwd = getcwd();
 
 $optionsWithArgs = array( "o" );
 include_once( "commandLine.inc" );
 
+/**
+ * @todo document
+ * @package MediaWiki
+ * @subpackage Maintenance
+ */
 class Site {
        var $suffix, $lateral, $url;
 
@@ -28,8 +40,8 @@ function getRebuildInterwikiSQL() {
        $sites = array( 
                'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ),
                'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ),
-               'wikiquote' => new Site( 'wikiquote', 'wikiquote', 'wikiquote.org' ),
-               'wikibooks' => new Site( 'wikibooks', 'wikibooks', 'wikibooks.org' )
+               'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ),
+               'wikibooks' => new Site( 'wikibooks', 'b', 'wikibooks.org' )
        );
        $langlist = array_map( "trim", file( "/home/wikipedia/common/langlist" ) );
        $dblist = array_map( "trim", file( "/home/wikipedia/common/all.dblist" ) );
@@ -51,6 +63,7 @@ function getRebuildInterwikiSQL() {
        $languageAliases = array(
                'zh-cn' => 'zh',
                'zh-tw' => 'zh',
+               'dk' => 'da',
        );
 
        # Construct a list of reserved prefixes
@@ -67,7 +80,7 @@ function getRebuildInterwikiSQL() {
 
        # Extract the intermap from meta
        $dbr =& wfGetDB( DB_WRITE );
-       $row = $dbr->getArray( "metawiki.cur", array( "cur_text" ), 
+       $row = $dbr->selectRow( "metawiki.cur", array( "cur_text" ), 
                array( "cur_namespace" => 0, "cur_title" => "Interwiki_map" ) );
 
        if ( !$row ) {
@@ -123,7 +136,7 @@ function getRebuildInterwikiSQL() {
 
                        # Extra links
                        foreach ( $extraLinks as $link ) {
-                                       $sql .= makeLink( $link, $first );
+                               $sql .= makeLink( $link, $first );
                        }
                        
                        $sql .= ";\n";
@@ -152,7 +165,12 @@ function getRebuildInterwikiSQL() {
 
                        # Intermap links
                        foreach ( $iwArray as $iwEntry ) {
-                               $sql .= makeLink( $iwEntry, $first );
+                               # Suppress links with the same name as the site
+                               if ( ( $suffix == 'wiki' && $iwEntry['iw_prefix'] != 'wikipedia' ) || 
+                                 ( $suffix != 'wiki' && $suffix != $iwEntry['iw_prefix'] ) ) 
+                               {
+                                       $sql .= makeLink( $iwEntry, $first );
+                               }
                        }
 
                        # Lateral links