mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning
synced 2024-11-23 13:56:53 +00:00
Replace deprecated Http::get
Bug: T305813 Change-Id: Ief91d92c556244c36dfcec23f770319bd2f2c537
This commit is contained in:
parent
0a06382d72
commit
88aa29cb72
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
namespace CookieWarning;
|
namespace CookieWarning;
|
||||||
|
|
||||||
use Http;
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use MediaWiki\Http\HttpRequestFactory;
|
||||||
use Wikimedia\IPUtils;
|
use Wikimedia\IPUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,14 +13,19 @@ class HttpGeoLocation implements GeoLocation {
|
||||||
private $geoIPServiceURL;
|
private $geoIPServiceURL;
|
||||||
private $locatedIPs = [];
|
private $locatedIPs = [];
|
||||||
|
|
||||||
|
/** @var HttpRequestFactory */
|
||||||
|
private $httpRequestFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $geoIPServiceURL
|
* @param string $geoIPServiceURL
|
||||||
|
* @param HttpRequestFactory $httpRequestFactory
|
||||||
*/
|
*/
|
||||||
public function __construct( $geoIPServiceURL ) {
|
public function __construct( $geoIPServiceURL, HttpRequestFactory $httpRequestFactory ) {
|
||||||
if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) {
|
if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) {
|
||||||
throw new InvalidArgumentException( 'The geoIPServiceUL is invalid' );
|
throw new InvalidArgumentException( 'The geoIPServiceUL is invalid' );
|
||||||
}
|
}
|
||||||
$this->geoIPServiceURL = $geoIPServiceURL;
|
$this->geoIPServiceURL = $geoIPServiceURL;
|
||||||
|
$this->httpRequestFactory = $httpRequestFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,7 +43,7 @@ class HttpGeoLocation implements GeoLocation {
|
||||||
if ( substr( $this->geoIPServiceURL, -1 ) !== '/' ) {
|
if ( substr( $this->geoIPServiceURL, -1 ) !== '/' ) {
|
||||||
$this->geoIPServiceURL .= '/';
|
$this->geoIPServiceURL .= '/';
|
||||||
}
|
}
|
||||||
$json = Http::get( $this->geoIPServiceURL . $ip, [
|
$json = $this->httpRequestFactory->get( $this->geoIPServiceURL . $ip, [
|
||||||
'timeout' => '2',
|
'timeout' => '2',
|
||||||
] );
|
] );
|
||||||
if ( !$json ) {
|
if ( !$json ) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ return [
|
||||||
if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) {
|
if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) {
|
||||||
return new NoopGeoLocation();
|
return new NoopGeoLocation();
|
||||||
}
|
}
|
||||||
return new HttpGeoLocation( $geoIPServiceURL );
|
return new HttpGeoLocation( $geoIPServiceURL, $services->getHttpRequestFactory() );
|
||||||
},
|
},
|
||||||
'CookieWarning.Decisions' => static function ( MediaWikiServices $services ) {
|
'CookieWarning.Decisions' => static function ( MediaWikiServices $services ) {
|
||||||
return new Decisions(
|
return new Decisions(
|
||||||
|
|
Loading…
Reference in a new issue