mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ImageMap
synced 2024-11-23 13:56:46 +00:00
Use Parsoid's extension API's getExternalLinkAttribs
Depends-On: I31a8c6a9bb2741899d5445c3457fd424e283397b Change-Id: Iaf8531a37e8d9d3ce1bece9ab3086e5967dca08f
This commit is contained in:
parent
4b0aa6c502
commit
0c88ab1abd
|
@ -14,7 +14,6 @@ use Wikimedia\Parsoid\Ext\ExtensionTagHandler;
|
|||
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
|
||||
use Wikimedia\Parsoid\Ext\WTUtils;
|
||||
use Wikimedia\Parsoid\Utils\DOMCompat;
|
||||
use Wikimedia\Parsoid\Utils\UrlUtils;
|
||||
|
||||
/**
|
||||
* This is an adaptation of the existing ImageMap extension of the legacy
|
||||
|
@ -256,27 +255,14 @@ class ParsoidImageMap extends ExtensionTagHandler implements ExtensionModule {
|
|||
$attribs = [ 'href' => $href ];
|
||||
if ( $externLink ) {
|
||||
$attribs['class'] = 'plainlinks';
|
||||
|
||||
$siteConfig = $extApi->getSiteConfig();
|
||||
|
||||
// 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';
|
||||
// The AddLinkAttributes pass isn't run on nested pipelines
|
||||
// so $a doesn't have rel/target attributes to copy over
|
||||
$extLinkAttribs = $extApi->getExternalLinkAttribs( $href );
|
||||
if ( isset( $extLinkAttribs['rel'] ) ) {
|
||||
$attribs['rel'] = implode( ' ', $extLinkAttribs['rel'] );
|
||||
}
|
||||
|
||||
// Get the 'target' attribute for external link
|
||||
$externLinkTarget = $siteConfig->getExternalLinkTarget();
|
||||
if ( $externLinkTarget ) {
|
||||
$attribs['target'] = $externLinkTarget;
|
||||
if ( isset( $extLinkAttribs['target'] ) ) {
|
||||
$attribs['target'] = $extLinkAttribs['target'];
|
||||
}
|
||||
}
|
||||
if ( $shape != 'default' ) {
|
||||
|
|
|
@ -339,13 +339,14 @@ Foobar.jpg
|
|||
Imagemap with external link
|
||||
!! config
|
||||
wgParserEnableLegacyMediaDOM=false
|
||||
wgExternalLinkTarget="_blank"
|
||||
!! wikitext
|
||||
<imagemap>
|
||||
File:Foobar.jpg
|
||||
default [http://google.com]
|
||||
</imagemap>
|
||||
!! html/php
|
||||
<figure class="mw-default-size noresize mw-ext-imagemap-desc-bottom-right" typeof="mw:File"><a rel="nofollow" href="http://google.com" class="plainlinks" title="http://google.com"><img src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" class="mw-file-element" resource="/wiki/File:Foobar.jpg" /></a><figcaption></figcaption></figure>
|
||||
<figure class="mw-default-size noresize mw-ext-imagemap-desc-bottom-right" typeof="mw:File"><a target="_blank" rel="nofollow noreferrer noopener" href="http://google.com" class="plainlinks" title="http://google.com"><img src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" class="mw-file-element" resource="/wiki/File:Foobar.jpg" /></a><figcaption></figcaption></figure>
|
||||
!! html/parsoid
|
||||
<figure class="mw-default-size noresize mw-ext-imagemap-desc-bottom-right" typeof="mw:File mw:Extension/imagemap" data-mw='{"name":"imagemap","attrs":{},"body":{"extsrc":"\nFile:Foobar.jpg\ndefault [http://google.com]\n"}}'><a href="http://google.com" class="plainlinks" rel="nofollow"><img resource="./File:Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" class="mw-file-element"/></a><figcaption></figcaption></figure>
|
||||
<figure class="mw-default-size noresize mw-ext-imagemap-desc-bottom-right" typeof="mw:File mw:Extension/imagemap" data-mw='{"name":"imagemap","attrs":{},"body":{"extsrc":"\nFile:Foobar.jpg\ndefault [http://google.com]\n"}}'><a href="http://google.com" class="plainlinks" rel="nofollow noreferrer noopener" target="_blank"><img resource="./File:Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" class="mw-file-element"/></a><figcaption></figcaption></figure>
|
||||
!! end
|
||||
|
|
Loading…
Reference in a new issue