r22077 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22076‎ | r22077 | r22078 >
Date:19:13, 10 May 2007
Author:river
Status:old
Tags:
Comment:
- Http::request(), Http::post()
- don't redirect page views on POST
- Special:Export shouldn't do POST special case when page name provided
- Special:Import should use POST for interwiki fetches
Modified paths:
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)
  • /trunk/phase3/includes/SpecialExport.php (modified) (history)
  • /trunk/phase3/includes/SpecialImport.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialImport.php
@@ -857,13 +857,13 @@
858858 }
859859 }
860860
861 - function newFromURL( $url ) {
 861+ function newFromURL( $url, $method = 'GET' ) {
862862 wfDebug( __METHOD__ . ": opening $url\n" );
863863 # Use the standard HTTP fetch function; it times out
864864 # quicker and sorts out user-agent problems which might
865865 # otherwise prevent importing from large sites, such
866866 # as the Wikimedia cluster, etc.
867 - $data = Http::get( $url );
 867+ $data = Http::request( $method, $url );
868868 if( $data !== false ) {
869869 $file = tmpfile();
870870 fwrite( $file, $data );
@@ -882,7 +882,8 @@
883883 } else {
884884 $params = $history ? 'history=1' : '';
885885 $url = $link->getFullUrl( $params );
886 - return ImportStreamSource::newFromURL( $url );
 886+ # For interwikis, use POST to avoid redirects.
 887+ return ImportStreamSource::newFromURL( $url, "POST" );
887888 }
888889 }
889890 }
Index: trunk/phase3/includes/Wiki.php
@@ -158,7 +158,7 @@
159159 $title = SpecialPage::getTitleFor( 'Badtitle' );
160160 throw new ErrorPageError( 'badtitle', 'badtitletext' );
161161 }
162 - } else if ( ( $action == 'view' ) &&
 162+ } else if ( ( $action == 'view' ) && !$wgRequest->wasPosted() &&
163163 (!isset( $this->GET['title'] ) || $title->getPrefixedDBKey() != $this->GET['title'] ) &&
164164 !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
165165 {
Index: trunk/phase3/includes/SpecialExport.php
@@ -71,7 +71,7 @@
7272 }
7373 }
7474 }
75 - else if( $wgRequest->wasPosted() ) {
 75+ else if( $wgRequest->wasPosted() && $page == '' ) {
7676 $page = $wgRequest->getText( 'pages' );
7777 $curonly = $wgRequest->getCheck( 'curonly' );
7878 $rawOffset = $wgRequest->getVal( 'offset' );
Index: trunk/phase3/includes/HttpFunctions.php
@@ -4,12 +4,20 @@
55 * Various HTTP related functions
66 */
77 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+
816 /**
917 * Get the contents of a file by HTTP
1018 *
1119 * if $timeout is 'default', $wgHTTPTimeout is used
1220 */
13 - static function get( $url, $timeout = 'default' ) {
 21+ static function request( $method, $url, $timeout = 'default' ) {
1422 global $wgHTTPTimeout, $wgHTTPProxy, $wgVersion, $wgTitle;
1523
1624 # Use curl if available
@@ -26,6 +34,10 @@
2735 }
2836 curl_setopt( $c, CURLOPT_TIMEOUT, $timeout );
2937 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 );
3042
3143 # Set the referer to $wgTitle, even in command-line mode
3244 # This is useful for interwiki transclusion, where the foreign
@@ -49,8 +61,12 @@
5062 } else {
5163 # Otherwise use file_get_contents, or its compatibility function from GlobalFunctions.php
5264 # 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+
5369 $url_fopen = ini_set( 'allow_url_fopen', 1 );
54 - $text = file_get_contents( $url );
 70+ $text = file_get_contents( $url, false, $ctx );
5571 ini_set( 'allow_url_fopen', $url_fopen );
5672 }
5773 return $text;