Jump to content

Manual:Hooks/GetRelativeTimestamp

From mediawiki.org
GetRelativeTimestamp
Available from version 1.22.0 (Gerrit change 45677)
Pre-emptively override the relative timestamp generated by MWTimestamp::getRelativeTimestamp(). Return false in this hook to use the custom output.
Define function:
public static function onGetRelativeTimestamp( string $output, DateInterval &$diff, MWTimestamp $timestamp, MWTimestamp $relativeTo, User $user, Language $lang ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"GetRelativeTimestamp": "MediaWiki\\Extension\\MyExtension\\Hooks::onGetRelativeTimestamp"
	}
}
Called from: File(s): MWTimestamp.php
Function(s): getRelativeTimestamp
Interface: GetRelativeTimestampHook.php

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


Details

[edit]
  • &$output: string for the output timestamp
  • &$diff: DateInterval representing the difference between the timestamps
  • $timestamp: MWTimestamp object of the current (user-adjusted) timestamp
  • $relativeTo: MWTimestamp object of the relative (user-adjusted) timestamp
  • $user: User whose preferences are being used to make timestamp
  • $lang: Language that will be used to render the timestamp