Skin: Fix UrlUtils calls

This was broken in change I9a55545e4c (commit b90e0e4261):
wfUrlProtocols() without argument is equivalent to validProtocols(), not
validAbsoluteProtocols() (wfUrlProtocols()’s $includeProtocolRelative
defaults to true).

Bug: T364539
Change-Id: I050ed65624928ee8277468f70b8b80a3080f190a
This commit is contained in:
Lucas Werkmeister 2024-05-09 14:16:42 +02:00
parent da33068477
commit e376d6ed54
2 changed files with 30 additions and 2 deletions

View file

@ -1140,7 +1140,7 @@ abstract class Skin extends ContextSource {
* @return string URL
*/
public static function makeInternalOrExternalUrl( $name ) {
$protocols = MediaWikiServices::getInstance()->getUrlUtils()->validAbsoluteProtocols();
$protocols = MediaWikiServices::getInstance()->getUrlUtils()->validProtocols();
if ( preg_match( '/^(?i:' . $protocols . ')/', $name ) ) {
return $name;
@ -1617,7 +1617,7 @@ abstract class Skin extends ContextSource {
$text = $line[1];
}
if ( preg_match( '/^(?i:' . $urlUtils->validAbsoluteProtocols() . ')/', $link ) ) {
if ( preg_match( '/^(?i:' . $urlUtils->validProtocols() . ')/', $link ) ) {
$href = $link;
// Parser::getExternalLinkAttribs won't work here because of the Namespace things

View file

@ -150,6 +150,34 @@ class SideBarTest extends MediaWikiLangTestCase {
);
}
public function testProtocolRelativeExternalUrl() {
$this->overrideConfigValues( [
MainConfigNames::NoFollowLinks => true,
MainConfigNames::NoFollowDomainExceptions => [],
MainConfigNames::NoFollowNsExceptions => [],
] );
$bar = [];
$text = '* Title
** //www.mediawiki.org/| Home
';
$this->skin->addToSidebarPlain( $bar, $text );
$this->assertEquals(
[ 'Title' => [
# ** //www.mediawiki.org/| Home
[
'text' => 'Home',
'href' => '//www.mediawiki.org/', // not /wiki///www.mediawiki.org/ (T364539)
'id' => 'n-Home',
'active' => null,
'icon' => null,
'rel' => 'nofollow',
],
] ],
$bar
);
}
private function getAttribs() {
# Sidebar text we will use everytime
$text = '* Title