Jump to content
MediaWiki

Manual:Hooks/LinkEnd

From mediawiki.org
This feature was removed from MediaWiki core in version 1.36.0 (after being deprecated in 1.28.0). Please see HtmlPageLinkRendererEnd for an alternative way to use this feature.
LinkEnd
Available from version 1.14.0
Removed in version 1.36.0 (Gerrit change 593874)
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: In extension.json:
{
"Hooks":{
"LinkEnd":"MediaWiki\\Extension\\MyExtension\\Hooks::onLinkEnd"
}
}
Called from: File(s): LinkRenderer.php
Function(s): buildAElement
Interface: LinkEndHook.php

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


Warning

[edit ]

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

Details

[edit ]

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

[edit ]

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 ]

AltStyle によって変換されたページ (->オリジナル) /