Set target to $wgExternalLinkTarget

Set hyperlink 'target' attribute to $wgExternalLinkTarget.

In addition, set the 'rel' attribute according to the
$wgNoFollowLinks, $wgNoFollowDomainExceptions
and $wgNoFollowNsExceptions settings (bug T186241).

Bug: T356730
Change-Id: If4880e4e0b3cd2056521d44baf261ed848511bcd
This commit is contained in:
Alexander Mashin 2024-02-06 12:42:26 +07:00
parent 0cf105323f
commit 754b722c56
2 changed files with 28 additions and 8 deletions

View file

@ -60,7 +60,7 @@ class ImageMap implements ParserFirstCallInitHook {
* @return string HTML (Image map, or error message) * @return string HTML (Image map, or error message)
*/ */
public function render( $input, $params, Parser $parser ) { public function render( $input, $params, Parser $parser ) {
global $wgUrlProtocols, $wgNoFollowLinks; global $wgUrlProtocols;
$config = MediaWikiServices::getInstance()->getMainConfig(); $config = MediaWikiServices::getInstance()->getMainConfig();
$enableLegacyMediaDOM = $config->get( 'ParserEnableLegacyMediaDOM' ); $enableLegacyMediaDOM = $config->get( 'ParserEnableLegacyMediaDOM' );
@ -246,11 +246,11 @@ class ImageMap implements ParserFirstCallInitHook {
// Construct the area tag // Construct the area tag
$attribs = []; $attribs = [];
if ( $externLink ) { if ( $externLink ) {
// Get the 'target' and 'rel' attributes for external link.
$attribs = $parser->getExternalLinkAttribs( $title );
$attribs['href'] = $title; $attribs['href'] = $title;
$attribs['class'] = 'plainlinks'; $attribs['class'] = 'plainlinks';
if ( $wgNoFollowLinks ) {
$attribs['rel'] = 'nofollow';
}
} elseif ( $title->getFragment() !== '' && $title->getPrefixedDBkey() === '' ) { } elseif ( $title->getFragment() !== '' && $title->getPrefixedDBkey() === '' ) {
// XXX: kluge to handle [[#Fragment]] links, should really fix getLocalURL() // XXX: kluge to handle [[#Fragment]] links, should really fix getLocalURL()
// in Title.php to return an empty string in this case // in Title.php to return an empty string in this case

View file

@ -14,6 +14,7 @@ use Wikimedia\Parsoid\Ext\ExtensionTagHandler;
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
use Wikimedia\Parsoid\Ext\WTUtils; use Wikimedia\Parsoid\Ext\WTUtils;
use Wikimedia\Parsoid\Utils\DOMCompat; use Wikimedia\Parsoid\Utils\DOMCompat;
use Wikimedia\Parsoid\Utils\UrlUtils;
/** /**
* This is an adaptation of the existing ImageMap extension of the legacy * This is an adaptation of the existing ImageMap extension of the legacy
@ -251,13 +252,32 @@ class ParsoidImageMap extends ExtensionTagHandler implements ExtensionModule {
} }
// Construct the area tag // Construct the area tag
$attribs = [ 'href' => $href ]; $attribs = [ 'href' => $href ];
if ( $externLink ) { if ( $externLink ) {
$attribs['class'] = 'plainlinks'; $attribs['class'] = 'plainlinks';
// FIXME: T186241
// if ( $wgNoFollowLinks ) { $siteConfig = $extApi->getSiteConfig();
// $attribs['rel'] = 'nofollow';
// } // Get the 'rel' attribute for external link.
$noFollowConfig = $siteConfig->getNoFollowConfig();
if (
$noFollowConfig['nofollow'] &&
!in_array(
$extApi->getPageConfig()->getLinkTarget()->getNamespace(),
$noFollowConfig['nsexceptions'],
true
) &&
!UrlUtils::matchesDomainList( $href, $noFollowConfig['domainexceptions'] )
) {
$attribs['rel'] = 'nofollow';
}
// Get the 'target' attribute for external link
$externLinkTarget = $siteConfig->getExternalLinkTarget();
if ( $externLinkTarget ) {
$attribs['target'] = $externLinkTarget;
}
} }
if ( $shape != 'default' ) { if ( $shape != 'default' ) {
$attribs['shape'] = $shape; $attribs['shape'] = $shape;