Manual:Hooks/LanguageLinks

From MediaWiki.org
Jump to navigation Jump to search
LanguageLinks
Available from version 1.22.0
Manipulate a page's language links. This is called in various places to allow extensions to define the effective language links for a page.
Define function:
public static function onLanguageLinks( $title, &$links, &$linkFlags ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"LanguageLinks": "MyExtensionHooks::onLanguageLinks"
	}
}

For MediaWiki ≤1.25:

$wgHooks['LanguageLinks'][] = 'MyExtensionHooks::onLanguageLinks';
Called from:File(s): api/ApiParse.php, OutputPage.php

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

Example[edit]

$wgHooks['LanguageLinks'][] = function ( $title, &$links, &$linkFlags ) {
        // add Esperanto easter egg to all egg-related topics
        if ( stripos( $title->getText(), 'egg' ) !== false ) {
            $links[] = 'eo:Paska_ovo';
        }
        return true;
};