Manual:Hooks/APIQueryRecentChangesTokens

From MediaWiki.org
Jump to navigation Jump to search
APIQueryRecentChangesTokens
Available from version 1.14.0
Use this hook to add custom tokens to list=recentchanges.
Define function:
public static function onAPIQueryRecentChangesTokens( &$tokenFunctions ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"APIQueryRecentChangesTokens": "MyExtensionHooks::onAPIQueryRecentChangesTokens"
	}
}

For MediaWiki ≤1.25:

$wgHooks['APIQueryRecentChangesTokens'][] = 'MyExtensionHooks::onAPIQueryRecentChangesTokens';
Called from:File(s): api/ApiQueryRecentChanges.php

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

Details[edit]

  • $tokenFunctions: array(action => callback)

Notes[edit]

Every token has an action, which will be used in the rctoken parameter and in the output (actiontoken="..."), and a callback function which should return the token, or false if the user isn't allowed to obtain it.

The prototype of the callback function is func($pageid, $title, $rc) where $pageid is the page ID of the page associated to the revision the token is requested for, $title the associated Title object and $rc the associated RecentChange object.

In the hook, just add your callback to the $tokenFunctions array and return true (returning false makes no sense)