Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -11,34 +11,36 @@ |
12 | 12 | const ASYNC_DOWNLOAD = 2; // asynchronous upload we should spawn out another process and monitor progress if possible) |
13 | 13 | |
14 | 14 | var $body = ''; |
15 | | - public static function request( $url, $opts = array() ) { |
| 15 | + public static function request($method, $url, $opts = Array() ){ |
| 16 | + $opts['method'] = ( strtoupper( $method ) == 'GET' || strtoupper( $method ) == 'POST' ) ? strtoupper( $method ) : null; |
16 | 17 | $req = new HttpRequest( $url, $opts ); |
17 | 18 | $status = $req->doRequest(); |
18 | 19 | if( $status->isOK() ){ |
19 | 20 | return $status->value; |
20 | 21 | } else { |
| 22 | + wfDebug( 'http error: ' . $status->getWikiText() ); |
21 | 23 | return false; |
22 | 24 | } |
23 | 25 | } |
24 | | - |
25 | 26 | /** |
26 | 27 | * Simple wrapper for Http::request( 'GET' ) |
27 | 28 | */ |
28 | | - public static function get( $url, $opts = array() ) { |
29 | | - $opt['method'] = 'GET'; |
30 | | - return Http::request( $url, $opts ); |
| 29 | + public static function get( $url, $timeout = false) { |
| 30 | + $opts = Array(); |
| 31 | + if( $timeout ) |
| 32 | + $opts['timeout'] = $timeout; |
| 33 | + return Http::request( 'GET', $url, $opts ); |
31 | 34 | } |
32 | 35 | |
33 | 36 | /** |
34 | 37 | * Simple wrapper for Http::request( 'POST' ) |
35 | 38 | */ |
36 | 39 | public static function post( $url, $opts = array() ) { |
37 | | - $opts['method'] = 'POST'; |
38 | | - return Http::request( $url, $opts ); |
| 40 | + return Http::request( 'POST', $url, $opts ); |
39 | 41 | } |
40 | 42 | |
41 | 43 | public static function doDownload( $url, $target_file_path , $dl_mode = self::SYNC_DOWNLOAD , $redirectCount = 0 ){ |
42 | | - global $wgPhpCliPath, $wgMaxUploadSize, $wgMaxRedirects; |
| 44 | + global $wgPhpCli, $wgMaxUploadSize, $wgMaxRedirects; |
43 | 45 | // do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize |
44 | 46 | $head = get_headers( $url, 1 ); |
45 | 47 | |
— | — | @@ -67,7 +69,7 @@ |
68 | 70 | } |
69 | 71 | |
70 | 72 | // check if we can find phpCliPath (for doing a background shell request to php to do the download: |
71 | | - if( $wgPhpCliPath && wfShellExecEnabled() && $dl_mode == self::ASYNC_DOWNLOAD ){ |
| 73 | + if( $wgPhpCli && wfShellExecEnabled() && $dl_mode == self::ASYNC_DOWNLOAD ){ |
72 | 74 | wfDebug( __METHOD__ . "\ASYNC_DOWNLOAD\n" ); |
73 | 75 | // setup session and shell call: |
74 | 76 | return self::initBackgroundDownload( $url, $target_file_path, $content_length ); |
— | — | @@ -87,7 +89,7 @@ |
88 | 90 | * |
89 | 91 | */ |
90 | 92 | private function initBackgroundDownload( $url, $target_file_path, $content_length = null ){ |
91 | | - global $wgMaxUploadSize, $IP, $wgPhpCliPath; |
| 93 | + global $wgMaxUploadSize, $IP, $wgPhpCli; |
92 | 94 | $status = Status::newGood(); |
93 | 95 | |
94 | 96 | // generate a session id with all the details for the download (pid, target_file_path ) |
— | — | @@ -105,7 +107,7 @@ |
106 | 108 | $_SESSION['wsDownload'][$upload_session_key]['loaded'] = 0; |
107 | 109 | |
108 | 110 | // run the background download request: |
109 | | - $cmd = $wgPhpCliPath . ' ' . $IP . "/maintenance/http_session_download.php --sid {$session_id} --usk {$upload_session_key}"; |
| 111 | + $cmd = $wgPhpCli . ' ' . $IP . "/maintenance/http_session_download.php --sid {$session_id} --usk {$upload_session_key}"; |
110 | 112 | $pid = wfShellBackgroundExec( $cmd, $retval ); |
111 | 113 | // the pid is not of much use since we won't be visiting this same apache any-time soon. |
112 | 114 | if( !$pid ) |