Lucas_Werkmeister_WMDE added a comment.
Super hacky sketch of an improvement: name=MediaWiki core diff --git a/includes/Linker.php b/includes/Linker.php index 8ebbd1c19e..33c5e9432a 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -120,7 +120,15 @@ public static function link( return $linkRenderer->makePreloadedLink( $target, $text, '', $customAttribs, $query ); } - return $linkRenderer->makeLink( $target, $text, $customAttribs, $query ); + if ( in_array( 'comment', $options, true ) ) { + $linkRenderer->renderingComment = true; + } + + try { + return $linkRenderer->makeLink( $target, $text, $customAttribs, $query ); + } finally { + $linkRenderer->renderingComment = false; + } } /** @@ -1639,6 +1647,7 @@ public static function makeCommentLink( /* escape = */ false // Already escaped ); } else { + $options[] = 'comment'; $link = self::link( $linkTarget, $text, [], [], $options ); } diff --git a/includes/linker/LinkRenderer.php b/includes/linker/LinkRenderer.php index 18df8cfbdd..65a1c02baf 100644 --- a/includes/linker/LinkRenderer.php +++ b/includes/linker/LinkRenderer.php @@ -82,6 +82,8 @@ class LinkRenderer { */ private $specialPageFactory; + public $renderingComment = false; + /** * @internal For use by LinkRendererFactory * @param TitleFormatter $titleFormatter name=Wikibase diff --git a/repo/includes/Hooks/HtmlPageLinkRendererEndHookHandler.php b/repo/includes/Hooks/HtmlPageLinkRendererEndHookHandler.php index 9718c45db1..0967aa7004 100644 --- a/repo/includes/Hooks/HtmlPageLinkRendererEndHookHandler.php +++ b/repo/includes/Hooks/HtmlPageLinkRendererEndHookHandler.php @@ -169,6 +169,10 @@ public function onHtmlPageLinkRendererEnd( return true; } + if ( !$linkRenderer->renderingComment ) { + return true; + } + return $this->doHtmlPageLinkRendererEnd( $linkRenderer, Title::newFromLinkTarget( $target ), This seems to work locally. A non-hacky version will look somewhat different, of course, but I think it might not be totally separate either. Looking at the many methods in `Linker`/`LinkRenderer`, and how edit summary links and regular links share so much code, I feel like a separate hook handler (which would be a very clean solution from Wikibase’s point of view) might not be feasible; some kind of flag on the link renderer, where the hook handler can look up what the link renderer is doing, could be a relatively economical way to transfor this information between `Linker::makeCommentLink()` and the hook handler. (The flag wouldn’t necessarily need to be mutable: `Linker::link()` already creates different `LinkRenderer` instances for different `$options`, so there could also be “a link renderer for comment links”, and the flag of that instance would never change during its lifetime.) TASK DETAIL https://phabricator.wikimedia.org/T292203 EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/ To: Lucas_Werkmeister_WMDE Cc: Lucas_Werkmeister_WMDE, Aklapper, Invadibot, maantietaja, Akuckartz, Iflorez, alaa_wmde, Nandana, Amorymeltzer, Lahi, Gq86, GoranSMilovanovic, QZanden, LawExplorer, Vali.matei, _jensen, rosalieper, Scott_WUaS, Wikidata-bugs, WMDE-Fisch, aude, Dinoguy1000, Lydia_Pintscher, Addshore, Mbch331, Jay8g
_______________________________________________ Wikidata-bugs mailing list -- wikidata-bugs@lists.wikimedia.org To unsubscribe send an email to wikidata-bugs-le...@lists.wikimedia.org