r96139 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96138‎ | r96139 | r96140 >
Date:18:28, 2 September 2011
Author:catrope
Status:ok
Tags:
Comment:
Merge r96132 from 1.17wmf1: support protocol-relative URLs in dumpInterwiki.php
Modified paths:
  • /trunk/phase3/maintenance/Site.php (modified) (history)
  • /trunk/phase3/maintenance/dumpInterwiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/Site.php
@@ -12,8 +12,8 @@
1313 $this->url = $u;
1414 }
1515
16 - function getURL( $lang ) {
 16+ function getURL( $lang, $urlprotocol ) {
1717 $xlang = str_replace( '_', '-', $lang );
18 - return "http://$xlang.{$this->url}/wiki/\$1";
 18+ return "$urlprotocol//$xlang.{$this->url}/wiki/\$1";
1919 }
20 -}
\ No newline at end of file
 20+}
Index: trunk/phase3/maintenance/dumpInterwiki.php
@@ -37,6 +37,7 @@
3838 $this->addOption( 'dblist', 'File with one db per line', false, true );
3939 $this->addOption( 'specialdbs', "File with one 'special' db per line", false, true );
4040 $this->addOption( 'o', 'Cdb output file', false, true );
 41+ $this->addOption( 'protocolrelative', 'Output wikimedia interwiki urls as protocol relative', false, false );
4142 }
4243
4344 function execute() {
@@ -55,6 +56,12 @@
5657 $this->dbFile = false;
5758 }
5859
 60+ if ( $this->hasOption( 'protocolrelative' ) ) {
 61+ $this->urlprotocol = '';
 62+ } else {
 63+ $this->urlprotocol = 'http:';
 64+ }
 65+
5966 $this->getRebuildInterwikiDump();
6067 }
6168
@@ -76,9 +83,9 @@
7784
7885 # Extra interwiki links that can't be in the intermap for some reason
7986 $extraLinks = array(
80 - array( 'm', 'http://meta.wikimedia.org/wiki/$1', 1 ),
81 - array( 'meta', 'http://meta.wikimedia.org/wiki/$1', 1 ),
82 - array( 'sep11', 'http://sep11.wikipedia.org/wiki/$1', 1 ),
 87+ array( 'm', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ),
 88+ array( 'meta', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ),
 89+ array( 'sep11', $this->urlprotocol . '//sep11.wikipedia.org/wiki/$1', 1 ),
8390 );
8491
8592 # Language aliases, usually configured as redirects to the real wiki in apache
@@ -126,6 +133,13 @@
127134
128135 $url = $matches[2];
129136 if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) {
 137+ if ( $this->hasOption( 'protocolrelative' ) ) {
 138+ if ( substr( $url, 0, 5 ) == 'http:' ) {
 139+ $url = substr( $url, 5 );
 140+ } else if ( substr( $url, 0, 6 ) == 'https:' ) {
 141+ $url = substr( $url, 6 );
 142+ }
 143+ }
130144 $local = 1;
131145 } else {
132146 $local = 0;
@@ -155,7 +169,7 @@
156170 # Links to multilanguage sites
157171 foreach ( $sites as $targetSite ) {
158172 $this->makeLink( array( 'iw_prefix' => $targetSite->lateral,
159 - 'iw_url' => $targetSite->getURL( 'en' ),
 173+ 'iw_url' => $targetSite->getURL( 'en', $this->urlprotocol ),
160174 'iw_local' => 1 ), $db );
161175 }
162176 } else {
@@ -179,14 +193,14 @@
180194 foreach ( $sites as $targetSite ) {
181195 if ( $targetSite->suffix != $site->suffix ) {
182196 $this->makeLink( array( 'iw_prefix' => $targetSite->lateral,
183 - 'iw_url' => $targetSite->getURL( $lang ),
 197+ 'iw_url' => $targetSite->getURL( $lang, $this->urlprotocol ),
184198 'iw_local' => 1 ), $db );
185199 }
186200 }
187201
188202 if ( $site->suffix == "wiki" ) {
189203 $this->makeLink( array( 'iw_prefix' => 'w',
190 - 'iw_url' => "http://en.wikipedia.org/wiki/$1",
 204+ 'iw_url' => $this->urlprotocol . "//en.wikipedia.org/wiki/$1",
191205 'iw_local' => 1 ), $db );
192206 }
193207
@@ -214,12 +228,12 @@
215229 function makeLanguageLinks( &$site, $source ) {
216230 # Actual languages with their own databases
217231 foreach ( $this->langlist as $targetLang ) {
218 - $this->makeLink( array( $targetLang, $site->getURL( $targetLang ), 1 ), $source );
 232+ $this->makeLink( array( $targetLang, $site->getURL( $targetLang, $this->urlprotocol ), 1 ), $source );
219233 }
220234
221235 # Language aliases
222236 foreach ( $this->languageAliases as $alias => $lang ) {
223 - $this->makeLink( array( $alias, $site->getURL( $lang ), 1 ), $source );
 237+ $this->makeLink( array( $alias, $site->getURL( $lang, $this->urlprotocol ), 1 ), $source );
224238 }
225239 }
226240

Follow-up revisions

RevisionCommit summaryAuthorDate
r96529Tweaks to WikimediaMaintenance:...demon00:35, 8 September 2011
r982391.18wmf1: MFT r96139catrope19:46, 27 September 2011
r984461.18: MFT r93912, r95318, r96139reedy20:59, 29 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96132Add support in for making a cdb with protocol relative interwiki links.laner17:51, 2 September 2011

Status & tagging log