2005-06-26 06:34:13 +00:00
|
|
|
<?php
|
2009-11-26 12:00:36 +00:00
|
|
|
/**
|
|
|
|
|
* Various HTTP related functions
|
2009-11-28 03:49:29 +00:00
|
|
|
* @defgroup HTTP HTTP
|
2009-11-26 12:00:36 +00:00
|
|
|
* @ingroup HTTP
|
|
|
|
|
*/
|
2006-07-02 15:57:59 +00:00
|
|
|
class Http {
|
2009-07-25 20:05:41 +00:00
|
|
|
|
2008-09-29 06:12:47 +00:00
|
|
|
/**
|
|
|
|
|
* Simple wrapper for Http::request( 'GET' )
|
2009-11-26 12:00:36 +00:00
|
|
|
* @see Http::request()
|
2008-09-29 06:12:47 +00:00
|
|
|
*/
|
2009-11-26 12:00:36 +00:00
|
|
|
public static function get( $url, $timeout = 'default', $opts = array() ) {
|
|
|
|
|
return Http::request( "GET", $url, $timeout, $opts );
|
2007-05-10 19:13:02 +00:00
|
|
|
}
|
2009-07-15 00:55:58 +00:00
|
|
|
|
2008-09-29 06:12:47 +00:00
|
|
|
/**
|
|
|
|
|
* Simple wrapper for Http::request( 'POST' )
|
2009-11-26 12:00:36 +00:00
|
|
|
* @see Http::request()
|
2008-09-29 06:12:47 +00:00
|
|
|
*/
|
2009-11-26 12:00:36 +00:00
|
|
|
public static function post( $url, $timeout = 'default', $opts = array() ) {
|
|
|
|
|
return Http::request( "POST", $url, $timeout, $opts );
|
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt.
Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview
= Upload Improvements =
==Upload API ==
* Based on the early work of Bryan Tong and others it adds the upload option to the api.
* We rewrite Special:Upload page to include use the new refactoring
* Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions
== Copy by URL==
$wgAllowCopyUploads = false;
* http class rewrite includes a new http background download see: includes/HttpFunctions.php
* spins off a php process that calls: maintenance/http_session_download.php
* pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time)
== Firefogg ==
* Firefogg enables resumable upload by chunks
* progress indicators and conditional invokation (js2 system)
* and of-course client side transcoding.
= Script Server =
$wgEnableScriptLoader = false;
* off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc.
for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader
* Includes some early skin js include fixes (skin/script system still lots of love)
* Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html )
* The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php
* One can use this auto class loading dependency system with extensions and add-ons but I need to better document that.
= js2 system / mwEmbed=
$wgEnableJS2system = false
* includes initial rewrite towards more jquery based javascript code
* especially for the Special:Upload page.
* Also the edit page include support for the "add-media-wizard"
* includes dependency loader for javascript that optionally takes advantage of the script-loader
* remote embedding of javascript interfaces (like embedding video, or commons media searching)
* $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output.
= mwEmbed =
* Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player.
** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins.
* add-media-wizard adds easy inserts of media to pages (with import)
== jQuery==
* we include a base install of jQuery, jQuery ui and some plugins.
* all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded.
== other stuff ==
there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
|
|
|
}
|
2009-07-15 00:55:58 +00:00
|
|
|
|
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt.
Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview
= Upload Improvements =
==Upload API ==
* Based on the early work of Bryan Tong and others it adds the upload option to the api.
* We rewrite Special:Upload page to include use the new refactoring
* Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions
== Copy by URL==
$wgAllowCopyUploads = false;
* http class rewrite includes a new http background download see: includes/HttpFunctions.php
* spins off a php process that calls: maintenance/http_session_download.php
* pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time)
== Firefogg ==
* Firefogg enables resumable upload by chunks
* progress indicators and conditional invokation (js2 system)
* and of-course client side transcoding.
= Script Server =
$wgEnableScriptLoader = false;
* off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc.
for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader
* Includes some early skin js include fixes (skin/script system still lots of love)
* Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html )
* The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php
* One can use this auto class loading dependency system with extensions and add-ons but I need to better document that.
= js2 system / mwEmbed=
$wgEnableJS2system = false
* includes initial rewrite towards more jquery based javascript code
* especially for the Special:Upload page.
* Also the edit page include support for the "add-media-wizard"
* includes dependency loader for javascript that optionally takes advantage of the script-loader
* remote embedding of javascript interfaces (like embedding video, or commons media searching)
* $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output.
= mwEmbed =
* Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player.
** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins.
* add-media-wizard adds easy inserts of media to pages (with import)
== jQuery==
* we include a base install of jQuery, jQuery ui and some plugins.
* all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded.
== other stuff ==
there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
|
|
|
/**
|
2009-11-26 12:00:36 +00:00
|
|
|
* Get the contents of a file by HTTP
|
|
|
|
|
* @param $method string HTTP method. Usually GET/POST
|
|
|
|
|
* @param $url string Full URL to act on
|
|
|
|
|
* @param $timeout int Seconds to timeout. 'default' falls to $wgHTTPTimeout
|
|
|
|
|
* @param $curlOptions array Optional array of extra params to pass
|
|
|
|
|
* to curl_setopt()
|
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt.
Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview
= Upload Improvements =
==Upload API ==
* Based on the early work of Bryan Tong and others it adds the upload option to the api.
* We rewrite Special:Upload page to include use the new refactoring
* Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions
== Copy by URL==
$wgAllowCopyUploads = false;
* http class rewrite includes a new http background download see: includes/HttpFunctions.php
* spins off a php process that calls: maintenance/http_session_download.php
* pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time)
== Firefogg ==
* Firefogg enables resumable upload by chunks
* progress indicators and conditional invokation (js2 system)
* and of-course client side transcoding.
= Script Server =
$wgEnableScriptLoader = false;
* off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc.
for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader
* Includes some early skin js include fixes (skin/script system still lots of love)
* Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html )
* The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php
* One can use this auto class loading dependency system with extensions and add-ons but I need to better document that.
= js2 system / mwEmbed=
$wgEnableJS2system = false
* includes initial rewrite towards more jquery based javascript code
* especially for the Special:Upload page.
* Also the edit page include support for the "add-media-wizard"
* includes dependency loader for javascript that optionally takes advantage of the script-loader
* remote embedding of javascript interfaces (like embedding video, or commons media searching)
* $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output.
= mwEmbed =
* Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player.
** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins.
* add-media-wizard adds easy inserts of media to pages (with import)
== jQuery==
* we include a base install of jQuery, jQuery ui and some plugins.
* all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded.
== other stuff ==
there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
|
|
|
*/
|
2009-11-26 12:00:36 +00:00
|
|
|
public static function request( $method, $url, $timeout = 'default', $curlOptions = array() ) {
|
|
|
|
|
global $wgHTTPTimeout, $wgHTTPProxy, $wgTitle;
|
2009-08-13 20:39:20 +00:00
|
|
|
|
2009-11-26 12:00:36 +00:00
|
|
|
// Go ahead and set the timeout if not otherwise specified
|
|
|
|
|
if ( $timeout == 'default' ) {
|
|
|
|
|
$timeout = $wgHTTPTimeout;
|
2008-09-22 15:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-26 12:00:36 +00:00
|
|
|
wfDebug( __METHOD__ . ": $method $url\n" );
|
|
|
|
|
# Use curl if available
|
|
|
|
|
if ( function_exists( 'curl_init' ) ) {
|
|
|
|
|
$c = curl_init( $url );
|
|
|
|
|
if ( self::isLocalURL( $url ) ) {
|
|
|
|
|
curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' );
|
|
|
|
|
} else if ($wgHTTPProxy) {
|
|
|
|
|
curl_setopt($c, CURLOPT_PROXY, $wgHTTPProxy);
|
|
|
|
|
}
|
2005-07-03 07:15:53 +00:00
|
|
|
|
2009-11-26 12:00:36 +00:00
|
|
|
curl_setopt( $c, CURLOPT_TIMEOUT, $timeout );
|
|
|
|
|
curl_setopt( $c, CURLOPT_USERAGENT, self :: userAgent() );
|
|
|
|
|
if ( $method == 'POST' ) {
|
|
|
|
|
curl_setopt( $c, CURLOPT_POST, true );
|
|
|
|
|
curl_setopt( $c, CURLOPT_POSTFIELDS, '' );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
curl_setopt( $c, CURLOPT_CUSTOMREQUEST, $method );
|
|
|
|
|
|
|
|
|
|
# Set the referer to $wgTitle, even in command-line mode
|
|
|
|
|
# This is useful for interwiki transclusion, where the foreign
|
|
|
|
|
# server wants to know what the referring page is.
|
|
|
|
|
# $_SERVER['REQUEST_URI'] gives a less reliable indication of the
|
|
|
|
|
# referring page.
|
|
|
|
|
if ( is_object( $wgTitle ) ) {
|
|
|
|
|
curl_setopt( $c, CURLOPT_REFERER, $wgTitle->getFullURL() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( is_array( $curlOptions ) ) {
|
|
|
|
|
foreach( $curlOptions as $option => $value ) {
|
|
|
|
|
curl_setopt( $c, $option, $value );
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-02-01 04:41:53 +00:00
|
|
|
|
2009-11-26 12:00:36 +00:00
|
|
|
ob_start();
|
|
|
|
|
curl_exec( $c );
|
|
|
|
|
$text = ob_get_contents();
|
|
|
|
|
ob_end_clean();
|
2009-07-27 19:00:27 +00:00
|
|
|
|
2009-11-26 12:00:36 +00:00
|
|
|
# Don't return the text of error messages, return false on error
|
|
|
|
|
$retcode = curl_getinfo( $c, CURLINFO_HTTP_CODE );
|
|
|
|
|
if ( $retcode != 200 ) {
|
|
|
|
|
wfDebug( __METHOD__ . ": HTTP return code $retcode\n" );
|
|
|
|
|
$text = false;
|
2009-07-27 00:42:26 +00:00
|
|
|
}
|
2009-11-26 12:00:36 +00:00
|
|
|
# Don't return truncated output
|
|
|
|
|
$errno = curl_errno( $c );
|
|
|
|
|
if ( $errno != CURLE_OK ) {
|
|
|
|
|
$errstr = curl_error( $c );
|
|
|
|
|
wfDebug( __METHOD__ . ": CURL error code $errno: $errstr\n" );
|
|
|
|
|
$text = false;
|
|
|
|
|
}
|
|
|
|
|
curl_close( $c );
|
|
|
|
|
} else {
|
|
|
|
|
# Otherwise use file_get_contents...
|
|
|
|
|
# This doesn't have local fetch capabilities...
|
2009-07-27 19:00:27 +00:00
|
|
|
|
2009-11-26 12:00:36 +00:00
|
|
|
$headers = array( "User-Agent: " . self :: userAgent() );
|
|
|
|
|
if( strcasecmp( $method, 'post' ) == 0 ) {
|
|
|
|
|
// Required for HTTP 1.0 POSTs
|
|
|
|
|
$headers[] = "Content-Length: 0";
|
|
|
|
|
}
|
|
|
|
|
$opts = array(
|
|
|
|
|
'http' => array(
|
|
|
|
|
'method' => $method,
|
|
|
|
|
'header' => implode( "\r\n", $headers ),
|
|
|
|
|
'timeout' => $timeout ) );
|
|
|
|
|
$ctx = stream_context_create($opts);
|
2007-05-10 19:13:02 +00:00
|
|
|
|
2009-11-26 12:00:36 +00:00
|
|
|
$text = file_get_contents( $url, false, $ctx );
|
2005-11-01 22:26:11 +00:00
|
|
|
}
|
2009-11-26 12:00:36 +00:00
|
|
|
return $text;
|
2005-06-26 06:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
2006-07-02 15:57:59 +00:00
|
|
|
/**
|
|
|
|
|
* Check if the URL can be served by localhost
|
2008-09-29 06:12:47 +00:00
|
|
|
* @param $url string Full url to check
|
|
|
|
|
* @return bool
|
2006-07-02 15:57:59 +00:00
|
|
|
*/
|
2008-11-18 22:48:03 +00:00
|
|
|
public static function isLocalURL( $url ) {
|
2006-07-02 15:57:59 +00:00
|
|
|
global $wgCommandLineMode, $wgConf;
|
|
|
|
|
if ( $wgCommandLineMode ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2005-11-01 22:26:11 +00:00
|
|
|
|
2006-07-02 15:57:59 +00:00
|
|
|
// Extract host part
|
|
|
|
|
$matches = array();
|
|
|
|
|
if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) {
|
|
|
|
|
$host = $matches[1];
|
|
|
|
|
// Split up dotwise
|
|
|
|
|
$domainParts = explode( '.', $host );
|
|
|
|
|
// Check if this domain or any superdomain is listed in $wgConf as a local virtual host
|
|
|
|
|
$domainParts = array_reverse( $domainParts );
|
|
|
|
|
for ( $i = 0; $i < count( $domainParts ); $i++ ) {
|
|
|
|
|
$domainPart = $domainParts[$i];
|
|
|
|
|
if ( $i == 0 ) {
|
|
|
|
|
$domain = $domainPart;
|
|
|
|
|
} else {
|
|
|
|
|
$domain = $domainPart . '.' . $domain;
|
|
|
|
|
}
|
|
|
|
|
if ( $wgConf->isLocalVHost( $domain ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2005-06-26 06:34:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-07-02 15:57:59 +00:00
|
|
|
return false;
|
2005-06-26 06:34:13 +00:00
|
|
|
}
|
2009-11-26 12:00:36 +00:00
|
|
|
|
2008-11-18 22:48:03 +00:00
|
|
|
/**
|
|
|
|
|
* Return a standard user-agent we can use for external requests.
|
|
|
|
|
*/
|
|
|
|
|
public static function userAgent() {
|
|
|
|
|
global $wgVersion;
|
|
|
|
|
return "MediaWiki/$wgVersion";
|
|
|
|
|
}
|
2009-07-25 00:19:36 +00:00
|
|
|
}
|