mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SecureLinkFixer
synced 2024-11-11 17:01:43 +00:00
Merge "Avoid use of deprecated URL related global functions"
This commit is contained in:
commit
c989487db5
|
@ -20,7 +20,8 @@
|
|||
"main": {
|
||||
"class": "MediaWiki\\SecureLinkFixer\\Hooks",
|
||||
"services": [
|
||||
"HSTSPreloadLookup"
|
||||
"HSTSPreloadLookup",
|
||||
"UrlUtils"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue