Index: trunk/extensions/Collection/Collection.body.php |
— | — | @@ -1060,7 +1060,8 @@ |
1061 | 1061 | |
1062 | 1062 | $template = new CollectionRenderingTemplate(); |
1063 | 1063 | $template->set( 'status', $status ); |
1064 | | - $template->set( 'progress', $response['status']['progress'] ); |
| 1064 | + if ( !isset( $response['status']['progress'] ) ) $response['status']['progress'] = 1.00; |
| 1065 | + $template->set( 'progress', $response['status']['progress'] ); |
1065 | 1066 | $wgOut->addTemplate( $template ); |
1066 | 1067 | break; |
1067 | 1068 | case 'finished': |
— | — | @@ -1082,24 +1083,28 @@ |
1083 | 1084 | global $wgOut; |
1084 | 1085 | global $wgRequest; |
1085 | 1086 | global $wgCollectionContentTypeToFilename; |
1086 | | - |
| 1087 | + |
1087 | 1088 | $tempfile = tmpfile(); |
1088 | 1089 | $r = self::mwServeCommand( 'render_status', array( |
1089 | 1090 | 'collection_id' => $wgRequest->getVal( 'collection_id' ), |
1090 | 1091 | 'writer' => $wgRequest->getVal( 'writer' ), |
1091 | 1092 | ) ); |
1092 | | - $errorMessage = ''; |
| 1093 | + |
1093 | 1094 | $info = false; |
1094 | 1095 | if ( isset( $r['url'] ) ) { |
1095 | | - self::curlreq( 'GET', $r['url'], array(), $errorMessage, $info, $timeout = false, $toFile = $tempfile ); |
| 1096 | + $result = Http::get( $r['url'] ); |
| 1097 | + if ($result) { |
| 1098 | + fwrite($tempfile, $result); |
| 1099 | + $info = true; |
| 1100 | + } |
1096 | 1101 | $content_type = $r['content_type']; |
1097 | 1102 | $content_length = $r['content_length']; |
1098 | 1103 | $content_disposition = $r['content_disposition']; |
1099 | 1104 | } else { |
1100 | 1105 | $info = self::mwServeCommand( 'download', array( |
1101 | | - 'collection_id' => $wgRequest->getVal( 'collection_id' ), |
1102 | | - 'writer' => $wgRequest->getVal( 'writer' ), |
1103 | | - ), $timeout = false, $toFile = $tempfile ); |
| 1106 | + 'collection_id' => $wgRequest->getVal( 'collection_id' ), |
| 1107 | + 'writer' => $wgRequest->getVal( 'writer' ), |
| 1108 | + ) ); |
1104 | 1109 | $content_type = $info['content_type']; |
1105 | 1110 | $content_length = $info['download_content_length']; |
1106 | 1111 | $content_disposition = null; |
— | — | @@ -1202,7 +1207,7 @@ |
1203 | 1208 | $wgOut->addTemplate( $template ); |
1204 | 1209 | } |
1205 | 1210 | |
1206 | | - static function mwServeCommand( $command, $args, $timeout = true, $toFile = null ) { |
| 1211 | + static function mwServeCommand( $command, $args ) { |
1207 | 1212 | global $wgOut; |
1208 | 1213 | global $wgCollectionMWServeURL; |
1209 | 1214 | global $wgCollectionMWServeCredentials; |
— | — | @@ -1216,22 +1221,13 @@ |
1217 | 1222 | if ( $wgCollectionMWServeCredentials ) { |
1218 | 1223 | $args['login_credentials'] = $wgCollectionMWServeCredentials; |
1219 | 1224 | } |
1220 | | - $errorMessage = ''; |
1221 | | - $info = false; |
1222 | | - $response = self::curlreq( 'POST', $serveURL, $args, $errorMessage, $info, $timeout, $toFile ); |
1223 | | - if ( $toFile ) { |
1224 | | - if ( $info ) { |
1225 | | - return $info; |
1226 | | - } else { |
1227 | | - return array( 'error' => $errorMessage ); |
1228 | | - } |
1229 | | - } |
| 1225 | + $response = Http::post($serveURL, array('postData' => $args)); |
1230 | 1226 | |
1231 | 1227 | if ( !$response ) { |
1232 | 1228 | $wgOut->showErrorPage( |
1233 | 1229 | 'coll-post_failed_title', |
1234 | 1230 | 'coll-post_failed_msg', |
1235 | | - array( $wgCollectionMWServeURL, $errorMessage ) |
| 1231 | + array( $wgCollectionMWServeURL ) |
1236 | 1232 | ); |
1237 | 1233 | return false; |
1238 | 1234 | } |
— | — | @@ -1260,63 +1256,4 @@ |
1261 | 1257 | return $json_response; |
1262 | 1258 | } |
1263 | 1259 | |
1264 | | - static function curlreq( $method, $url, $postFields, &$errorMessage, &$info, |
1265 | | - $timeout = true, $toFile = null ) { |
1266 | | - global $wgHTTPTimeout, $wgHTTPProxy, $wgTitle, $wgRequest, $wgVersion; |
1267 | | - global $wgCollectionMWServeCert; |
1268 | | - global $wgCollectionVersion; |
1269 | | - |
1270 | | - if ( $method == 'GET' ) { |
1271 | | - $url = wfAppendQuery( $url, wfArrayToCGI( $postFields ) ); |
1272 | | - } |
1273 | | - $c = curl_init( $url ); |
1274 | | - curl_setopt( $c, CURLOPT_PROXY, $wgHTTPProxy ); |
1275 | | - $userAgent = $wgRequest->getHeader( 'User-Agent' ); |
1276 | | - if ( !$userAgent ) { |
1277 | | - $userAgent = "Unknown user agent"; |
1278 | | - } |
1279 | | - $userAgent .= " (via MediaWiki/$wgVersion, Collection/$wgCollectionVersion)"; |
1280 | | - curl_setopt( $c, CURLOPT_USERAGENT, $userAgent ); |
1281 | | - if ( $method == 'POST' ) { |
1282 | | - curl_setopt( $c, CURLOPT_POST, true ); |
1283 | | - curl_setopt( $c, CURLOPT_POSTFIELDS, $postFields ); |
1284 | | - } |
1285 | | - curl_setopt( $c, CURLOPT_HTTPHEADER, array( 'Expect:' ) ); |
1286 | | - curl_setopt( $c, CURLOPT_HEADER, false ); |
1287 | | - if ( is_object( $wgTitle ) ) { |
1288 | | - curl_setopt( $c, CURLOPT_REFERER, wfExpandUrl( $wgTitle->getFullURL(), PROTO_CURRENT ) ); |
1289 | | - } |
1290 | | - if ( $timeout ) { |
1291 | | - curl_setopt( $c, CURLOPT_TIMEOUT, $wgHTTPTimeout ); |
1292 | | - } |
1293 | | - /* Allow the use of self-signed certificates by referencing |
1294 | | - * a local (to the mediawiki install) copy of the signing |
1295 | | - * certificate */ |
1296 | | - if ( !( $wgCollectionMWServeCert === null ) ) { |
1297 | | - curl_setopt ( $c, CURLOPT_SSL_VERIFYPEER, TRUE ); |
1298 | | - curl_setopt ( $c, CURLOPT_CAINFO, $wgCollectionMWServeCert ); |
1299 | | - } |
1300 | | - |
1301 | | - if ( $toFile ) { |
1302 | | - curl_setopt( $c, CURLOPT_FILE, $toFile ); |
1303 | | - } else { |
1304 | | - curl_setopt( $c, CURLOPT_RETURNTRANSFER, true ); |
1305 | | - } |
1306 | | - $result = curl_exec( $c ); |
1307 | | - $text = false; |
1308 | | - $info = false; |
1309 | | - if ( curl_errno( $c ) != CURLE_OK ) { |
1310 | | - $errorMessage = curl_error( $c ); |
1311 | | - } elseif ( curl_getinfo( $c, CURLINFO_HTTP_CODE ) != 200 ) { |
1312 | | - $errorMessage = 'HTTP status ' . curl_getinfo( $c, CURLINFO_HTTP_CODE ); |
1313 | | - } else { |
1314 | | - $info = curl_getinfo( $c ); |
1315 | | - if ( !$toFile ) { |
1316 | | - $text = $result; |
1317 | | - } |
1318 | | - $errorMessage = ''; |
1319 | | - } |
1320 | | - curl_close( $c ); |
1321 | | - return $text; |
1322 | | - } |
1323 | 1260 | } |