From 88aa29cb722dd42db7d19934fc56508a1d9c5cbe Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Sun, 11 Dec 2022 14:18:17 +0100 Subject: [PATCH] Replace deprecated Http::get Bug: T305813 Change-Id: Ief91d92c556244c36dfcec23f770319bd2f2c537 --- includes/HttpGeoLocation.php | 11 ++++++++--- includes/ServiceWiring.php | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/HttpGeoLocation.php b/includes/HttpGeoLocation.php index a328619..dfca26f 100644 --- a/includes/HttpGeoLocation.php +++ b/includes/HttpGeoLocation.php @@ -2,8 +2,8 @@ namespace CookieWarning; -use Http; use InvalidArgumentException; +use MediaWiki\Http\HttpRequestFactory; use Wikimedia\IPUtils; /** @@ -13,14 +13,19 @@ class HttpGeoLocation implements GeoLocation { private $geoIPServiceURL; private $locatedIPs = []; + /** @var HttpRequestFactory */ + private $httpRequestFactory; + /** * @param string $geoIPServiceURL + * @param HttpRequestFactory $httpRequestFactory */ - public function __construct( $geoIPServiceURL ) { + public function __construct( $geoIPServiceURL, HttpRequestFactory $httpRequestFactory ) { if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) { throw new InvalidArgumentException( 'The geoIPServiceUL is invalid' ); } $this->geoIPServiceURL = $geoIPServiceURL; + $this->httpRequestFactory = $httpRequestFactory; } /** @@ -38,7 +43,7 @@ class HttpGeoLocation implements GeoLocation { if ( substr( $this->geoIPServiceURL, -1 ) !== '/' ) { $this->geoIPServiceURL .= '/'; } - $json = Http::get( $this->geoIPServiceURL . $ip, [ + $json = $this->httpRequestFactory->get( $this->geoIPServiceURL . $ip, [ 'timeout' => '2', ] ); if ( !$json ) { diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 76fa9ff..8b55197 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -18,7 +18,7 @@ return [ if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) { return new NoopGeoLocation(); } - return new HttpGeoLocation( $geoIPServiceURL ); + return new HttpGeoLocation( $geoIPServiceURL, $services->getHttpRequestFactory() ); }, 'CookieWarning.Decisions' => static function ( MediaWikiServices $services ) { return new Decisions(