* (bug 5161) Don't try to load template list for nonexistent pages
[lhc/web/wiklou.git] / maintenance / rebuildInterwiki.inc
index a10a224..fea5f64 100644 (file)
@@ -35,7 +35,7 @@ function getRebuildInterwikiSQL() {
 
        # Multi-language sites
        # db suffix => db suffix, iw prefix, hostname
-       $sites = array( 
+       $sites = array(
                'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ),
                'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ),
                'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ),
@@ -50,9 +50,9 @@ function getRebuildInterwikiSQL() {
 
        # List of all database names
        $dblist = array_map( "trim", file( "/home/wikipedia/common/all.dblist" ) );
-       
+
        # Special-case hostnames
-       $specials = array( 
+       $specials = array(
                'sourceswiki' => 'sources.wikipedia.org',
                'quotewiki' => 'wikiquote.org',
                'textbookwiki' => 'wikibooks.org',
@@ -70,7 +70,7 @@ function getRebuildInterwikiSQL() {
 
        # Language aliases, usually configured as redirects to the real wiki in apache
        # Interlanguage links are made directly to the real wiki
-       # Something horrible happens if you forget to list an alias here, I can't 
+       # Something horrible happens if you forget to list an alias here, I can't
        #   remember what
        $languageAliases = array(
                'zh-cn' => 'zh',
@@ -102,27 +102,27 @@ function getRebuildInterwikiSQL() {
        $lines = array_map( 'trim', explode( "\n", trim( $intermap ) ) );
 
        if ( !$lines || count( $lines ) < 2 ) {
-               die( "m:Interwiki_map not found" );
+               wfDie( "m:Interwiki_map not found" );
        }
 
        $iwArray = array();
 
        foreach ( $lines as $line ) {
-               if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(.*?)\s*$/', $line, $matches ) ) {
+               if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(https?:\/\/.*?)\s*$/', $line, $matches ) ) {
                        $prefix = strtolower( $matches[1] );
                        $url = $matches[2];
-                       if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks)\.org/', $url ) ) {
+                       if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) {
                                $local = 1;
                        } else {
                                $local = 0;
                        }
-                       
+
                        if ( empty( $reserved[$prefix] ) ) {
                                $iwArray[$prefix] = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local );
                        }
                }
        }
-       
+
        $sql = "-- Generated by rebuildInterwiki.php";
 
 
@@ -130,14 +130,14 @@ function getRebuildInterwikiSQL() {
                if ( isset( $specials[$db] ) ) {
                        # Special wiki
                        # Has interwiki links and interlanguage links to wikipedia
-                       
+
                        $host = $specials[$db];
                        $sql .= "\n--$host\n\n";
                        $sql .= "USE $db;\n" .
-                                       "TRUNCATE TABLE interwiki;\n" . 
+                                       "TRUNCATE TABLE interwiki;\n" .
                                        "INSERT INTO interwiki (iw_prefix, iw_url, iw_local) VALUES \n";
                        $first = true;
-                       
+
                        # Intermap links
                        foreach ( $iwArray as $iwEntry ) {
                                $sql .= makeLink( $iwEntry, $first, $db );
@@ -147,7 +147,7 @@ function getRebuildInterwikiSQL() {
                        foreach ( $sites as $targetSite ) {
                                $sql .= makeLink( array( $targetSite->lateral, $targetSite->getURL( 'en' ), 1 ), $first, $db );
                        }
-                       
+
                        # Interlanguage links to wikipedia
                        $sql .= makeLanguageLinks( $sites['wiki'], $first, $db );
 
@@ -155,7 +155,7 @@ function getRebuildInterwikiSQL() {
                        foreach ( $extraLinks as $link ) {
                                $sql .= makeLink( $link, $first, $db );
                        }
-                       
+
                        $sql .= ";\n";
                } else {
                        # Find out which site this DB belongs to
@@ -174,7 +174,7 @@ function getRebuildInterwikiSQL() {
                        $lang = $matches[1];
                        $host = "$lang." . $site->url;
                        $sql .= "\n--$host\n\n";
-                       
+
                        $sql .= "USE $db;\n" .
                                        "TRUNCATE TABLE interwiki;\n" .
                                        "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES\n";
@@ -183,8 +183,8 @@ function getRebuildInterwikiSQL() {
                        # Intermap links
                        foreach ( $iwArray as $iwEntry ) {
                                # Suppress links with the same name as the site
-                               if ( ( $suffix == 'wiki' && $iwEntry['iw_prefix'] != 'wikipedia' ) || 
-                                 ( $suffix != 'wiki' && $suffix != $iwEntry['iw_prefix'] ) ) 
+                               if ( ( $suffix == 'wiki' && $iwEntry['iw_prefix'] != 'wikipedia' ) ||
+                                 ( $suffix != 'wiki' && $suffix != $iwEntry['iw_prefix'] ) )
                                {
                                        $sql .= makeLink( $iwEntry, $first, $db );
                                }
@@ -206,9 +206,9 @@ function getRebuildInterwikiSQL() {
                        if ( $site->suffix == "wiki" ) {
                                $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";