TTO has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/184610

Change subject: Use interwiki cache directly to resolve transwiki import sources
......................................................................

Use interwiki cache directly to resolve transwiki import sources

In order to resolve T17583, we will need to have a WMF-wide map of import
sources. This will most likely consist of a project dropdown, e.g.
"wikipedia", "wiktionary", "meta"... and a subproject dropdown, listing
each language edition of the selected project.

This would mean, if we wanted to import a page from French Wikipedia to
English Wikipedia, we would need to select project "wikipedia" and language
"fr". Currently, this causes the error "Bad interwiki link", because the
prefix "wikipedia:" maps to the local project namespace on enwiki, instead
of the relevant interwiki prefix.

To avoid this error we need to bypass Title and directly query the
interwiki map.

Change-Id: I68989203e367e7ea515e4ae2222c330b264a7cb1
---
M includes/Import.php
1 file changed, 31 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/10/184610/1

diff --git a/includes/Import.php b/includes/Import.php
index 97d6edd..848d3b1 100644
--- a/includes/Import.php
+++ b/includes/Import.php
@@ -1867,23 +1867,38 @@
                if ( $page == '' ) {
                        return Status::newFatal( 'import-noarticle' );
                }
-               $link = Title::newFromText( "$interwiki:Special:Export/$page" );
-               if ( is_null( $link ) || !$link->isExternal() ) {
+
+               # Look up the first interwiki prefix, and let the foreign site 
handle
+               # subsequent interwiki prefixes
+               $firstIwPrefix = strtok( $interwiki, ':' );
+               $firstIw = Interwiki::fetch( $firstIwPrefix );
+               if ( !$firstIw ) {
                        return Status::newFatal( 'importbadinterwiki' );
-               } else {
-                       $params = array();
-                       if ( $history ) {
-                               $params['history'] = 1;
-                       }
-                       if ( $templates ) {
-                               $params['templates'] = 1;
-                       }
-                       if ( $pageLinkDepth ) {
-                               $params['pagelink-depth'] = $pageLinkDepth;
-                       }
-                       $url = $link->getFullURL( $params );
-                       # For interwikis, use POST to avoid redirects.
-                       return ImportStreamSource::newFromURL( $url, "POST" );
                }
+
+               $additionalIwPrefixes = strtok( '' );
+               if ( $additionalIwPrefixes ) {
+                       $additionalIwPrefixes .= ':';
+               }
+               # Have to do a DB-key replacement ourselves; otherwise spaces 
get
+               # URL-encoded to +, which is wrong in this case. Similar to 
logic in
+               # Title::getLocalURL
+               $link = $firstIw->getURL( str_replace( ' ', '_',
+                       "${additionalIwPrefixes}Special:Export/$page" ) );
+
+               $params = array();
+               if ( $history ) {
+                       $params['history'] = 1;
+               }
+               if ( $templates ) {
+                       $params['templates'] = 1;
+               }
+               if ( $pageLinkDepth ) {
+                       $params['pagelink-depth'] = $pageLinkDepth;
+               }
+
+               $url = wfAppendQuery( $link, $params );
+               # For interwikis, use POST to avoid redirects.
+               return ImportStreamSource::newFromURL( $url, "POST" );
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/184610
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I68989203e367e7ea515e4ae2222c330b264a7cb1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: TTO <at.li...@live.com.au>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to