Manual:Hooks/LinkerMakeExternalLink

From Linux Web Expert

LinkerMakeExternalLink
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate>
Called before the HTML for external links is returned, used for modifying external link HTML
<translate> Define function:</translate>
public static function onLinkerMakeExternalLink( &$url, &$text, &$link, &$attribs, $linktype ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"LinkerMakeExternalLink": "MediaWiki\\Extension\\MyExtension\\Hooks::onLinkerMakeExternalLink"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> Linker.php
<translate> Interface:</translate> LinkerMakeExternalLinkHook.php

<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:LinkerMakeExternalLink extensions</tvar>.</translate>

Details

  • &$url: The URL of the external link
  • &$text: The link text that would normally be displayed on the page
  • &$link: The link HTML if you choose to override the default.
  • &$attribs: Link attributes (added in MediaWiki 1.15, r48223)
  • $linktype: Type of external link, e.g. 'free', 'text', 'autonumber'. Gets added to the css classes. (added in MediaWiki 1.15, r48226)

You need to return false if you want to modify the HTML of external links, returning true will produce the normal external link HTML, regardless of if $link is set to something. Please note that you will need to include all parts of the HTML in $link, including the <a> tag, if you choose to return false.

To modify interwiki external links, see Manual:Hooks/LinkEnd.