Manual:Hooks/LinkEnd

From MediaWiki.org
Jump to: navigation, search
LinkEnd
Available from version 1.14.0
Used when generating internal and interwiki links in Linker::link(), just before the function returns a value.

Define function:
public static function onLinkEnd( $dummy, Title $target, array $options, &$html, array &$attribs, &$ret ) { ... }

Attach hook:
$wgHooks['LinkEnd'][] = 'MyExtensionHooks::onLinkEnd';
Called from: File(s): Linker.php

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


Details[edit | edit source]

If you return true, an <a> element with HTML attributes $attribs and contents $text will be returned. If you return false, $ret (which defaults to null) will be returned. If you return true, then Html::rawElement( 'a', $attribs, $html ) will be returned.

  • $dummy: used to be a skin, but that was eliminated.
  • $target: the Title object that the link is pointing to.
  • $options: the options. Can include 'known', 'broken', 'noclasses', 'forcearticlepath', 'http', or 'https'.
  • &$html: the HTML contents of the <a> element, i.e., the link text. This is raw HTML and will not be escaped. If null, defaults to the prefixed text of the Title; or if the Title is just a fragment, the contents of the fragment.
  • &$attribs: the final HTML attributes of the <a> tag, after processing, in associative array form.
  • &$ret: the value to return if your hook returns false.

Note that this hook can allow changes to interwiki links (detect class attribute is set to "extiw" to change $ret, and if not, return true). Since Html::rawElement() is not immediately available to this hook, one may able to use Xml::tags() in its place.

Example[edit | edit source]

The following code will show all wikilinks and interwiki links as broken (i.e. as red links) by using the "new" class:

$wgHooks['LinkEnd'][] = 'ExampleExtension::exampleExtensionLinkEnd';
 
class ExampleExtension {
	public static function exampleExtensionLinkEnd( $dummy, Title $target, array $options, &$html, array &$attribs, &$ret ) {
		$ret = Html::rawElement ( 'a', array ( 'href' => $target->getFullURL(), 'class' => 'new' ),
			$target->getPrefixedDBKey() );
		return false;
	}
}

See also[edit | edit source]