[MediaWiki-commits] [Gerrit] Fix up a[rel=mw:ExtLink] to have class=external and rel=n... - change (mediawiki...Flow)
jenkins-bot has submitted this change and it was merged. Change subject: Fix up a[rel=mw:ExtLink] to have class=external and rel=nofollow .. Fix up a[rel=mw:ExtLink] to have class=external and rel=nofollow Respecting MW's domain exceptions for nofollow. Bug: T68289 Bug: T96855 Change-Id: I7cfdedb0507f9bb93d941b42c011fe9562d7e274 --- M autoload.php M container.php A includes/Parsoid/Fixer/ExtLinkFixer.php 3 files changed, 46 insertions(+), 1 deletion(-) Approvals: Matthias Mullie: Looks good to me, approved jenkins-bot: Verified diff --git a/autoload.php b/autoload.php index ff9e156..5049f53 100644 --- a/autoload.php +++ b/autoload.php @@ -248,6 +248,7 @@ 'Flow\\Parsoid\\Fixer' = __DIR__ . '/includes/Parsoid/Fixer.php', 'Flow\\Parsoid\\Fixer\\BadImageRemover' = __DIR__ . '/includes/Parsoid/Fixer/BadImageRemover.php', 'Flow\\Parsoid\\Fixer\\BaseHrefFixer' = __DIR__ . '/includes/Parsoid/Fixer/BaseHrefFixer.php', + 'Flow\\Parsoid\\Fixer\\ExtLinkFixer' = __DIR__ . '/includes/Parsoid/Fixer/ExtLinkFixer.php', 'Flow\\Parsoid\\Fixer\\WikiLinkFixer' = __DIR__ . '/includes/Parsoid/Fixer/WikiLinkFixer.php', 'Flow\\Parsoid\\ReferenceExtractor' = __DIR__ . '/includes/Parsoid/ReferenceExtractor.php', 'Flow\\Parsoid\\ReferenceFactory' = __DIR__ . '/includes/Parsoid/ReferenceFactory.php', diff --git a/container.php b/container.php index cb286b4..0f354b3 100644 --- a/container.php +++ b/container.php @@ -73,11 +73,16 @@ return new Flow\Parsoid\Fixer\BaseHrefFixer( $wgArticlePath ); }; +$c['ext_link_fixer'] = function ( $c ) { + return new Flow\Parsoid\Fixer\ExtLinkFixer(); +}; + $c['content_fixer'] = function( $c ) { return new Flow\Parsoid\ContentFixer( $c['wiki_link_fixer'], $c['bad_image_remover'], - $c['base_href_fixer'] + $c['base_href_fixer'], + $c['ext_link_fixer'] ); }; diff --git a/includes/Parsoid/Fixer/ExtLinkFixer.php b/includes/Parsoid/Fixer/ExtLinkFixer.php new file mode 100644 index 000..9562e58 --- /dev/null +++ b/includes/Parsoid/Fixer/ExtLinkFixer.php @@ -0,0 +1,39 @@ +?php + +namespace Flow\Parsoid\Fixer; + +use Flow\Parsoid\Fixer; + +/** + * Parsoid markup doesn't contain class=external for external links. This is needed for + * correct styling, so we add it here. + */ +class ExtLinkFixer implements Fixer { + /** +* Returns XPath matching elements that need to be transformed +* +* @return string XPath of elements this acts on +*/ + public function getXPath() { + return '//a[@rel=mw:ExtLink]'; + } + + /** +* Adds class=external rel=nofollow to external links. +* +* @param \DOMNode $node Link +* @param \Title $title +*/ + public function apply( \DOMNode $node, \Title $title ) { + if ( !$node instanceof \DOMElement ) { + return; + } + + $node-setAttribute( 'class', 'external' ); + + global $wgNoFollowLinks, $wgNoFollowDomainExceptions; + if ( $wgNoFollowLinks !wfMatchesDomainList( $node-getAttribute( 'href' ), $wgNoFollowDomainExceptions ) ) { + $node-setAttribute( 'rel', 'nofollow' ); + } + } +} -- To view, visit https://gerrit.wikimedia.org/r/206344 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I7cfdedb0507f9bb93d941b42c011fe9562d7e274 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Catrope roan.katt...@gmail.com Gerrit-Reviewer: Matthias Mullie mmul...@wikimedia.org Gerrit-Reviewer: jenkins-bot ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] Fix up a[rel=mw:ExtLink] to have class=external and rel=n... - change (mediawiki...Flow)
Catrope has uploaded a new change for review. https://gerrit.wikimedia.org/r/206344 Change subject: Fix up a[rel=mw:ExtLink] to have class=external and rel=nofollow .. Fix up a[rel=mw:ExtLink] to have class=external and rel=nofollow Respecting MW's domain exceptions for nofollow. Bug: T68289 Bug: T96855 Change-Id: I7cfdedb0507f9bb93d941b42c011fe9562d7e274 --- M autoload.php M container.php A includes/Parsoid/Fixer/ExtLinkFixer.php 3 files changed, 46 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/44/206344/1 diff --git a/autoload.php b/autoload.php index ff9e156..5049f53 100644 --- a/autoload.php +++ b/autoload.php @@ -248,6 +248,7 @@ 'Flow\\Parsoid\\Fixer' = __DIR__ . '/includes/Parsoid/Fixer.php', 'Flow\\Parsoid\\Fixer\\BadImageRemover' = __DIR__ . '/includes/Parsoid/Fixer/BadImageRemover.php', 'Flow\\Parsoid\\Fixer\\BaseHrefFixer' = __DIR__ . '/includes/Parsoid/Fixer/BaseHrefFixer.php', + 'Flow\\Parsoid\\Fixer\\ExtLinkFixer' = __DIR__ . '/includes/Parsoid/Fixer/ExtLinkFixer.php', 'Flow\\Parsoid\\Fixer\\WikiLinkFixer' = __DIR__ . '/includes/Parsoid/Fixer/WikiLinkFixer.php', 'Flow\\Parsoid\\ReferenceExtractor' = __DIR__ . '/includes/Parsoid/ReferenceExtractor.php', 'Flow\\Parsoid\\ReferenceFactory' = __DIR__ . '/includes/Parsoid/ReferenceFactory.php', diff --git a/container.php b/container.php index cb286b4..0f354b3 100644 --- a/container.php +++ b/container.php @@ -73,11 +73,16 @@ return new Flow\Parsoid\Fixer\BaseHrefFixer( $wgArticlePath ); }; +$c['ext_link_fixer'] = function ( $c ) { + return new Flow\Parsoid\Fixer\ExtLinkFixer(); +}; + $c['content_fixer'] = function( $c ) { return new Flow\Parsoid\ContentFixer( $c['wiki_link_fixer'], $c['bad_image_remover'], - $c['base_href_fixer'] + $c['base_href_fixer'], + $c['ext_link_fixer'] ); }; diff --git a/includes/Parsoid/Fixer/ExtLinkFixer.php b/includes/Parsoid/Fixer/ExtLinkFixer.php new file mode 100644 index 000..968f836 --- /dev/null +++ b/includes/Parsoid/Fixer/ExtLinkFixer.php @@ -0,0 +1,39 @@ +?php + +namespace Flow\Parsoid\Fixer; + +use Flow\Parsoid\Fixer; + +/** + * Parsoid markup doesn't contain class=external for external links. This is needed for + * correct styling, so we add it here. + */ +class ExtLinkFixer implements Fixer { + /** +* Returns XPath matching elements that need to be transformed +* +* @return string XPath of elements this acts on +*/ + public function getXPath() { + return '//a[@rel=mw:ExtLink]'; + } + + /** +* Prefixes the href with base href. +* +* @param DOMNode $node Link +* @param Title $title +*/ + public function apply( \DOMNode $node, \Title $title ) { + if ( !$node instanceof \DOMElement ) { + return; + } + + $node-setAttribute( 'class', 'external' ); + + global $wgNoFollowLinks, $wgNoFollowDomainExceptions; + if ( $wgNoFollowLinks !wfMatchesDomainList( $node-getAttribute( 'href' ), $wgNoFollowDomainExceptions ) ) { + $node-setAttribute( 'rel', 'nofollow' ); + } + } +} -- To view, visit https://gerrit.wikimedia.org/r/206344 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7cfdedb0507f9bb93d941b42c011fe9562d7e274 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Catrope roan.katt...@gmail.com ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits