r22199 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22198‎ | r22199 | r22200 >
Date:01:56, 16 May 2007
Author:suuch
Status:old
Tags:
Comment:
Renamed my_file_get_contents to more obvious curl_file_get_contents
Modified paths:
  • /branches/instantcommons/includes/Image.php (modified) (history)

Diff [purge]

Index: branches/instantcommons/includes/Image.php
@@ -371,7 +371,7 @@
372372 $rname=tempnam(wfTempDir(),'icresponse.xml');
373373 $url = $wgInstantCommonsServerPath.'/api.php?action=instantcommons&format=xml&media='.$this->name;
374374 $fp = fopen($rname, "w");
375 - $xmlString = $this-> my_file_get_contents($url, $fp);
 375+ $xmlString = $this-> curl_file_get_contents($url, $fp);
376376 $p =& new ApiInstantCommons('instantcommons', 'maint');
377377 fclose($fp);
378378 //TODO: Replace the xml-parser with a preg_grep since it's a single line of XML that's returned.
@@ -394,12 +394,12 @@
395395 $icFileUrl = $wgInstantCommonsServerPath.$row['URL'];
396396 $fp = fopen("{$this->mSavedFile}", "w");
397397 if($row['SIZE'] > 3000) {wfDebug(join($row, ' | '));
398 - $this-> my_file_get_contents($icFileUrl, $this->mSavedFile, TRUE);
 398+ $this-> curl_file_get_contents($icFileUrl, $this->mSavedFile, TRUE);
399399 }else {
400400 /*
401401 $icFileUrl = $wgInstantCommonsServerPath.$row['URL'];
402402 $icFp = fopen("{$this->mSavedFile}", "w");
403 - my_file_get_contents($icFileUrl, $icFp);
 403+ curl_file_get_contents($icFileUrl, $icFp);
404404 fclose($icFp);*/
405405
406406 $ch = curl_init($wgInstantCommonsServerPath.$row['URL']);
@@ -456,8 +456,33 @@
457457 $this->dataLoaded = true;
458458 wfProfileOut( __METHOD__ );
459459 }
 460+
 461+ /**
 462+ * Use cURL to read the content of a URL into a string
 463+ * @param string $url - the URL to fetch
 464+ * @param resource $fp - filename to write file contents to
 465+ * @param boolean $bg - call cURL in the background (don't hang page until complete)
 466+ * @param int $timeout - cURL connect timeout
 467+ */
 468+ function curl_file_get_contents($url, $fp, $bg=FALSE, $timeout = 1){//ref: http://groups-beta.google.com/group/comp.lang.php/browse_thread/thread/8efbbaced3c45e3c/d63c7891cf8e380b?lnk=raot
 469+ if(!$bg){
 470+ $ch = curl_init();
 471+ curl_setopt ($ch, CURLOPT_URL, $url);
 472+ curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
 473+ curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
 474+ curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
 475+ $file_contents = curl_exec($ch);
 476+ curl_close($ch);
 477+ } else {//call curl in the background to download the file
 478+ $cmd = 'curl '.escapeshellcmd($url).' -o '.$fp.'&';
 479+ wfDebug('Curl download initiated='.$cmd );
 480+ pclose(popen($cmd, 'r'));
 481+ $file_contents = 1;
 482+ }
 483+ return $file_contents;
 484+ }
460485
461 - /*
 486+ /**
462487 * Load image metadata from a DB result row
463488 */
464489 function loadFromRow( &$row ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r22200Merged InstantCommons changes with trunk @r22199suuch02:04, 16 May 2007

Status & tagging log