Merge "Use interwiki cache directly to resolve transwiki import sources"
[lhc/web/wiklou.git] / includes / Import.php
index 33ab4ea..f0576d7 100644 (file)
@@ -515,6 +515,7 @@ class WikiImporter {
                while ( $this->reader->read() ) {
                        switch ( $this->reader->nodeType ) {
                        case XMLReader::TEXT:
+                       case XMLReader::CDATA:
                        case XMLReader::SIGNIFICANT_WHITESPACE:
                                $buffer .= $this->reader->value;
                                break;
@@ -1963,23 +1964,38 @@ class ImportStreamSource implements ImportSource {
                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( strtr( "${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" );
        }
 }