* (bug 5161) Don't try to load template list for nonexistent pages
[lhc/web/wiklou.git] / maintenance / rebuildInterwiki.inc
index 48db503..fea5f64 100644 (file)
@@ -50,7 +50,7 @@ function getRebuildInterwikiSQL() {
 
        # List of all database names
        $dblist = array_map( "trim", file( "/home/wikipedia/common/all.dblist" ) );
-       
+
        # Special-case hostnames
        $specials = array(
                'sourceswiki' => 'sources.wikipedia.org',
@@ -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" .
                                        "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";
@@ -206,7 +206,7 @@ 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 ){
                                        $sql .= makeLink( $link, $first, $db );