r95816 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95815‎ | r95816 | r95817 >
Date:22:14, 30 August 2011
Author:ckepper
Status:ok (Comments)
Tags:
Comment:
fixed bug 24512 (removed curlreq()) and cleaned up parameters for mwServeCommand()
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.body.php
@@ -1060,7 +1060,8 @@
10611061
10621062 $template = new CollectionRenderingTemplate();
10631063 $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'] );
10651066 $wgOut->addTemplate( $template );
10661067 break;
10671068 case 'finished':
@@ -1082,24 +1083,28 @@
10831084 global $wgOut;
10841085 global $wgRequest;
10851086 global $wgCollectionContentTypeToFilename;
1086 -
 1087+
10871088 $tempfile = tmpfile();
10881089 $r = self::mwServeCommand( 'render_status', array(
10891090 'collection_id' => $wgRequest->getVal( 'collection_id' ),
10901091 'writer' => $wgRequest->getVal( 'writer' ),
10911092 ) );
1092 - $errorMessage = '';
 1093+
10931094 $info = false;
10941095 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+ }
10961101 $content_type = $r['content_type'];
10971102 $content_length = $r['content_length'];
10981103 $content_disposition = $r['content_disposition'];
10991104 } else {
11001105 $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+ ) );
11041109 $content_type = $info['content_type'];
11051110 $content_length = $info['download_content_length'];
11061111 $content_disposition = null;
@@ -1202,7 +1207,7 @@
12031208 $wgOut->addTemplate( $template );
12041209 }
12051210
1206 - static function mwServeCommand( $command, $args, $timeout = true, $toFile = null ) {
 1211+ static function mwServeCommand( $command, $args ) {
12071212 global $wgOut;
12081213 global $wgCollectionMWServeURL;
12091214 global $wgCollectionMWServeCredentials;
@@ -1216,22 +1221,13 @@
12171222 if ( $wgCollectionMWServeCredentials ) {
12181223 $args['login_credentials'] = $wgCollectionMWServeCredentials;
12191224 }
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));
12301226
12311227 if ( !$response ) {
12321228 $wgOut->showErrorPage(
12331229 'coll-post_failed_title',
12341230 'coll-post_failed_msg',
1235 - array( $wgCollectionMWServeURL, $errorMessage )
 1231+ array( $wgCollectionMWServeURL )
12361232 );
12371233 return false;
12381234 }
@@ -1260,63 +1256,4 @@
12611257 return $json_response;
12621258 }
12631259
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 - }
13231260 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r95841cleaned up whitespace and indentation according to coding conventionsckepper08:44, 31 August 2011

Comments

#Comment by Jack Phoenix (talk | contribs)   23:58, 30 August 2011
+			if ( !isset( $response['status']['progress'] ) ) $response['status']['progress'] = 1.00;

Needs more braces.

Also, our coding conventions aren't followed here; indentation is wonky (either just spaces or tabs and spaces). Our standard is to use tabs to indent code in most cases (see the coding conventions page for the few exceptions, i.e. vertical alignment).

Status & tagging log