Manual:Hooks/ListDefinedTags
ListDefinedTags | |
---|---|
Available from version 1.15.0 Can be used by extensions to register change tags. | |
Define function: | public static function onListDefinedTags( &$tags ) { ... }
|
Attach hook: | In extension.json:
{
"Hooks": {
"ListDefinedTags": "MediaWiki\\Extension\\MyExtension\\Hooks::onListDefinedTags"
}
}
|
Called from: | File(s): ChangeTags.php |
Interface: | ListDefinedTagsHook.php |
For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:ListDefinedTags extensions.
Details
edit&$tags
: The list of tags. Add your extension's tags to this array.
Notes
editIf you don't implement this hook, tags used by your extension will show up on Special:Tags as "no longer in use", and administrators will be able to delete them.
You should always implement the ChangeTagsListActive hook as well. If all defined tags are active, then the same handler can be used for both (see example below).
Example
editThis imaginary extension is registering two tags, which are both active. One is used to mark automated edits, while the other is used to mark edits requiring attention.
In extension.json
:
{
"Hooks": {
"ListDefinedTags": "MediaWiki\Extension\MyExtension\Hooks::onRegisterTags",
"ChangeTagsListActive": "MediaWiki\Extension\MyExtension\Hooks::onRegisterTags"
}
}
In extensions/MyExtension/includes/Hooks.php
:
namespace MediaWiki\Extension\MyExtension;
class MyExtensionHooks {
public static function onRegisterTags( array &$tags ) {
$tags[] = 'my-extension-automated-edit';
$tags[] = 'my-extension-attention-required';
return true;
}
}