Jump to content

Manual:Hooks/GetLocalURL

From mediawiki.org
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.
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": "MediaWiki\\Extension\\MyExtension\\Hooks::onGetLocalURL"
	}
}
Called from: File(s): Title.php
Interface: GetLocalURLHook.php

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

Details

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

Usage

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