Last modified: 2014-01-21 12:55:41 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T29391, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 27391 - class HTTP::getAsFile
class HTTP::getAsFile
Status: NEW
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.17.x
All All
: Low enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-02-14 07:41 UTC by Amgine
Modified: 2014-01-21 12:55 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Amgine 2011-02-14 07:41:24 UTC
A common http request in extensions is to retrieve a url as a file.
Comment 1 Amgine 2011-02-14 16:34:45 UTC
Here is a function currently used in an extension maintenance script to retrieve a remote file; it uses cURL which is not universally installed, stores files in a temporary directory under the extension using a temporary name, the former of which is fragile and writability must be tested within the script, and returns the temporary filename or false:

function getHttpFile( $url ){
	$val = false;
	$tempName = tempnam( 'temp/', 'MyExtension' );
	if( is_writable( $tempName ) ){
		$tfh = fopen( $tempName, 'w' );
		if( is_resource( $tfh ) ){
			$ch = curl_init( $url );
			curl_setopt( $ch, CURLOPT_FILE, $tfh );
			curl_setopt( $ch, CURLOPT_HEADER, false );
			if( curl_exec( $ch ) ){
				$val = $tempName;
			}
			curl_close( $ch );
			fclose( $tfh );
		}
	}
	return $val;
}

There are a lot of reasons this is a less-than-desirable solution.
Comment 2 Chad H. 2011-02-14 17:17:05 UTC
The extension should use wfTempDir() instead of "temp/" (unless it really wants the file to stick around, then it should use $wgTmpDir). 

As far as writing output...this can already be done by specifying a callback function. I improved this in r82117 to allow specifying it in the $options array (rather than having to call setCallback() yourself)

Generally, I don't think letting callers handle file output is bad, there's nothing inherently wrong with it. However, we could add the ability to the Http class fairly trivially, if we really think it would help in some places (or reduce code duplication, I haven't grep'd around to see)
Comment 3 Mark A. Hershberger 2011-02-14 19:36:16 UTC
Assigning to myself since this is something I asked Amgine to submit.  But feel free to do this yourself, Chad ;)
Comment 4 Andre Klapper 2013-01-09 13:17:33 UTC
Mark: 
This report has been in ASSIGNED status for more than one year and you are set as its assignee. In case that you are not actively working on a fix, please reset the bug status to NEW/UNCONFIRMED.
In case you do not plan to work on a fix in the near future: Please also edit the "Assigned To" field by clicking "Reset Assignee to default", in order to not prevent potential contributors from working on a fix. Thanks for your help!
[assigned>=1y]

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links