Jump to content

Manual:Hooks/LinkerMakeMediaLinkFile

From mediawiki.org
LinkerMakeMediaLinkFile
Available from version 1.23.0
Called before the HTML for media link is returned, used for modifying media link HTML
Define function:
public static function onLinkerMakeMediaLinkFile( $title, $file, &$html, &$attribs, &$ret ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"LinkerMakeMediaLinkFile": "MediaWiki\\Extension\\MyExtension\\Hooks::onLinkerMakeMediaLinkFile"
	}
}
Called from: File(s): Linker.php
Interface: LinkerMakeMediaLinkFileHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:LinkerMakeMediaLinkFile extensions.


Details

[edit]
  • $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.