Revision: 43690
Author: demon
Date: 2008-11-18 22:48:03 +0000 (Tue, 18 Nov 2008)
Log Message:
-----------
* Move user-agent construction to its own method, so we're not writing the same
string in two places (and provides a reliable way for getting MW's standard
user-agent)
* Mark visibility, they're all public anyway
Modified Paths:
--------------
trunk/phase3/includes/HttpFunctions.php
Modified: trunk/phase3/includes/HttpFunctions.php
===================================================================
--- trunk/phase3/includes/HttpFunctions.php 2008-11-18 22:22:31 UTC (rev
43689)
+++ trunk/phase3/includes/HttpFunctions.php 2008-11-18 22:48:03 UTC (rev
43690)
@@ -16,7 +16,7 @@
* Simple wrapper for Http::request( 'GET' )
* @see Http::request()
*/
- static function get( $url, $timeout = 'default', $opts = array() ) {
+ public static function get( $url, $timeout = 'default', $opts = array()
) {
return Http::request( "GET", $url, $timeout, $opts );
}
@@ -24,7 +24,7 @@
* Simple wrapper for Http::request( 'POST' )
* @see Http::request()
*/
- static function post( $url, $timeout = 'default', $opts = array() ) {
+ public static function post( $url, $timeout = 'default', $opts =
array() ) {
return Http::request( "POST", $url, $timeout, $opts );
}
@@ -36,8 +36,8 @@
* @param $curlOptions array Optional array of extra params to pass
* to curl_setopt()
*/
- static function request( $method, $url, $timeout = 'default',
$curlOptions = array() ) {
- global $wgHTTPTimeout, $wgHTTPProxy, $wgVersion, $wgTitle;
+ public static function request( $method, $url, $timeout = 'default',
$curlOptions = array() ) {
+ global $wgHTTPTimeout, $wgHTTPProxy, $wgTitle;
// Go ahead and set the timeout if not otherwise specified
if ( $timeout == 'default' ) {
@@ -55,7 +55,7 @@
}
curl_setopt( $c, CURLOPT_TIMEOUT, $timeout );
- curl_setopt( $c, CURLOPT_USERAGENT,
"MediaWiki/$wgVersion" );
+ curl_setopt( $c, CURLOPT_USERAGENT, self :: userAgent()
);
if ( $method == 'POST' )
curl_setopt( $c, CURLOPT_POST, true );
else
@@ -99,7 +99,7 @@
# Otherwise use file_get_contents...
# This doesn't have local fetch capabilities...
- $headers = array( "User-Agent: MediaWiki/$wgVersion" );
+ $headers = array( "User-Agent: " . self :: userAgent()
);
if( strcasecmp( $method, 'post' ) == 0 ) {
// Required for HTTP 1.0 POSTs
$headers[] = "Content-Length: 0";
@@ -121,7 +121,7 @@
* @param $url string Full url to check
* @return bool
*/
- static function isLocalURL( $url ) {
+ public static function isLocalURL( $url ) {
global $wgCommandLineMode, $wgConf;
if ( $wgCommandLineMode ) {
return false;
@@ -149,4 +149,12 @@
}
return false;
}
+
+ /**
+ * Return a standard user-agent we can use for external requests.
+ */
+ public static function userAgent() {
+ global $wgVersion;
+ return "MediaWiki/$wgVersion";
+ }
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs