Manual:Hooks/APIQueryUsersTokens

From MediaWiki.org
Jump to navigation Jump to search
APIQueryUsersTokens
Available from version 1.15.0
Use this hook to add custom token to list=users.
Define function:
public static function onAPIQueryUsersTokens( &$tokenFunctions ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"APIQueryUsersTokens": "MyExtensionHooks::onAPIQueryUsersTokens"
	}
}

For MediaWiki ≤1.25:

$wgHooks['APIQueryUsersTokens'][] = 'MyExtensionHooks::onAPIQueryUsersTokens';
Called from:File(s): api/ApiQueryUsers.php

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

Details[edit]

  • $tokenFunctions: array(action => callback)

Notes[edit]

Every token has an action, which will be used in the ustoken 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($user) where $user is the User object. In the hook, just add your callback to the $tokenFunctions array and return true (returning false makes no sense)