Index: trunk/phase3/includes/SpecialImport.php |
— | — | @@ -857,13 +857,13 @@ |
858 | 858 | } |
859 | 859 | } |
860 | 860 | |
861 | | - function newFromURL( $url ) { |
| 861 | + function newFromURL( $url, $method = 'GET' ) { |
862 | 862 | wfDebug( __METHOD__ . ": opening $url\n" ); |
863 | 863 | # Use the standard HTTP fetch function; it times out |
864 | 864 | # quicker and sorts out user-agent problems which might |
865 | 865 | # otherwise prevent importing from large sites, such |
866 | 866 | # as the Wikimedia cluster, etc. |
867 | | - $data = Http::get( $url ); |
| 867 | + $data = Http::request( $method, $url ); |
868 | 868 | if( $data !== false ) { |
869 | 869 | $file = tmpfile(); |
870 | 870 | fwrite( $file, $data ); |
— | — | @@ -882,7 +882,8 @@ |
883 | 883 | } else { |
884 | 884 | $params = $history ? 'history=1' : ''; |
885 | 885 | $url = $link->getFullUrl( $params ); |
886 | | - return ImportStreamSource::newFromURL( $url ); |
| 886 | + # For interwikis, use POST to avoid redirects. |
| 887 | + return ImportStreamSource::newFromURL( $url, "POST" ); |
887 | 888 | } |
888 | 889 | } |
889 | 890 | } |
Index: trunk/phase3/includes/Wiki.php |
— | — | @@ -158,7 +158,7 @@ |
159 | 159 | $title = SpecialPage::getTitleFor( 'Badtitle' ); |
160 | 160 | throw new ErrorPageError( 'badtitle', 'badtitletext' ); |
161 | 161 | } |
162 | | - } else if ( ( $action == 'view' ) && |
| 162 | + } else if ( ( $action == 'view' ) && !$wgRequest->wasPosted() && |
163 | 163 | (!isset( $this->GET['title'] ) || $title->getPrefixedDBKey() != $this->GET['title'] ) && |
164 | 164 | !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) ) |
165 | 165 | { |
Index: trunk/phase3/includes/SpecialExport.php |
— | — | @@ -71,7 +71,7 @@ |
72 | 72 | } |
73 | 73 | } |
74 | 74 | } |
75 | | - else if( $wgRequest->wasPosted() ) { |
| 75 | + else if( $wgRequest->wasPosted() && $page == '' ) { |
76 | 76 | $page = $wgRequest->getText( 'pages' ); |
77 | 77 | $curonly = $wgRequest->getCheck( 'curonly' ); |
78 | 78 | $rawOffset = $wgRequest->getVal( 'offset' ); |
Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -4,12 +4,20 @@ |
5 | 5 | * Various HTTP related functions |
6 | 6 | */ |
7 | 7 | class Http { |
| 8 | + static function get( $url, $timeout = 'default' ) { |
| 9 | + return request( "GET", $url, $timeout ); |
| 10 | + } |
| 11 | + |
| 12 | + static function post( $url, $timeout = 'default' ) { |
| 13 | + return request( "POST", $url, $timeout ); |
| 14 | + } |
| 15 | + |
8 | 16 | /** |
9 | 17 | * Get the contents of a file by HTTP |
10 | 18 | * |
11 | 19 | * if $timeout is 'default', $wgHTTPTimeout is used |
12 | 20 | */ |
13 | | - static function get( $url, $timeout = 'default' ) { |
| 21 | + static function request( $method, $url, $timeout = 'default' ) { |
14 | 22 | global $wgHTTPTimeout, $wgHTTPProxy, $wgVersion, $wgTitle; |
15 | 23 | |
16 | 24 | # Use curl if available |
— | — | @@ -26,6 +34,10 @@ |
27 | 35 | } |
28 | 36 | curl_setopt( $c, CURLOPT_TIMEOUT, $timeout ); |
29 | 37 | curl_setopt( $c, CURLOPT_USERAGENT, "MediaWiki/$wgVersion" ); |
| 38 | + if ( $method == 'POST' ) |
| 39 | + curl_setopt( $c, CURLOPT_POST, true ); |
| 40 | + else |
| 41 | + curl_setopt( $c, CURLOPT_CUSTOMREQUEST, $method ); |
30 | 42 | |
31 | 43 | # Set the referer to $wgTitle, even in command-line mode |
32 | 44 | # This is useful for interwiki transclusion, where the foreign |
— | — | @@ -49,8 +61,12 @@ |
50 | 62 | } else { |
51 | 63 | # Otherwise use file_get_contents, or its compatibility function from GlobalFunctions.php |
52 | 64 | # This may take 3 minutes to time out, and doesn't have local fetch capabilities |
| 65 | + |
| 66 | + $opts = array('http' => array( 'method' => $method ) ); |
| 67 | + $ctx = stream_context_create($opts); |
| 68 | + |
53 | 69 | $url_fopen = ini_set( 'allow_url_fopen', 1 ); |
54 | | - $text = file_get_contents( $url ); |
| 70 | + $text = file_get_contents( $url, false, $ctx ); |
55 | 71 | ini_set( 'allow_url_fopen', $url_fopen ); |
56 | 72 | } |
57 | 73 | return $text; |