Manual:Hooks/LinkerMakeMediaLinkFile

From Linux Web Expert

LinkerMakeMediaLinkFile
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate>
Called before the HTML for media link is returned, used for modifying media link HTML
<translate> Define function:</translate>
public static function onLinkerMakeMediaLinkFile( $title, $file, &$html, &$attribs, &$ret ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"LinkerMakeMediaLinkFile": "MediaWiki\\Extension\\MyExtension\\Hooks::onLinkerMakeMediaLinkFile"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> Linker.php
<translate> Interface:</translate> LinkerMakeMediaLinkFileHook.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:LinkerMakeMediaLinkFile extensions</tvar>.</translate>


Details

  • $title: The Title object associated with the file.
  • $file: The File object or false if it doesn't exist yet.
  • &$html: Pre-sanitized HTML that goes inside the anchor tag.
  • &$attribs: Link attributes.
  • &$ret: The link HTML if you choose to override the default. Default is an empty string.

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