Merge "Avoid use of deprecated URL related global functions"

This commit is contained in:
jenkins-bot 2024-09-09 19:52:01 +00:00 committed by Gerrit Code Review
commit c989487db5
3 changed files with 10 additions and 5 deletions

View file

@ -20,7 +20,8 @@
"main": {
"class": "MediaWiki\\SecureLinkFixer\\Hooks",
"services": [
"HSTSPreloadLookup"
"HSTSPreloadLookup",
"UrlUtils"
]
}
},

View file

@ -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 );
}
}
}

View file

@ -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 );