Merge r96132 from 1.17wmf1: support protocol-relative URLs in dumpInterwiki.php
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 2 Sep 2011 18:28:28 +0000 (18:28 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 2 Sep 2011 18:28:28 +0000 (18:28 +0000)
maintenance/Site.php
maintenance/dumpInterwiki.php

index 85e0126..87d637b 100644 (file)
@@ -12,8 +12,8 @@ class Site {
                $this->url = $u;
        }
 
-       function getURL( $lang ) {
+       function getURL( $lang, $urlprotocol ) {
                $xlang = str_replace( '_', '-', $lang );
-               return "http://$xlang.{$this->url}/wiki/\$1";
+               return "$urlprotocol//$xlang.{$this->url}/wiki/\$1";
        }
-}
\ No newline at end of file
+}
index 254ebb5..e1170bd 100644 (file)
@@ -37,6 +37,7 @@ class DumpInterwiki extends Maintenance {
                $this->addOption( 'dblist', 'File with one db per line', false, true );
                $this->addOption( 'specialdbs', "File with one 'special' db per line", false, true );
                $this->addOption( 'o', 'Cdb output file', false, true );
+               $this->addOption( 'protocolrelative', 'Output wikimedia interwiki urls as protocol relative', false, false );
        }
 
        function execute() {
@@ -55,6 +56,12 @@ class DumpInterwiki extends Maintenance {
                        $this->dbFile = false;
                }
 
+               if ( $this->hasOption( 'protocolrelative' ) ) {
+                       $this->urlprotocol = '';
+               } else {
+                       $this->urlprotocol = 'http:';
+               }
+
                $this->getRebuildInterwikiDump();
        }
 
@@ -76,9 +83,9 @@ class DumpInterwiki extends Maintenance {
 
                # Extra interwiki links that can't be in the intermap for some reason
                $extraLinks = array(
-                       array( 'm', 'http://meta.wikimedia.org/wiki/$1', 1 ),
-                       array( 'meta', 'http://meta.wikimedia.org/wiki/$1', 1 ),
-                       array( 'sep11', 'http://sep11.wikipedia.org/wiki/$1', 1 ),
+                       array( 'm', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ),
+                       array( 'meta', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ),
+                       array( 'sep11', $this->urlprotocol . '//sep11.wikipedia.org/wiki/$1', 1 ),
                );
 
                # Language aliases, usually configured as redirects to the real wiki in apache
@@ -126,6 +133,13 @@ class DumpInterwiki extends Maintenance {
 
                                $url = $matches[2];
                                if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) {
+                                       if ( $this->hasOption( 'protocolrelative' ) ) {
+                                               if ( substr( $url, 0, 5 ) == 'http:' ) {
+                                                       $url = substr( $url, 5 );
+                                               } else if ( substr( $url, 0, 6 ) == 'https:' ) {
+                                                       $url = substr( $url, 6 );
+                                               }
+                                       }
                                        $local = 1;
                                } else {
                                        $local = 0;
@@ -155,7 +169,7 @@ class DumpInterwiki extends Maintenance {
                                # Links to multilanguage sites
                                foreach ( $sites as $targetSite ) {
                                        $this->makeLink( array( 'iw_prefix' => $targetSite->lateral,
-                                               'iw_url' => $targetSite->getURL( 'en' ),
+                                               'iw_url' => $targetSite->getURL( 'en', $this->urlprotocol ),
                                                'iw_local' => 1 ), $db );
                                }
                        } else {
@@ -179,14 +193,14 @@ class DumpInterwiki extends Maintenance {
                                foreach ( $sites as $targetSite ) {
                                        if ( $targetSite->suffix != $site->suffix ) {
                                                $this->makeLink( array( 'iw_prefix' => $targetSite->lateral,
-                                                       'iw_url' => $targetSite->getURL( $lang ),
+                                                       'iw_url' => $targetSite->getURL( $lang, $this->urlprotocol ),
                                                        'iw_local' => 1 ), $db );
                                        }
                                }
 
                                if ( $site->suffix == "wiki" ) {
                                        $this->makeLink( array( 'iw_prefix' => 'w',
-                                               'iw_url' => "http://en.wikipedia.org/wiki/$1",
+                                               'iw_url' => $this->urlprotocol . "//en.wikipedia.org/wiki/$1",
                                                'iw_local' => 1 ), $db );
                                }
 
@@ -214,12 +228,12 @@ class DumpInterwiki extends Maintenance {
        function makeLanguageLinks( &$site, $source ) {
                # Actual languages with their own databases
                foreach ( $this->langlist as $targetLang ) {
-                       $this->makeLink( array( $targetLang, $site->getURL( $targetLang ), 1 ), $source );
+                       $this->makeLink( array( $targetLang, $site->getURL( $targetLang, $this->urlprotocol ), 1 ), $source );
                }
 
                # Language aliases
                foreach ( $this->languageAliases as $alias => $lang ) {
-                       $this->makeLink( array( $alias, $site->getURL( $lang ), 1 ), $source );
+                       $this->makeLink( array( $alias, $site->getURL( $lang, $this->urlprotocol ), 1 ), $source );
                }
        }