Manual:Hooks/LinkerMakeExternalImage

From Linux Web Expert

LinkerMakeExternalImage
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate>
Called before the HTML for external images is returned, used for modifying external image HTML
<translate> Define function:</translate>
public static function onLinkerMakeExternalImage( &$url, &$alt, &$img ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"LinkerMakeExternalImage": "MediaWiki\\Extension\\MyExtension\\Hooks::onLinkerMakeExternalImage"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> Linker.php
<translate> Interface:</translate> LinkerMakeExternalImageHook.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:LinkerMakeExternalImage extensions</tvar>.</translate>

Details

  • &$url: The URL of the external image
  • &$alt: The alt text of the image
  • &$img: The image HTML if you choose to override the default.

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