diff --git a/extension.json b/extension.json index 7cb41a1..f24028d 100644 --- a/extension.json +++ b/extension.json @@ -20,7 +20,8 @@ "main": { "class": "MediaWiki\\SecureLinkFixer\\Hooks", "services": [ - "HSTSPreloadLookup" + "HSTSPreloadLookup", + "UrlUtils" ] } }, diff --git a/includes/Hooks.php b/includes/Hooks.php index b266183..360465c 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -19,13 +19,16 @@ namespace MediaWiki\SecureLinkFixer; use MediaWiki\Hook\LinkerMakeExternalLinkHook; +use MediaWiki\Utils\UrlUtils; class Hooks implements LinkerMakeExternalLinkHook { private HSTSPreloadLookup $lookup; + private UrlUtils $urlUtils; - public function __construct( HSTSPreloadLookup $lookup ) { + public function __construct( HSTSPreloadLookup $lookup, UrlUtils $urlUtils ) { $this->lookup = $lookup; + $this->urlUtils = $urlUtils; } /** @@ -48,7 +51,7 @@ class Hooks implements LinkerMakeExternalLinkHook { return; } - $parsed = wfParseUrl( $url ); + $parsed = $this->urlUtils->parse( $url ); if ( !$parsed ) { return; } @@ -61,7 +64,7 @@ class Hooks implements LinkerMakeExternalLinkHook { if ( $this->lookup->isPreloaded( $parsed['host'] ) ) { $parsed['scheme'] = 'https'; $parsed['delimiter'] = '://'; - $url = wfAssembleUrl( $parsed ); + $url = UrlUtils::assemble( $parsed ); } } } diff --git a/tests/phpunit/HooksTest.php b/tests/phpunit/HooksTest.php index 0184953..06b8509 100644 --- a/tests/phpunit/HooksTest.php +++ b/tests/phpunit/HooksTest.php @@ -30,7 +30,8 @@ class HooksTest extends MediaWikiIntegrationTestCase { * @dataProvider provideOnLinkerMakeExternalLink */ public function testOnLinkerMakeExternalLink( $input, $expected ) { - $hooks = new Hooks( $this->getServiceContainer()->getService( 'HSTSPreloadLookup' ) ); + $services = $this->getServiceContainer(); + $hooks = new Hooks( $services->getService( 'HSTSPreloadLookup' ), $services->getUrlUtils() ); $dummy = ''; $dummy2 = []; $hooks->onLinkerMakeExternalLink( $input, $dummy, $dummy, $dummy2, $dummy );