Manual:Hooks/LinkEnd

From Linux Web Expert

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
LinkEnd
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate>
<translate> Removed in <tvar name=1><translate> version <tvar (Gerrit change 593874)</tvar></translate>
Used when generating internal and interwiki links in Linker::link(), just before the function returns a value.
<translate> Define function:</translate>
public static function onLinkEnd( $dummy, Title $target, array $options, &$html, array &$attribs, &$ret ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"LinkEnd": "MediaWiki\\Extension\\MyExtension\\Hooks::onLinkEnd"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> LinkRenderer.php
<translate> Function(s):</translate> buildAElement
<translate> Interface:</translate> LinkEndHook.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:LinkEnd extensions</tvar>.</translate>


Warning

In MediaWiki 1.28 this hook has been superseded by HtmlPageLinkRendererEnd. LinkEnd is considered outdated.

Details

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

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