Manual:Hooks/ListDefinedTags
ListDefinedTags | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> Can be used by extensions to register change tags. | |
<translate> Define function:</translate> | public static function onListDefinedTags( &$tags ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"ListDefinedTags": "MediaWiki\\Extension\\MyExtension\\Hooks::onListDefinedTags"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> ChangeTags.php |
<translate> Interface:</translate> | ListDefinedTagsHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:ListDefinedTags extensions</tvar>.</translate>
Details
&$tags
: The list of tags. Add your extension's tags to this array.
Notes
If 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
This 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;
}
}