Standardised file description headers:
[lhc/web/wiklou.git] / maintenance / dumpInterwiki.inc
index 1a33844..97e5be9 100644 (file)
@@ -3,22 +3,20 @@
  * Rebuild interwiki table using the file on meta and the language list
  * Wikimedia specific!
  *
+ * @file
  * @todo document
- * @package MediaWiki
- * @subpackage Maintenance
+ * @ingroup Maintenance
+ * @ingroup Wikimedia
  */
 
-/** */
-
 /**
  * @todo document
- * @package MediaWiki
- * @subpackage Maintenance
+ * @ingroup Maintenance
  */
 class Site {
        var $suffix, $lateral, $url;
 
-       function Site( $s, $l, $u ) {
+       function __construct( $s, $l, $u ) {
                $this->suffix = $s;
                $this->lateral = $l;
                $this->url = $u;
@@ -31,7 +29,7 @@ class Site {
 }
 
 function getRebuildInterwikiDump() {
-       global $langlist, $languageAliases, $prefixRewrites;
+       global $langlist, $languageAliases, $prefixRewrites, $wgContLang;
 
        # Multi-language sites
        # db suffix => db suffix, iw prefix, hostname
@@ -78,8 +76,8 @@ function getRebuildInterwikiDump() {
        # Special case prefix rewrites, for the benefit of Swedish which uses s:t
        # as an abbreviation for saint
        $prefixRewrites = array(
-                'svwiki' => array ( 's' => 'src'),
-       ); 
+                'svwiki' => array ( 's' => 'src' ),
+       );
 
        # Construct a list of reserved prefixes
        $reserved = array();
@@ -89,12 +87,12 @@ function getRebuildInterwikiDump() {
        foreach ( $languageAliases as $alias => $lang ) {
                $reserved[$alias] = 1;
        }
-       foreach( $sites as $site ) {
+       foreach ( $sites as $site ) {
                $reserved[$site->lateral] = 1;
        }
 
        # Extract the intermap from meta
-       $intermap = wfGetHTTP( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 );
+       $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 );
        $lines = array_map( 'trim', explode( "\n", trim( $intermap ) ) );
 
        if ( !$lines || count( $lines ) < 2 ) {
@@ -104,6 +102,8 @@ function getRebuildInterwikiDump() {
        # Global iterwiki map
        foreach ( $lines as $line ) {
                if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(.*?)\s*$/', $line, $matches ) ) {
+                       $prefix = $wgContLang->lc( $matches[1] );
+                       $prefix = str_replace( ' ', '_', $prefix );
                        $prefix = strtolower( $matches[1] );
                        $url = $matches[2];
                        if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) {
@@ -114,17 +114,17 @@ function getRebuildInterwikiDump() {
 
                        if ( empty( $reserved[$prefix] ) ) {
                            $imap  = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local );
-                            makeLink ($imap, "__global");
+                            makeLink ( $imap, "__global" );
                        }
                }
        }
 
         # Exclude Wikipedia for Wikipedia
-        makeLink ( array ('iw_prefix' => 'wikipedia', 'is_url' => null ), "_wiki" );
+        makeLink ( array ( 'iw_prefix' => 'wikipedia', 'is_url' => null ), "_wiki" );
         
-        #Multilanguage sites
-        foreach ($sites as $site) 
-            makeLanguageLinks ( $site, "_".$site->suffix );
+        # Multilanguage sites
+        foreach ( $sites as $site )
+            makeLanguageLinks ( $site, "_" . $site->suffix );
 
 
         foreach ( $dblist as $db ) {
@@ -132,25 +132,25 @@ function getRebuildInterwikiDump() {
                        # Special wiki
                        # Has interwiki links and interlanguage links to wikipedia
 
-                        makeLink( array( 'iw_prefix' => $db, 'iw_url' => "wiki"), "__sites" );
+                        makeLink( array( 'iw_prefix' => $db, 'iw_url' => "wiki" ), "__sites" );
                        # Links to multilanguage sites
                        foreach ( $sites as $targetSite ) {
-                               makeLink( array( 'iw_prefix' => $targetSite->lateral, 
-                                                    'iw_url' =>$targetSite->getURL( 'en' ),
+                               makeLink( array( 'iw_prefix' => $targetSite->lateral,
+                                                    'iw_url' => $targetSite->getURL( 'en' ),
                                                     'iw_local' => 1 ), $db );
                        }
 
                } else {
                        # Find out which site this DB belongs to
                        $site = false;
-                       foreach( $sites as $candidateSite ) {
+                       foreach ( $sites as $candidateSite ) {
                                $suffix = $candidateSite->suffix;
                                if ( preg_match( "/(.*)$suffix$/", $db, $matches ) ) {
                                $site = $candidateSite;
                                        break;
                                }
                        }
-                        makeLink( array( 'iw_prefix' => $db, 'iw_url' => $site->suffix), "__sites" );
+                        makeLink( array( 'iw_prefix' => $db, 'iw_url' => $site->suffix ), "__sites" );
                        if ( !$site ) {
                                print "Invalid database $db\n";
                                continue;
@@ -160,16 +160,16 @@ function getRebuildInterwikiDump() {
                        # Lateral links
                        foreach ( $sites as $targetSite ) {
                                if ( $targetSite->suffix != $site->suffix ) {
-                                       makeLink( array( 'iw_prefix' => $targetSite->lateral, 
-                                                            'iw_url' => $targetSite->getURL( $lang ), 
+                                       makeLink( array( 'iw_prefix' => $targetSite->lateral,
+                                                            'iw_url' => $targetSite->getURL( $lang ),
                                                             'iw_local' => 1 ), $db );
                                }
                        }
 
                        if ( $site->suffix == "wiki" ) {
-                               makeLink( array('iw_prefix' => 'w', 
-                                                'iw_url' => "http://en.wikipedia.org/wiki/$1", 
-                                                'iw_local' => 1), $db );
+                               makeLink( array( 'iw_prefix' => 'w',
+                                                'iw_url' => "http://en.wikipedia.org/wiki/$1",
+                                                'iw_local' => 1 ), $db );
                        }
 
                }
@@ -198,16 +198,14 @@ function makeLink( $entry, $source ) {
        global $prefixRewrites, $dbFile;
        if ( isset( $prefixRewrites[$source] ) && isset( $prefixRewrites[$source][$entry[0]] ) )
                $entry[0] = $prefixRewrites[$source][$entry[0]];
-        if (!array_key_exists("iw_prefix",$entry))
-            $entry = array("iw_prefix" => $entry[0], "iw_url" => $entry[1], "iw_local" => $entry[2]);
-        if ( array_key_exists($source,$prefixRewrites) && 
-                array_key_exists($entry['iw_prefix'],$prefixRewrites[$source]))
+        if ( !array_key_exists( "iw_prefix", $entry ) )
+            $entry = array( "iw_prefix" => $entry[0], "iw_url" => $entry[1], "iw_local" => $entry[2] );
+        if ( array_key_exists( $source, $prefixRewrites ) &&
+                array_key_exists( $entry['iw_prefix'], $prefixRewrites[$source] ) )
                     $entry['iw_prefix'] = $prefixRewrites[$source][$entry['iw_prefix']];
-        if ($dbFile)
-            dba_insert("{$source}:{$entry['iw_prefix']}", trim("{$entry['iw_local']} {$entry['iw_url']}"),$dbFile);
+        if ( $dbFile )
+            $dbFile->set( "{$source}:{$entry['iw_prefix']}", trim( "{$entry['iw_local']} {$entry['iw_url']}" ) );
         else
             print "{$source}:{$entry['iw_prefix']} {$entry['iw_url']} {$entry['iw_local']}\n";
 
     }
-
-?>