Kill NamespaceCompat. Nothing, anywhere (not even comments, since r70692) still refer...
[lhc/web/wiklou.git] / maintenance / rebuildInterwiki.inc
index fea5f64..9ad9dbf 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;
@@ -30,8 +28,8 @@ class Site {
        }
 }
 
-function getRebuildInterwikiSQL() {
-       global $langlist, $languageAliases, $prefixRewrites, $wgDBname;
+function makeInterwikiSQL( $destDir ) {
+       global $langlist, $languageAliases, $prefixRewrites;
 
        # Multi-language sites
        # db suffix => db suffix, iw prefix, hostname
@@ -43,6 +41,7 @@ function getRebuildInterwikiSQL() {
                'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ),
                'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ),
                'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ),
+               'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ),
        );
 
        # List of language prefixes likely to be found in multi-language sites
@@ -59,6 +58,7 @@ function getRebuildInterwikiSQL() {
                'sep11wiki' => 'sep11.wikipedia.org',
                'metawiki' => 'meta.wikimedia.org',
                'commonswiki' => 'commons.wikimedia.org',
+               'specieswiki' => 'species.wikimedia.org',
        );
 
        # Extra interwiki links that can't be in the intermap for some reason
@@ -93,12 +93,12 @@ function getRebuildInterwikiSQL() {
        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 ) {
@@ -108,6 +108,7 @@ function getRebuildInterwikiSQL() {
        $iwArray = array();
 
        foreach ( $lines as $line ) {
+               $matches = array();
                if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(https?:\/\/.*?)\s*$/', $line, $matches ) ) {
                        $prefix = strtolower( $matches[1] );
                        $url = $matches[2];
@@ -123,10 +124,10 @@ function getRebuildInterwikiSQL() {
                }
        }
 
-       $sql = "-- Generated by rebuildInterwiki.php";
 
 
        foreach ( $dblist as $db ) {
+               $sql = "-- Generated by rebuildInterwiki.php";
                if ( isset( $specials[$db] ) ) {
                        # Special wiki
                        # Has interwiki links and interlanguage links to wikipedia
@@ -160,7 +161,7 @@ function getRebuildInterwikiSQL() {
                } 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;
@@ -204,17 +205,17 @@ function getRebuildInterwikiSQL() {
                        # 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, $db );
+                               $sql .= makeLink( array( "w", "http://en.wikipedia.org/wiki/$1", 1 ), $first, $db );
                        }
 
                        # Extra links
-                       foreach ( $extraLinks as $link ){
+                       foreach ( $extraLinks as $link ) {
                                        $sql .= makeLink( $link, $first, $db );
                        }
-                       $sql .= ";\n\n";
+                       $sql .= ";\n";
                }
+               file_put_contents( "$destDir/$db.sql", $sql );
        }
-       return $sql;
 }
 
 # ------------------------------------------------------------------------------------------
@@ -252,9 +253,7 @@ function makeLink( $entry, &$first, $source ) {
        } else {
                $sql .= ",\n";
        }
-       $dbr =& wfGetDB( DB_SLAVE );
+       $dbr = wfGetDB( DB_SLAVE );
        $sql .= "(" . $dbr->makeList( $entry ) . ")";
        return $sql;
 }
-
-?>