Open main menu

Manual:Hooks/GetLocalURL

GetLocalURL
Available from version 1.6.0
Used to modify local URLs as output into page links
Define function:
public static function onGetLocalURL( $title, $url, $query ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"GetLocalURL": "MyExtensionHooks::onGetLocalURL"
	}
}

For MediaWiki ≤1.25:

$wgHooks['GetLocalURL'][] = 'MyExtensionHooks::onGetLocalURL';
Called from:File(s): Title.php

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

DetailsEdit

  • $title: Title object of page
  • $url: string value as output (out parameter, can modify)
  • $query: query options passed to Title::getLocalURL()

UsageEdit

This hook can be used to alter the canonical URL of pages under specific circumstances. This is useful for instance since git #155d555b (MediaWiki 1.26) made MediaWiki automatically redirect from non-standard to canonical URLs. See an example usage at git #92dd60c4.